This is the 14th day of my participation in the August More Text Challenge

Disruptor Disruptor Disruptor Disruptor Disruptor Disruptor Disruptor Disruptor Disruptor

Disruptor design is to ensure that any data should be owned by a single thread only for write access permissions, eliminating the write contention, understandable for Java. Util. Concurrent. The Phaser, because it has similar elements, Functionally similar to CyclicBarrier and CountDownLatch, but with more flexible use, introduced to support fork-join; The goal is to maximize the efficiency of memory allocation and to run in a cache-friendly manner so that it runs optimally on modern hardware.

Disruptor core is a bounded data structure in the form of a pre-allocated ring buffer. Data is added to the circular buffer by one or more producers and processed by one or more consumers. The amount of space required for the ring buffer is pre-allocated at startup. Since the ring buffer is valid for the duration of the Disruptor, the garbage collector does not need to collect for the duration of the Disruptor, thus reducing the burden of garbage collection in high memory utilization projects.

The head and tail of the bounded queue will have competition phenomenon when they are getting, because of the special structure of the ring, there is no such phenomenon, we only need to pay attention to the queue and queue;

Sorting is the core concept behind Disruptor’s concurrency management. Each producer and consumer determines how it interacts with the circular buffer according to a strict concept of order. The producer declares the next slot in the ring in order. Use CAS to manipulate updated atomic counters in the case of multiple producers. Once a sequence value has been declared, the data in the ring buffer can now be written by the declared producer. When the producer has finished updating the data, it can commit the changes by updating a separate counter that represents the cursor on the ring buffer of the most recent data available to the consumer, which is visible to the consumer through the memory barrier. If the ring buffer is behind some steps on queuing, It will quickly process to the same pace as enqueueing without concurrency to stabilize the system;

Disruptor says this is the highest performance mechanism for this type of data exchange. By focusing on a clear separation of the issues involved in cross-thread data exchange, by eliminating write contention, minimizing read contention, and ensuring that code works well with caches used by modern processors, you create an efficient mechanism for exchanging data between threads in any application.

Batch effects that allow consumers to process data up to a given threshold without any contention; For most systems, the delay increases exponentially as load and contention increase, the characteristic “J” curve. As the load on Disruptor increases, the latency remains almost constant until the memory subsystem saturates.