JCTools
JCTools copied to clipboard
[Channels] Implement MPSC Channels
Queue semantics don't offer object reuse. Having to allocate new object instance for every offer() call effectively halves queue throughput.
It would be useful to have disruptor-like pattern around a buffer.
I think the approach prototyped in the channels
package of the experimental project addresses this need. It involves a 3 step process:
- You claim a slot
- You write in your data
- You commit the slot
While JCTools v0.1 (almost here) will only support the Queue interface (which sucks a bit, but everyone uses) we do plan to have support for claim/commit type queues.
To add some detail to the ticket the disruptor offers 2 distinct features beyond the common queue:
- Static entry allocation and reuse: This becomes a bit more complex in the multi consumer/producer scenario where a claim can block all claim and releases happening 'after' it from becoming visible (this is the case for multi producer in disruptor). But this is not inherent to the pattern. A simple way to implement this pattern using a queue would utilise 2 queues, one acting as the queue object pool.
- Multicast: the disruptor allows all consumers to consume all elements. Only once all consumers are finished is the slot released. This is desirable in some scenarios and can be tacked separately.
thank you guys.
Does SpscChannel support multiple publishers?
(there is a directory "java" missing between "test" and "org" in experimental package, IDEA doesn't recognise tests for java code)
The "Sp" stands for "Single Producer" ;) There's some plans for Multiple producers, not yet implemented.
Thanks Richard, acronyms was going to be my next question but I thought I'd throttle them down a bit :)
Renamed to reflect conclusion, object reuse is covered in other channels related ticket #14
There's a fixed sized MPSC channel impl in experimental. It's got issues, but there's some progress on this.