Skip to content

vivkver/chronos

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

16 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Project CHRONOS

Deterministic Limit Order Book (LOB) for Sub-Microsecond Matching

🌐 Visit the Website

A production-grade, ultra-low latency (ULL) trading system built in Java, demonstrating HFT-level performance engineering across 5 integrated services.

Java 21 Aeron Vector API Zero GC SBE


Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                 β”‚     β”‚      Aeron Cluster (Raft)            β”‚     β”‚                    β”‚
β”‚  FIX Gateway    │────▢│  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  │────▢│  Response Gateway   β”‚
β”‚  (Ingress)      β”‚ SBE β”‚  β”‚  Sequencer  │──│  Matching    β”‚  β”‚ SBE β”‚  (Egress)           β”‚
β”‚                 β”‚     β”‚  β”‚  (Spinal    β”‚  β”‚  Engine      β”‚  β”‚     β”‚  + HDRHistogram     β”‚
β”‚  β€’ TCP/NIO      β”‚     β”‚  β”‚   Cord)     β”‚  β”‚  (Brain)     β”‚  β”‚     β”‚  β€’ P99.99 tracking  β”‚
│  ‒ FIX Parser   │     │  │             │  │  ‒ SIMD/AVX  │  │     │  ‒ SBE→FIX encode   │
│  ‒ FIX→SBE      │     │  │  ‒ Total    │  │  ‒ Off-heap  │  │     │                    │
β”‚  β€’ Zero-alloc   β”‚     β”‚  β”‚    Order    β”‚  β”‚    LOB       β”‚  β”‚     β”‚                    β”‚
31: β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                         β”‚
                        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                        β”‚  Warmup Service (AOT/CDS)          β”‚
                        β”‚  β€’ JIT training runs               β”‚
                        β”‚  β€’ CDS archive generation          β”‚
                        β”‚  β€’ GraalVM PGO support             β”‚
                        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Key Performance Techniques

Technique Where Why
Zero Allocation FIX parser, SBE codecs, matching engine Eliminate GC pauses β€” no objects created on hot path
SIMD Vectorization VectorizedPriceScanner Compare 8 price levels per CPU cycle (AVX-512)
Off-Heap Memory OffHeapOrderBook 64-byte cache-line-aligned order slots via Agrona UnsafeBuffer
SOA Layout Order book price arrays Structure-of-Arrays enables SIMD-friendly contiguous memory access
SBE Encoding All inter-service messaging Flyweight codec with zero-copy reads β€” no deserialization
Aeron Cluster Sequencer Raft consensus for deterministic total ordering
Fixed-Point Arithmetic Prices long scaled by 10⁸ β€” eliminates floating-point non-determinism
Core Pinning All services taskset -c N eliminates context-switch jitter
ZGC JVM flags Generational ZGC for sub-millisecond pause times

Project Structure

chronos/
β”œβ”€β”€ chronos-schema/          # SBE message codecs (flyweight encoders/decoders)
β”œβ”€β”€ chronos-core/            # Domain model + off-heap order book
β”œβ”€β”€ chronos-matching/        # SIMD matching engine (Vector API)
β”œβ”€β”€ chronos-sequencer/       # Aeron Cluster service (Raft)
β”œβ”€β”€ chronos-fix-gateway/     # FIX protocol ingress
β”œβ”€β”€ chronos-response-gateway/# Execution report egress + latency tracking
β”œβ”€β”€ chronos-warmup/          # JIT training & AOT cache generation
└── chronos-benchmarks/      # JMH + wire-to-wire + JFR zero-GC proof

Prerequisites

  • JDK 21+ (GraalVM CE recommended for faster JIT warmup)
  • Gradle 9.x (wrapper included)

Quick Start

# Build all modules
./gradlew build

# Run JMH benchmarks (SIMD vs scalar, SBE vs string-based)
./gradlew :chronos-benchmarks:jmh

# Run wire-to-wire benchmark (1M orders)
./gradlew :chronos-benchmarks:run

# Run warmup training
./gradlew :chronos-warmup:run

# Start the sequencer (Aeron cluster node)
./gradlew :chronos-sequencer:run

# Start the FIX gateway (TCP port 9876)
./gradlew :chronos-fix-gateway:run

# Start the response gateway
./gradlew :chronos-response-gateway:run

Performance Highlights

For detailed benchmark results, methodology, and the Linux optimization guide, please see BENCHMARK_GUIDE.md.

  • FIX Parsing: 110ns (vs 542ns QuickFIX/J)
  • Wire-to-Wire Latency: < 50Β΅s (Linux Optimized)
  • Zero GC: Verified via JFR on critical paths.

Production Deployment

Recommended JVM Configuration

java -XX:+UseZGC \
     -XX:+ZGenerational \
     -Xms8g -Xmx8g \
     -XX:SoftMaxHeapSize=6g \
     --add-modules jdk.incubator.vector \
     --add-opens java.base/sun.misc=ALL-UNNAMED \
     -jar chronos-sequencer.jar

GC Selection:

  • Production: ZGC with generational mode (sub-millisecond GC pauses)
  • Benchmarking: Epsilon GC (no-op GC for zero-allocation verification)
  • Development: G1GC (default, balanced)

See docs/gc-selection-guide.md for detailed GC configuration guidance.

CPU Isolation (Linux)

# Isolate cores 2-5 from the OS scheduler
# Add to kernel boot params: isolcpus=2-5 nohz_full=2-5
taskset -c 2 java -jar chronos-sequencer.jar
taskset -c 3 java -jar chronos-fix-gateway.jar
taskset -c 4 java -jar chronos-response-gateway.jar

CDS Archive (Fast Startup)

# Step 1: Train and dump class list
java -Xshare:off -XX:DumpLoadedClassList=chronos.classlist -jar chronos-warmup.jar

# Step 2: Create CDS archive
java -Xshare:dump -XX:SharedClassListFile=chronos.classlist -XX:SharedArchiveFile=chronos.jsa

# Step 3: Run with CDS
java -Xshare:on -XX:SharedArchiveFile=chronos.jsa -jar chronos-sequencer.jar

Future Exploration (JDK 26+)

These features are currently in preview/incubator but will enhance CHRONOS when stabilized:

Feature JEP Benefit
Project Valhalla (Value Classes) JEP 401 Eliminate object headers for Order/PriceLevel β€” better cache density
Project Panama (FFM API finalized) JEP 454 Replace Unsafe with MemorySegment + Arena for safer off-heap access
Vector API (finalized) JEP 489 Remove --add-modules jdk.incubator.vector flag
Project Leyden (AOT Cache) JEP draft Native AOT cache replacing CDS for instant startup

License

Apache License 2.0

About

A deterministic, high-frequency trading platform built on Agrona and Aeron. Designed for zero garbage collection and predictable microsecond-level latency.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors