NiksP
NiksP

Reputation: 69

Disruptor - Are the Consumers Multithreaded?

I have following questions regarding the disruptor:

  1. The consumers (event processors) are not implementing any of the Callable or Runnable interfaces they implement EventHandler, Then how can they run in parallel, so for example I have a disruptor implementation where there is a diamond pattern like this
     c1
P1 - c2 - c4 - c5
     c3

Where c1 to c3 can work in parallel after p1, and C4 and C5 work after them.

So conventionally I'd have something like this (with P1 and C1-C5 being runnables/callables)

p1.start();
p1.join();

c1.start();
c2.start();
c3.start();
c1.join();
c2.join();
c3.join();

c4.start();
c4.join();
c5.start();
c5.join();

But in case of the Disruptor none of my event handlers implement Runnable or Callable, so how'd the disruptor framework end up running them in parallel?

Take following sceanrio:

My consumer C2 requires to make a webservice call for some annotation to the Event, In SEDA I can startup 10 threads for such 10 C2 requests [for pulling the message out of queue + make Webservice Call and update the next SEDA Queue] and that will make sure that I don't sequentially wait for a web service response for each of the 10 requests where as in this case my eventprocessor C2 (if) being the single instance would wait sequentially for 10 C2 requests.

Upvotes: 2

Views: 5797

Answers (2)

mohamus
mohamus

Reputation: 83

Disruptor default strategy is multi-threaded, so if every of your processors are working in a different Handler (Consumer), so it should be fine, and your processors are multi-threaded.

Upvotes: 0

jasonk
jasonk

Reputation: 969

Your EventHandler is composed into an instance of a BatchEventProcessor, which is a Runnable.

  • The BatchEventProcessor implements the run() loop.
  • It is responsible for fetching updated event sequence numbers from the ring buffer.
  • When events are available for processing, it passes them to your EventHandler for processing.

When using the DSL, the Disruptor takes care of creating these threads via an Executor instance.

  • You provide an Executor in the Disruptor constructor.
  • You provide a list of your EventHandlers using and/then/etc on the DSL.
  • Then, you call Disruptor start() method. As part of the start() method, each EventProcessor (Runnable) is submitted to the Executor.
  • Executor will in turn launch your EventProcessor/EventHandler on a thread.

With respect to your specific scenario (ie: long running event handlers), you might refer to this question:

Upvotes: 5

Related Questions