是这样,我写了一段测试代码用来测试disruptor在多个生产者对应一个消费者处理模式下的性能,代码很简单:
public static void main(String[] args) throws Exception {
int publisherNum = 50000;
Executor executor = Executors.newCachedThreadPool();
Disruptor<ValueEvent> disruptor = new Disruptor<ValueEvent>(
ValueEvent.EVENT_FACTORY, executor, new
MultiThreadedLowContentionClaimStrategy(4),new YieldingWaitStrategy() );
disruptor.handleEventsWith(new Customer());
RingBuffer<ValueEvent> ringBuffer = disruptor.start();
for (int i=0; i<publisherNum; i++) {
long sequence = ringBuffer.next();
ValueEvent event = ringBuffer.get(sequence);
executor.execute(new Publisher(ringBuffer, sequence));
}
}
其中Customer实现了EventHandler。在onEvent方法中只是打印输出,表示收到消息。
可是整个循环运行下来大概用了5分钟左右。
所以我对于Disruptor提到过的每秒6百万的处理能力不知道该如何去理解?还是说我这样的测试方法根本就有问题?
还请各位高手能够解释一下。谢谢大家!