Do disruptor queues provide superior performance when there are N Producers and 1 consumer? I wrote a program with Multiple Producer and Single Consumer using Disruptor Queues. I find the results are neck-on-neck with blocking arraybounded queues. The latter performs better. Am I doing something wrong here?
public void asynchronous_execution( )
{
// Set up the executor and disruptor
ExecutorService exec = Executors.newCachedThreadPool();
Disruptor<valueEvent> disruptor =
new Disruptor<valueEvent>( valueEvent.EVENT_FACTORY,
globalVariables.RING_SIZE,
exec );
// Handler of Events
final EventHandler<valueEvent> handler = new EventHandler<valueEvent>()
{
public void onEvent(final valueEvent event, final long sequence,
final boolean endOfBatch) throws Exception
{ .... }
};
// Building Dependency Graph
disruptor.handleEventsWith(handler);
// Starting the disruptor
final RingBuffer<valueEvent> ringBuffer = disruptor.start();
// Producer Thread
final long[] runtime = new long [globalVariables.NUMBER_OF_THREADS];
final class ProducerThread extends Thread {
...
public void run()
{
..
long sequence = ringBuffer.next();
valueEvent event = ringBuffer.get(sequence);
event.setValue(globalVariables.WRITE_CODE);
// make the event available to EventProcessors
ringBuffer.publish(sequence);
...
}
...
};
ProducerThread[] threads = new ProducerThread[globalVariables.NUMBER_OF_THREADS];
for (int i = 0; i < globalVariables.NUMBER_OF_THREADS; i++) {
threads[i] = new ProducerThread( i );
threads[i].start();
}
....
}