Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NanoMatch: High-Frequency Lock-Free Matching Engine (C++20)

Architecture

graph LR
    A[Network Thread] -->|Orders| B(SPSC Ring Buffer)
    B -->|Sequenced Orders| C[Matching Engine]
Loading
  • 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.

Key Features

  • Lock-Free SPSC Queue: Implemented using std::atomic with relaxed consistency and alignas(64) to prevent False Sharing.
  • Zero-Allocation Architecture: Uses a pre-allocated object pool (std::vector) and pointer-based std::priority_queue to eliminate dynamic memory allocation on the hot path.
  • C++20 Concepts: Utilizes std::span, std::jthread and modern memory ordering.
  • HFT Metrics: Benchmarking suite includes p99 and p99.9 latency analysis.

Performance

  • 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.

Build Instructions

The project includes a comprehensive helper script run_profile.sh for building, running, and benchmarking the engine.

Prerequisites

  • C++20 compatible compiler (GCC 10+ or Clang 12+)
  • CMake 3.15+
  • Make

Usage

  1. Grant execution permissions:

    chmod +x run_profile.sh
  2. 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.

About

Ultra-low-latency limit order book featuring a cache-aligned lock-free queue and pointer-based matching logic, optimized for sub-microsecond reaction times on multicore systems.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages