Question

I am also thinking of integrating the disruptor pattern in our application. I am a bit unsure about a few things before I start using the disruptor

  1. I have 3 producers, mainly a FIX thread which de-serialises the requests. Another thread which continously modifies order price as the market moves. Also we have one more thread which is responsible for de-serialising the requests sent from a GUI application. All three threads currently write to a Blocking Queue (hence we see a lot of contention on the queue)
  2. The disruptor talks about a Single writer principle and from what I have read that approach scales the best. Is there any way we could make the above three threads obey the single writer principle?
  3. Also in a typical request/response application, specially in our case we have contention on an in memory cache, as we need to lock the cache when we update the cache with the response, whilst a request might be happening for the same order. How do we handle this through the disruptor, i.e. how do I tie up a response to a particular request? Can I eliminate the lock on the cache if yes how?

Any suggestions/pointers would be highly appreciated. We are currently using Java 1.6

Was it helpful?

Solution

I'm new to distruptor and am trying to understand as much usecases as possible. I have tried to answer your questions.

  1. Yes, Disruptor can be used to sequence calls from multiple producers. I understand that all 3 threads try to update the state of a shared object. And a single consumer which takes necessary action on the shared object. Internally you can have the single consumer delegate calls to the appropriate single threaded handler based on responsibility. The

  2. The Disruptor exactly does this. It sequences the calls such that the state is accessed only by a thread at a time. If there's a specific order in which the event handlers are to be invoked, set up the memory barrier. The latest version of Disruptor has a DSL that lets you setup the order easily.

  3. The Cache can be abstracted and accessed through the Disruptor. At a time, only a Reader or a Writer would get access to the cache, since all calls to the cache are sequential.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top