Assembling MPSC using SPSC queues

216 views
Skip to first unread message

Dain Ironfoot

unread,
Nov 18, 2014, 9:11:52 PM11/18/14
to mechanica...@googlegroups.com

Hello Guys.

I am attempting to assemble a Multiple Producer Single Consumer queue using Martin/Nitsan's Single Producer Single Consumer queue.
What I have thus far works but wanted to get your opinions/suggestions to ensure the correctness of my approach.

In a nutshell, I have multiple producers generating events which needs to be dispatched to consumers in strict LIFO order.
I currently use an ArrayBlockingQueue where the producers simply en-queque and a poller thread dequeues and dispatches the events.
With this configuration, I am able to push 10 million events/sec but I in the next phase, I need to push at least 15-17 million/sec (hence the re-design).

Since the number of event producers is fixed, what I am thinking is this:
Different producer threads will enqueue data into separate SPSC queues.
As before, a single poller thread will poll all the queue. If nothing is polled, I apply back pressure by parking the poller thread and then retrying.
If events are polled, I sort them according to their monotonically increasing Id (to maintain FIFO ordering) and finally dispatch them to their respective listeners.

          P-Thread1  -> Q1 ==================== |  <=  
          P-Thread2  -> Q2 ==================== |  <= Poller Thread |  =|=|=|=|=|=|=|=|=|=| Sort | Dispatch
          P-Thread3  -> Q3 ==================== |  <=                           (Events polled)
          P-Thread4  -> Q4 ==================== |  <=

Are their any issues I should be aware of before discarding the trusted ArrayBlockingQueue?

Cheers

Georges Gomes

unread,
Nov 19, 2014, 3:37:07 AM11/19/14
to mechanica...@googlegroups.com
Hi

Disclaimer: Measurements are always preferred.

But here are my thoughts:

If you create your monotonical increasing id thought a CAS operation, you are likely to have the same results with MPSCArrayQueue from JCTools. I would recommed to try it first. Let us know your results.

My 2 cents
GG





--
You received this message because you are subscribed to the Google Groups "mechanical-sympathy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mechanical-symp...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages