Search code examples
eventhandlercircular-bufferdisruptor-patternlmax

Why lmax disruptor architecture use 2 disruptor?


In " lmax disruptor architecture design" it is showing that , they are taking input and enqueing it in input disruptor and there are multiple event handlers like journaling ,un-marshalling , business logic and after that that enqueing it to output disruptor and output disruptor has Marshalling , journaling etc event handlers ..

My doubt is ..why not using one disruptor with all combine event handlers of input and output disruptor. We can handle event in such a way that , after business logic processing output's disruptor events will call.??

Correct me if I misunderstood it.


Solution

  • In the article there are potentially multiple output disruptors.

    It is a perfectly valid design choice in some cases to have the output processors in the same disruptor as the business logic processor. The advantage is that there is no copying of the data that needs to be output if it is already contained in the input event.

    However in this case and one of them is slow that would potentially cause the disruptor to fill to capacity and prevent the business logic processor from processing new events.

    By having the output disruptors as separate ring buffers the business logic processor can decide how to handle an output disruptor that is slow and whose ring buffer is full. It also allow multiple input disruptors to share the same output disruptor if that output disruptor needs exclusive access to some external resource.