graph LR
A[Network Thread] -->|Orders| B(SPSC Ring Buffer)
B -->|Sequenced Orders| C[Matching Engine]
- Network Thread: Simulates high-throughput order ingestion.
- SPSC Ring Buffer: A lock-free Single-Producer Single-Consumer queue ensuring low-latency data transfer between threads without mutex contention.
- Matching Engine: A deterministic limit order book processor handling order execution, matching, and book updates.
- Lock-Free SPSC Queue: Implemented using
std::atomicwith relaxed consistency andalignas(64)to prevent False Sharing. - Zero-Allocation Architecture: Uses a pre-allocated object pool (
std::vector) and pointer-basedstd::priority_queueto eliminate dynamic memory allocation on the hot path. - C++20 Concepts: Utilizes
std::span,std::jthreadand modern memory ordering. - HFT Metrics: Benchmarking suite includes p99 and p99.9 latency analysis.
- Throughput: ~3.2 Million orders/second (Single Core)
- End-to-End Latency (Under Load): ~450 microseconds (p99)
- Core Matching Latency: ~300 nanoseconds/order (implied)
See benchmark_results.txt for latest run statistics.
The project includes a comprehensive helper script run_profile.sh for building, running, and benchmarking the engine.
- C++20 compatible compiler (GCC 10+ or Clang 12+)
- CMake 3.15+
- Make
-
Grant execution permissions:
chmod +x run_profile.sh
-
Build and Run: You can use the script to clean build, compile, and run the matching engine or benchmarks.
-
Build & Run Main Engine:
./run_profile.sh
This command will compile the project and start the main matching engine application.
-
Run Latency Benchmarks:
./run_profile.sh benchmark
This will compile and execute the latency benchmark suite, which measures order processing time and throughput.
-