Disruptor相对于传统ConcurrentQueue 速度对比分析

it2022-05-05  110

入队响应时间对比

public static void main(String[] args) throws InterruptedException { Disruptor<Event> dp = new Disruptor<>(Event::new, 33554432, Thread::new); final RingBuffer<Event> bf = dp.getRingBuffer(); Thread th = new Thread(() -> { int i = 0; long start = System.currentTimeMillis(); for (; i < 100000; i++) { long seq = bf.next(); Event e = dp.get(seq); e.setMessage("message " + i++); bf.publish(seq); } long use = System.currentTimeMillis() - start; System.out.println("using time: " + use); }); dp.start(); th.start(); th.join(); Queue<Event> queue = new ConcurrentLinkedQueue<>(); Thread th1 = new Thread(() -> { int i = 0; long start = System.currentTimeMillis(); for (; i < 100000; i++) { Event e = new Event(); e.setMessage("message "+i++ ); queue.offer(e); } long use = System.currentTimeMillis() - start; System.out.println("using time: " + use); }); th1.start(); th1.join(); } static class Event { public Event() { } String message; long seq; public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } public long getSeq() { return seq; } public void setSeq(long seq) { this.seq = seq; } }

com.lmax.disruptor.test.MainTest data size :16 disruptor using time: 0 concurrent Quueu using time: 0 blocking Queue using time: 0 data size :32 disruptor using time: 0 concurrent Quueu using time: 1 blocking Queue using time: 0 data size :64 disruptor using time: 1 concurrent Quueu using time: 0 blocking Queue using time: 0 data size :128 disruptor using time: 0 concurrent Quueu using time: 1 blocking Queue using time: 1 data size :256 disruptor using time: 1 concurrent Quueu using time: 0 blocking Queue using time: 1 data size :512 disruptor using time: 1 concurrent Quueu using time: 1 blocking Queue using time: 2 data size :1024 disruptor using time: 2 concurrent Quueu using time: 0 blocking Queue using time: 3 data size :2048 disruptor using time: 2 concurrent Quueu using time: 1 blocking Queue using time: 3 data size :4096 disruptor using time: 2 concurrent Quueu using time: 2 blocking Queue using time: 1 data size :8192 disruptor using time: 3 concurrent Quueu using time: 3 blocking Queue using time: 2 data size :16384 disruptor using time: 4 concurrent Quueu using time: 4 blocking Queue using time: 15 data size :32768 disruptor using time: 8 concurrent Quueu using time: 6 blocking Queue using time: 7 data size :65536 disruptor using time: 15 concurrent Quueu using time: 10 blocking Queue using time: 12 data size :131072 disruptor using time: 29 concurrent Quueu using time: 18 blocking Queue using time: 19 data size :262144 disruptor using time: 37 concurrent Quueu using time: 17 blocking Queue using time: 105 data size :524288 disruptor using time: 127 concurrent Quueu using time: 75 blocking Queue using time: 285 data size :1048576 disruptor using time: 286 concurrent Quueu using time: 244 blocking Queue using time: 145 data size :2097152 disruptor using time: 408 concurrent Quueu using time: 376 blocking Queue using time: 602 data size :4194304 disruptor using time: 1152 concurrent Quueu using time: 991 blocking Queue using time: 699 data size :8388608 disruptor using time: 1832 concurrent Quueu using time: 2010 blocking Queue using time: 2318 data size :16777216 disruptor using time: 4898 concurrent Quueu using time: 3819

Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread “Thread-62” data size :33554432 disruptor using time: 10892

Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread “Thread-64” Exception in thread “main” java.lang.OutOfMemoryError: Java heap space


最新回复(0)