3 ms·
What you are missing is that with the disruptor pattern you can do this lock-less while keeping the order: The producer gets a sequence number before accessing
by ahoka 10y ago
What you are missing is that with the disruptor pattern you can do this lock-less while keeping the order: The producer gets a sequence number before accessing the space in the queue. This seqno guarantees the order of consumption so there will be no reordering of events on the consumer side. After creating the message, the producer commits this id. Meanwhile the consumer waits for the next seqno to become committed and consumes it.
I have implemented a multiple producer, single consumer variant in C for logging and it works quite well. Loggers can write their message concurrently to the ring buffer, but the order will be correct in the log file.
- infamouscow 10y agoSounds exactly what Concurrency Kit already does. http://concurrencykit.org/ http://concurrencykit.org/
- therestisgone 10y agoExcept Concurrency Kit only supports a single producer.
- mej10 10y agoThe paper linked says that the most common use of Disruptor only has one producer.
- newobj 10y ago"Already does"? They're both from 2011. Even if they both do the same thing, do you have a point?
- irishjohnnie 10y agoIIRC, the data structure that they used was not thread-safe. There eventually had to be an interlocked compare exchange operation which slowed throughput. Also, I couldn't imagine this working correctly in out-of-order cores without memory barriers at the very least.
- ahoka 10y agoYes, you need to use CAS and barriers to make it thread safe. I have also used a condvar for the consumer to avoid spinning while waiting for log messages.