How abc-arbitrage/disruptor-cpp works
Purpose and Build Surface
Disruptor-cpp is a C++ port of LMAX Disruptor: an in-process, low-latency concurrent event pipeline built around preallocated ring buffers and sequence coordination. The root build defines the library and optional test/performance targets: CMakeLists.txt, Disruptor/CMakeLists.txt, Disruptor.cmake. Primary consumable API is header-centric under Disruptor/; no network, database, or web-service boundary exists.
Application Entry Points
Library users construct Disruptor::disruptor<T>, register handlers, start a scheduler, publish into its ring buffer, then shut down. The fluent orchestration entry point is Disruptor/Disruptor.h; the storage/publishing surface is Disruptor/RingBuffer.h. Executable entry points are benchmark runner Disruptor.PerfTests/main.cpp and unit-test runner Disruptor.Tests/main.cpp.
Event Storage and Publication
RingBuffer<T> owns a fixed-size, precreated event array and exposes claiming/publishing APIs. A sequencer assigns monotonically increasing sequence numbers, gates producers on consumer progress, and publishes availability:
• Disruptor/RingBuffer.h
• Disruptor/Sequencer.h
• Disruptor/SingleProducerSequencer.h
• Disruptor/MultiProducerSequencer.h
Producer mode is selected through Disruptor/ProducerType.h. The key data boundary is sequence-indexed mutable event slots: producers populate an acquired slot before publishing it; consumers read only published sequences.
Consumer Graph Assembly
The high-level disruptor constructs a dependency graph of event handlers/processors. Handler groups model fan-out and downstream dependencies; the repository tracks consumer metadata and updates gating sequences so upstream producers do not overwrite unconsumed slots:
• Disruptor/Disruptor.h
• Disruptor/EventHandlerGroup.h
• Disruptor/ConsumerRepository.h
• Disruptor/SequenceGroups.h
This is the primary control-plane boundary: registration occurs before start(), which materializes processors and schedules their run loops.
Consumption, Barriers, and Work Sharing
A ProcessingSequenceBarrier makes a consumer wait for a dependent/published sequence and propagates alerts during shutdown. BatchEventProcessor invokes ordered IEventHandler<T> callbacks, while WorkProcessor/WorkerPool distribute each event to one worker rather than broadcasting it:
• Disruptor/ProcessingSequenceBarrier.h
• Disruptor/BatchEventProcessor.h
• Disruptor/WorkProcessor.h
• Disruptor/WorkerPool.h
EventPoller.h provides a caller-driven polling alternative to dedicated processor loops.
Synchronization and Execution Runtime
Sequence is the shared progress primitive; barriers delegate waiting/signaling to selectable wait strategies. Strategies trade CPU use for latency, from blocking/timeout to busy-spin, yielding, sleeping, and phased backoff:
• Disruptor/Sequence.h
• Disruptor/IWaitStrategy.h
• Disruptor/BlockingWaitStrategy.h
• Disruptor/BusySpinWaitStrategy.h
Processors execute through scheduler abstractions, with per-task threads or round-robin thread-affined scheduling:
• Disruptor/ITaskScheduler.h
• Disruptor/ThreadPerTaskScheduler.h
• Disruptor/RoundRobinThreadAffinedTaskScheduler.h
Platform-specific thread support is separated in Disruptor/ThreadHelper_Linux.cpp, Disruptor/ThreadHelper_Windows.cpp, and Disruptor/ThreadHelper_macOS.cpp.
Failure, Validation, and Measurement
Consumer callback failures are routed through configurable exception handlers, including fatal and ignore policies: Disruptor/IExceptionHandler.h, Disruptor/FatalExceptionHandler.h, Disruptor/ExceptionHandlerWrapper.h. Unit tests validate concurrency primitives and graph behavior in Disruptor.Tests/; performance scenarios exercise producer/consumer topologies through Disruptor.PerfTests/TestRepository.cpp and session result types. Build dependencies are CMake, Boost, optional Conan, and vendored GoogleTest/GoogleMock (googletest-release-1.8.0/); CI targets Travis and AppVeyor.
Main entry points: Disruptor.h disruptor<T> · ProcessingSequenceBarrier.h ProcessingSequenceBarrier · Sequencer.h Sequencer · CMakeLists.txt CMake build surface
Components 18
Build & validation
- CMake build surface · Builds the library plus optional tests and performance targets.
CMakeLists.txt - Unit-test runner
Disruptor.Tests/main.cpp - Benchmark runner
Disruptor.PerfTests/main.cpp
Public orchestration
- disruptor<T> · Registers consumers, builds dependencies, starts and shuts down the pipeline.
Disruptor/Disruptor.h - EventHandlerGroup · Expresses fan-out and downstream handler dependencies.
Disruptor/EventHandlerGroup.h - ConsumerRepository · Tracks consumer metadata while assembling the graph.
Disruptor/ConsumerRepository.h - SequenceGroups · Updates producer gating sequences from consumer progress.
Disruptor/SequenceGroups.h
Event pipeline
- RingBuffer<T> · Preallocates mutable sequence-indexed event slots for publication and consumption.
Disruptor/RingBuffer.h - Sequencer · Claims sequences, gates producers, and publishes availability.
Disruptor/Sequencer.h - Producer sequencers · Single- and multi-producer implementations select claim coordination.
Disruptor/ProducerType.h - ProcessingSequenceBarrier · Waits for published and dependent sequences and propagates shutdown alerts.
Disruptor/ProcessingSequenceBarrier.h - BatchEventProcessor · Invokes ordered IEventHandler<T> callbacks.
Disruptor/BatchEventProcessor.h - WorkerPool · Uses WorkProcessor instances so one worker handles each event.
Disruptor/WorkerPool.h - EventPoller · Alternative to dedicated processor run loops.
Disruptor/EventPoller.h
Runtime & synchronization
- Sequence · Shared atomic progress state for producers and consumers.
Disruptor/Sequence.h - Wait strategies · Blocking, busy-spin, and other policies trade CPU use for latency.
Disruptor/IWaitStrategy.h - Task schedulers · Runs processor loops on per-task or thread-affined scheduling.
Disruptor/ITaskScheduler.h - Exception handlers · Routes consumer callback failures to fatal or configurable handlers.
Disruptor/IExceptionHandler.h
Connections 24
- CMake build surface → disruptor<T>: builds library
- CMake build surface → Unit-test runner: optional target
- CMake build surface → Benchmark runner: optional target
- Unit-test runner → disruptor<T>: validates
- Benchmark runner → disruptor<T>: exercises topologies
- disruptor<T> → EventHandlerGroup: defines dependencies
- disruptor<T> → ConsumerRepository: registers consumers
- EventHandlerGroup → SequenceGroups: derives gating
- ConsumerRepository → Task schedulers: schedules at start
- disruptor<T> → RingBuffer<T>: creates pipeline storage
- RingBuffer<T> → Sequencer: claims and publishes
- Producer sequencers → Sequencer: selects implementation
- SequenceGroups → Sequencer: gates overwrite
- Sequencer → ProcessingSequenceBarrier: publishes availability
- ProcessingSequenceBarrier → BatchEventProcessor: releases ordered events
- ProcessingSequenceBarrier → WorkerPool: releases work
- RingBuffer<T> → EventPoller: polls events
- Sequence → Sequencer: tracks producer and consumer progress
- Sequence → ProcessingSequenceBarrier: checks dependencies
- Wait strategies → ProcessingSequenceBarrier: waits and signals
- Task schedulers → BatchEventProcessor: runs loop
- Task schedulers → WorkerPool: runs workers
- BatchEventProcessor → Exception handlers: routes callback failures
- WorkerPool → Exception handlers: routes callback failures