One EventHandler
(DatabaseConsumer) of the Disruptor
calls stored procedures in database, which is so slow that it blocks the Disruptor
for some time.
Since I need the Disruptor
keep running without blocking. I am thinking adding an extra queue so that EventHandler
could serve as Producer
and another new-created thread could serve as Consumer
to handle database's work, which could be asynchronous without affecting the Disruptor
Here is some constrain:
Disruptor
passed to the EventHandler
is around 30KB and the number of this object is about 400k. In theory, the total size of the objects that needs to be handled is around 30KBX400K =12GB. So the extra queue should be enough for them.I'm thinking text file as a option. EventHandler
(Producer) writes the object to the file and Consumer
reads from them and call stored procedure. The problem is how to handle the situation that it reach to the end of the file and how to know the new coming line.
Anyone who has solve this situation before? Any advice?
The short answer is size your disruptor to cope with the size of your bursts not your entire volume, bare in mind the disruptor can just contain a reference to the 30kb object, the entire object does not need to be in the ring buffer.
With any form of buffering before your database will require the memory for buffering the disruptor offers you the option of back pressure on the rest of the system when the database has fallen too far behind. That is to say you can slow the inputs to the disruptor down.
The other option for spooling to files is to look at Java Chronicle which uses memory mapped files to persist things to disk.
The much more complicated answer is take advantage of the batching effects of the disruptor so that your DB can catch up. I.e. using a EventHandler which collects events a batch of events together and submits them to the database as one unit. This practice allows the EventHandler to become more efficient as things back up thus increasing throughput.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With