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
{
....
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.
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.
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.
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.
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 long
s 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With