LMAX BatchEventProcessor Break Pattern Role

What is the role of the BatchEventProcessor in the lmax disruptor pattern?

BatchEventProcessor<ValueEvent> eventProcessor 

= new BatchEventProcessor (ringBuffer, barrier, handler);

 EXECUTOR.execute( eventProcessor ); 
+4
source share
2 answers

BatchEventProcessor is an implementation of eventProcessor that controls the number of events available on each call. It then delegates the actual processing of each event to your eventHandler and signals when the final packet event has been delivered to your event handler.

The idea is that if you want to postpone the publication of an event from your handler, for example. Add a group of events to one larger message.

+3
source

If we talk about the task of โ€œadding a group of events to one larger messageโ€ from Samโ€™s answer, BatchEventProcessor allows us two main things:

  • We will get "endOfBatch == true" on the last call of the series of events, so we can delay the mass publication of messages for the call using "endOfBatch == true", and we will not get stuck in a situation where there is no event for several minutes, and we do not sent already collected once, and we need to additionally cope with this situation.
  • BatchEventProcessor will only move its Sequence value after all messages from the packet are sent by the handler. This allows you to hold previous events of the current batch in our Handler and use them, for example, to create a bulk message, and you should not think about manufacturers that can damage the content of these reused events. Manufacturers do not have access to these events and their associated sequences until the handler returns from onEvent (, endOfBatch == true).
+1
source

Source: https://habr.com/ru/post/1483475/


All Articles