Video in progress

For high-throughput messaging between services, how do you choose between ConcurrentLinkedQueue, LinkedBlockingQueue, JCTools and the LMAX Disruptor?

First I answer the questions "does it need to block, does it need a bound, how many producers and consumers are there". For ordinary cases the JDK queues are enough; if you need millions of messages per second and microsecond latency, JCTools' specialized queues or the Disruptor are chosen after measuring.

📖 Answer

They solve different problems:

LinkedBlockingQueue / ArrayBlockingQueue: blocking, bounded, easy to use. The consumer sleeps in take() and doesn't burn CPU. There is the cost of locking and waking up a thread, and usually it is fine up to a few hundred thousand messages per second.

ConcurrentLinkedQueue: lock-free (the Michael–Scott algorithm), but unbounded and non-blocking. You decide yourself what the consumer does on an empty queue: spin (CPU burns) or sleep (latency). A node per element means GC pressure.

JCTools: queues for specific scenarios: SPSC, MPSC, MPMC, array-based, bounded. Netty uses them directly, and Caffeine has its own queue based on JCTools code. For example, for "many producers, one consumer" (an event loop, a batch writer), MpscArrayQueue can be several times faster than the JDK queues, because it doesn't have to support the general case.

Disruptor: a preallocated ring buffer, objects are reused (no allocation), sequences and a choice of wait strategy (BusySpin, Yielding, Blocking). You can express several consumer stages (a pipeline) and the dependencies between them. The cost is a complex model, and with the busy-spin strategy a core is fully occupied.

My order of decisions:

  1. I start with a JDK blocking queue and export throughput, queue length and wait time as metrics.
  2. If the profile shows contention on the queue lock and the SLO is broken, a JCTools queue that matches the scenario.
  3. Disruptor only for very low latency (trading, telemetry ingest) and if the team can support it.

Often the real bottleneck turns out not to be the queue but the consumer itself (a DB write, serialization). So batching first (drainTo 500 at a time instead of one take) is the cheapest and gives a big win.