Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disruptor - Ring Buffer

I am investigating LMAX Disruptor's source code, and I came into RingBuffer abstract class. Why are there exactly 7 long fields (p1 ... p7) in RingBufferPad ? Here is actual code : https://github.com/LMAX-Exchange/disruptor/blob/master/src/main/java/com/lmax/disruptor/RingBuffer.java

abstract class RingBufferPad
{
    protected long p1, p2, p3, p4, p5, p6, p7;
}

abstract class RingBufferFields<E> extends RingBufferPad
{
....
like image 389
Humoyun Ahmad Avatar asked Aug 12 '15 13:08

Humoyun Ahmad


People also ask

What is LMAX Disruptor used for?

The Disruptor is a library that provides a concurrent ring buffer data structure. It is designed to provide a low-latency, high-throughput work queue in asynchronous event processing architectures.

How does a Disruptor work?

Disruptor has an array based circular data structure (ring buffer). It is an array that has a pointer to next available slot. It is filled with pre-allocated transfer objects. Producers and consumers perform writing and reading of data to the ring without locking or contention.

What is a Disruptor in Java?

Disruptor is a library for the Java programming language that provides a concurrent ring buffer data structure of the same name, developed at LMAX Exchange. It is designed to provide a low-latency, high-throughput work queue in asynchronous event processing architectures.

What is LMAX architecture?

LMAX is a new retail financial trading platform. As a result it has to process many trades with low latency. The system is built on the JVM platform and centers on a Business Logic Processor that can handle 6 million orders per second on a single thread.


1 Answers

This is to ensure the long value which is actually used is on it's own cache line. This avoid false sharing where you have two longs which need to be updated by different threads competing for the same cache line.

The assumption here is that the CPU cache line length is 64 bytes (and it is on most architectures e.g. ARM, AMD and Intel CPUs). Using 7 longs is slightly paranoid as the header will be 8 bytes min, 16 bytes max (with allocation alignment) so 6 or even 5 long values would be enough.

like image 154
Peter Lawrey Avatar answered Sep 25 '22 12:09

Peter Lawrey