In this example, https://stackoverflow.com/a/3208758/ and here Why is my disruptor example so slow? (at the end of the question) there is 1 publisher who publishes articles and 1 consumer.
But in my case, consumer work is much more complicated and takes some time. Therefore, I want 4 consumers to process data in parallel.
So, for example, if the manufacturer produces numbers: 1,2,3,4,5,6,7,8,9,10,11 ..
I want consumer1 to catch 1,5,9, ... consumer2 to catch 2,6,10, ... consumer3 to catch 3,7,11, ... consumer4 to catch 4,8,12 ... (well, not quite these numbers, the idea is that the data should be processed in parallel, I donβt care which particular number is processed by which consumer)
And remember that this must be done in parallel, because in real work the application is quite expensive. I expect consumers to run in different threads to use the power of multi-core systems.
Of course, I can just create 4 ringbuffers and attach 1 consumer to 1 ring buffer. That way I can use the original example. But I feel that it will be wrong. It would probably be right to create 1 publisher (1 ringbuffer) and 4 consumers - since that is what I need.
Adding a link to a very simulating question in google groups: https://groups.google.com/forum/#!msg/lmax-disruptor/-CLapWuwWLU/GHEP4UkxrAEJ
So, we have two options:
- one ring of many consumers (each consumer will "wake up" on each addition, each consumer must have the same WaitStrategy).
- a lot of "one ring - one consumer" (each consumer will wake up only on the data that he needs to process, each consumer can have his own WaitStrategy).