Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NanoLOB - Ultra-Low Latency Limit Order Book

High-performance matching engine in C++23, achieving sub-100ns core latency on a million price levels.

1. Key Performance

Environment: 11th Gen Intel(R) Core(TM) i5-11400H @ 2.70GHz, MSVC (Release mode), Windows/WSL2.

NanoLOB compilation&run

Note on Benchmarking: The report shows two consecutive runs. The first (10k levels) serves as a CPU warm-up, stabilizing frequency and caches. The second run demonstrates the engine's performance on 1,000,000 price levels, maintaining sub-microsecond P99.9 latency.

This benchmark is located in bench/OrderBookBenchBuyExisted.cpp

2. Architecture & Design Decisions

  • boost::intrusive::list and absl::flat_hash_map: Provide amortized O(1) "add", "delete", "find".
  • Hierarchical Bitsets: Used for best-price discovery.
  • Zero-Allocation Path: No dynamic memory allocation in the hot loops (Object Pooling & Arrays).
  • Asynchronous Pipeline: OrderBook -> [SPSC] -> Logger -> [SPSC WAL] -> Outputer
  • Lock-free Primitives: Custom SPSC queues for minimal inter-thread jitter.
  • Mechanical Sympathy: Explicit cache-line alignment (alignas(64)) and branch prediction hints ([[likely]]).
  • Persistence & Recovery (WAL): Integrated a Write-Ahead Logging strategy. All incoming events are asynchronously streamed to a persistent segment. This ensures data recoverability and consistency in case of a system crash.
  • Fault Tolerance & Burst Handling: The pipeline architecture uses pre-allocated lock-free SPSC queues as high-speed buffers. This provides a safety margin that absorbs traffic spikes without backpressuring the critical matching path.

3. Benchmarking Methodology

  • Measured using TSC (Time Stamp Counter) with serialization barriers (rdtscp) to eliminate out-of-order execution noise.
  • Ticks are converted to nanoseconds only in the Outputer to minimize hot-path overhead

4. Build-time Configuration (CMake)

add_compile_definitions(MAX_ORDERS=2'100'000ULL) # Pre-allocated memory
add_compile_definitions(NANOSECONDS_PER_STATS_SNAPSHOT=2*10'000'000'000ULL) # Telemetry interval
add_compile_definitions(RESET_WAL_FILES=true) # Continue read where program stopped earlier
add_compile_definitions(CLEAR_LOGGER_STATS_AFTER_SNAPSHOT=false) # False if you want to see full statistics

5. How to Run

mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j
./benchmark_orderbook

Build & Benchmark Run Proof

NanoLOB compilation&run

6. Dependencies

This project uses the following libraries:

About

Ultra-Low Latency Limit Order Book with Hierarchical Bitsets

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages