JCTools icon indicating copy to clipboard operation
JCTools copied to clipboard

[Channels] Implement MPSC Channels

Open bluestreak01 opened this issue 10 years ago • 7 comments

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.

bluestreak01 avatar Aug 20 '14 16:08 bluestreak01

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

RichardWarburton avatar Aug 20 '14 16:08 RichardWarburton

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:

  1. 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.
  2. 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.

nitsanw avatar Aug 20 '14 16:08 nitsanw

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)

bluestreak01 avatar Aug 20 '14 16:08 bluestreak01

The "Sp" stands for "Single Producer" ;) There's some plans for Multiple producers, not yet implemented.

RichardWarburton avatar Aug 20 '14 16:08 RichardWarburton

Thanks Richard, acronyms was going to be my next question but I thought I'd throttle them down a bit :)

bluestreak01 avatar Aug 20 '14 16:08 bluestreak01

Renamed to reflect conclusion, object reuse is covered in other channels related ticket #14

nitsanw avatar Apr 17 '15 10:04 nitsanw

There's a fixed sized MPSC channel impl in experimental. It's got issues, but there's some progress on this.

nitsanw avatar Feb 25 '16 08:02 nitsanw