JCTools icon indicating copy to clipboard operation
JCTools copied to clipboard

Implement intrusive linked queue MPSC

Open nitsanw opened this issue 9 years ago • 14 comments

This was found to be a useful usecase in Netty for internal uses where long/medium lived events are passed between threads and we wish to avoid the allocation of nodes by having the entity extend a node. The API changes to the following:

Queue<N extends Node> {
   boolean offer(N n);
   N poll();
...
}

It would be good if @normanmaurer could comment on usage pattern or any further detail relating to the usecase.

nitsanw avatar Apr 01 '16 10:04 nitsanw

see related discussion in https://github.com/netty/netty/pull/5051

nitsanw avatar Apr 01 '16 10:04 nitsanw

I'd like to voice strong support for this ticket! The intrusive sibling of the already implemented MpscLinkedQueue would be a very attractive addition for sure. I'd definitely prefer it over the non-intrusive variant in all cases where the universe of queue inhabitant types is closed and under my control, which is (for me) the majority.

Outline: http://www.1024cores.net/home/lock-free-algorithms/queues/intrusive-mpsc-node-based-queue

sirthias avatar Jun 07 '16 12:06 sirthias

@nitsanw sorry I totally missed this 😢

So the use-case for us was basically that we had full control over the queue and just wanted to add "one-time-events", which for example is a Runnable that is only needed one time. For this to be able to have this also be the node itself reduce the GC dramatically. So yes, please :)

normanmaurer avatar Jun 07 '16 12:06 normanmaurer

@sirthias @normanmaurer OK, will get to it. This is not a blocking issue for JCTools dependency is it?

nitsanw avatar Jun 10 '16 10:06 nitsanw

@nitsanw not for me atm... Just running final tests here before doing the cherry-pick FTW :)

normanmaurer avatar Jun 10 '16 10:06 normanmaurer

@nitsanw for me neither, but it would definitely sweeten the pie... :)

sirthias avatar Jun 10 '16 10:06 sirthias

@sirthias I live to sweeten :)

nitsanw avatar Jun 10 '16 10:06 nitsanw

@nitsanw This is not to say that the pie isn't already attractively sweet! But the top still sports some space for a few cherries... :)

sirthias avatar Jun 10 '16 10:06 sirthias

+1

Am 10.06.2016 um 12:22 schrieb Mathias [email protected]:

@nitsanw This is not to say that the pie isn't already attractively sweet! But the top still sports some space for a few cherries... :)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

normanmaurer avatar Jun 10 '16 10:06 normanmaurer

Has anyone started work on this yet? Would you like to maintain the existing MpscLinkedQueue interface exactly as is, and introduce a new (say) MpscIntrusiveLinkedQueue alongside it that would implement Queue<E extends Node>? What will be the strategy for dealing with node objects? Currently LinkedQueueNode contains some of the read/write logic. As a first pass, should we just ask users of the new MpscIntrusiveLinkedQueue to extend the existing LinkedQueueNode themselves?

pcholakov avatar Aug 04 '16 06:08 pcholakov

I gave this some thought:

  1. Implementing a mixed queue is more complex, and not the use case.
  2. We can't take care of the case where the user enqueues the same element twice, or to 2 queues.
  3. We therefore need a minimal interface implementation here.

We need to review the Netty usecase and see if the intrusive queue is assumed to be a java.util.Queue.

nitsanw avatar Aug 04 '16 07:08 nitsanw

@pcholakov please throw what you got into a PR and we can close this?

nitsanw avatar Oct 06 '16 06:10 nitsanw

GitHub noob - I tried to link it to this issue but ended up creating a separate #131. Comments? (Tips how to merge the two?)

pcholakov avatar Oct 06 '16 14:10 pcholakov

OK, so first cut is in, I'll follow up with some refactoring and we can look at a review from Netty guys. This will not be in 2.0 release.

nitsanw avatar Oct 28 '16 08:10 nitsanw