Best Practices
GC Strategy
KeySquare has tested and highly recommends using Generational ZGC if on Java 21 and ZGC on Java 17.
For Java 21, the following configuration has been tested:
java \
-Xlog:gc*:logs/component.gc.log:time,uptime \
-XX:+UseZGC -XX:+ZGenerational -Xmx$MAX_HEAP_SIZE_TO_USE -XX:SoftMaxHeapSize=$SOFT_MAX_HEAP_SIZE_TO_USE \
-XX:-ZUncommit -XX:ZUncommitDelay=300 -XX:+AlwaysPreTouch \
--add-opens java.base/jdk.internal.misc=ALL-UNNAMED
Measured Impact
The combination of transport, idle strategy and CPU pinning has a large impact on tail latency.
| Transport | Idle Strategy | Pinned | 99.999% | Over Base |
|---|---|---|---|---|
IPC_UDP | org.agrona.concurrent.NoOpIdleStrategy | Yes | 11.5us | 1.00x |
IPC_UDP | org.agrona.concurrent.NoOpIdleStrategy | No | 61.9us | 5.39x |
IPC_UDP | org.agrona.concurrent.SleepingMillisIdleStrategy | No | 1.06ms | 92.17x |
IPC_UDP | org.agrona.concurrent.SleepingMillisIdleStrategy | Yes | 1.11ms | 96.52x |
TCP | org.agrona.concurrent.NoOpIdleStrategy | Yes | 1.29ms | 112.17x |
TCP | org.agrona.concurrent.NoOpIdleStrategy | No | 1.67ms | 145.22x |
TCP | org.agrona.concurrent.SleepingMillisIdleStrategy | No | 2.38ms | 206.96x |
TCP | org.agrona.concurrent.SleepingMillisIdleStrategy | Yes | 2.42ms | 210.43x |
From the best to worst case in this measurement, transport selection, idle strategy and CPU pinning changed tail latency by more than 200x.
Related Guidance
Other best-practice guidance is covered with the relevant topic:
- Session covers transport mode and session configuration.
- Threading Model covers idle strategies, the session thread and core pinning.
- Platform Best Practices covers host-level tuning, core isolation and platform process pinning.