ВопросG1 or ZGC for a latency-sensitive API, and what JDK 27 changes

GM Giorgi M. Участник Регистрация: 11 июн. 2026 г.
Сообщений: 117
#1

A question for the JVM people. Suppose an API where p99 latency matters more than raw throughput, heap around 4 GB, JDK 25.

1. When does it make sense to move from G1 to ZGC?
2. How do you measure GC pauses before changing anything?
3. JDK 27 came out on 15 September. Which of its changes are relevant here?

ER Evgeny Rudenko Участник Регистрация: 14 авг. 2026 г.
Сообщений: 86
#2

Measure first, then decide. Unified GC logging costs almost nothing:

java -Xlog:gc*:file=gc.log:time,uptime,level,tags -jar app.jar

Look at pause times next to your p99. If the latency spikes don't line up with pauses, changing the collector won't help.

G1 aims at a pause-time goal (-XX:MaxGCPauseMillis, 200 ms by default) while keeping throughput reasonable. ZGC does almost all its work concurrently and keeps pauses very short regardless of heap size. Since JDK 24 there is only the generational mode, so plain -XX:+UseZGC is enough. The price is more CPU spent on concurrent work and the need for heap headroom: if allocation outruns the collector, threads get stalled.

# G1 with a tighter goal
java -XX:+UseG1GC -XX:MaxGCPauseMillis=100 -Xmx4g -jar app.jar

# ZGC
java -XX:+UseZGC -Xmx4g -jar app.jar

With 4 GB and pauses that do correlate with p99, ZGC is worth a load test. I would not switch in production on reading alone.

YS Yury Slinkin Сотрудник · админ Регистрация: 6 июн. 2026 г.
Сообщений: 94
#3

>>1
On 3, from the JDK 27 project page (https://openjdk.org/projects/jdk/27/):

- G1 is now the default collector everywhere. Before, on a machine or container the JVM saw as small (one CPU or under about 1792 MB of memory) it quietly picked Serial. That mostly matters for small containers.
- Compact Object Headers are on by default. In JDK 25 they became a product option (-XX:+UseCompactObjectHeaders, JEP 519): the object header shrinks from 12 to 8 bytes on 64-bit, which means a smaller heap with many small objects and less GC work.
- Hybrid post-quantum key exchange in TLS 1.3. Not related to GC, listed for completeness.

JDK 27 is not LTS. On 25 you can already try compact headers with the flag above and see the effect in the same GC log.

To see which collector the JVM actually chose:

java -XX:+PrintCommandLineFlags -version
GM Giorgi M. Участник Регистрация: 11 июн. 2026 г.
Сообщений: 117
#4

>>3
So on 25 in a small container it can be Serial without anyone noticing. Good to know. Is there a way to check a running process?

ER Evgeny Rudenko Участник Регистрация: 14 авг. 2026 г.
Сообщений: 86
#5

>>4
Yes, with jcmd from the same JDK:

jcmd <pid> VM.flags

Look for UseG1GC, UseZGC or UseSerialGC in the output. On 25 in containers I would set the collector explicitly anyway, so the choice doesn't depend on how many CPUs the orchestrator happens to give.

Быстрый ответ

Писать могут только вошедшие участники. Войти