btrace-core/JMH_BENCHMARKS.md
This document describes how to run the JMH (Java Microbenchmark Harness) benchmarks for the binary protocol v2 implementation.
The benchmarks compare the performance of the new binary protocol against Java serialization across multiple command types and data sizes.
./gradlew :btrace-core:jmh
This will run all benchmarks with default settings:
Use the jmhInclude property to filter which benchmarks to run:
# Run only serialization benchmarks
./gradlew :btrace-core:jmh -PjmhInclude=".*Serialize"
# Run only deserialization benchmarks
./gradlew :btrace-core:jmh -PjmhInclude=".*Deserialize"
# Run only round-trip benchmarks
./gradlew :btrace-core:jmh -PjmhInclude=".*RoundTrip"
# Run benchmarks for specific command type
./gradlew :btrace-core:jmh -PjmhInclude=".*InstrumentCommand.*"
# Run benchmarks for specific data size
./gradlew :btrace-core:jmh -PjmhInclude=".*small.*"
The benchmarks test the following command types:
Each command type is tested with three data sizes:
Each command type/size combination is tested with:
binarySerialize - Serialize using binary protocolbinaryDeserialize - Deserialize using binary protocoljavaSerialize - Serialize using Java serializationjavaDeserialize - Deserialize using Java serializationbinaryRoundTrip - Full round-trip with binary protocoljavaRoundTrip - Full round-trip with Java serializationHigher is better. Shows how many operations per microsecond.
Lower is better. Shows microseconds per operation.
Benchmark (commandType) (dataSize) Mode Cnt Score Error Units
BinaryProtocolBenchmark.binarySerialize MessageCommand small avgt 10 5.234 ± 0.123 us/op
BinaryProtocolBenchmark.javaSerialize MessageCommand small avgt 10 12.456 ± 0.234 us/op
This shows binary serialization is ~2.4x faster than Java serialization for small messages.
Based on architecture design goals, the binary protocol should deliver:
| Metric | Target Improvement |
|---|---|
| Serialization Speed | 3-6x faster |
| Deserialization Speed | 3-6x faster |
| Wire Size | 2-5x smaller |
| Memory Allocation | Significantly reduced |
With compression enabled (for messages >1KB):
Edit btrace-core/build.gradle to change JMH settings:
jmh {
warmupIterations = 3 // Number of warmup iterations
iterations = 5 // Number of measurement iterations
fork = 2 // Number of forked JVM processes
threads = 1 // Number of worker threads
timeUnit = 'ms' // Time unit for results
benchmarkMode = ['avgt', 'thrpt'] // Benchmark modes
}
JMH results are written to:
btrace-core/build/reports/jmh/ (if configured)Pass JMH options directly:
./gradlew :btrace-core:jmh -PjmhInclude=".*Serialize" \
--args="-prof gc -prof stack -rf json -rff results.json"
Common profilers:
-prof gc - GC profiling-prof stack - Stack traces-prof perfnorm - Normalized perf events-rf csv - CSV output-rf json - JSON output-rf text - Text output (default)Increase heap size:
./gradlew :btrace-core:jmh -Dorg.gradle.jvmargs="-Xmx4g"
Reduce iterations:
jmh {
warmupIterations = 1
iterations = 2
fork = 1
}
Enable JMH verbose output:
./gradlew :btrace-core:jmh --args="-v EXTRA"