Skip to main content

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.

TransportIdle StrategyPinned99.999%Over Base
IPC_UDPorg.agrona.concurrent.NoOpIdleStrategyYes11.5us1.00x
IPC_UDPorg.agrona.concurrent.NoOpIdleStrategyNo61.9us5.39x
IPC_UDPorg.agrona.concurrent.SleepingMillisIdleStrategyNo1.06ms92.17x
IPC_UDPorg.agrona.concurrent.SleepingMillisIdleStrategyYes1.11ms96.52x
TCPorg.agrona.concurrent.NoOpIdleStrategyYes1.29ms112.17x
TCPorg.agrona.concurrent.NoOpIdleStrategyNo1.67ms145.22x
TCPorg.agrona.concurrent.SleepingMillisIdleStrategyNo2.38ms206.96x
TCPorg.agrona.concurrent.SleepingMillisIdleStrategyYes2.42ms210.43x

From the best to worst case in this measurement, transport selection, idle strategy and CPU pinning changed tail latency by more than 200x.

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.