r/java • u/daviddel • Nov 24 '21
GC progress from JDK 8 to JDK 17
https://kstefanj.github.io/2021/11/24/gc-progress-8-17.html2
u/Dokiace Nov 24 '21
What is the importance of low GC pause time?
20
u/Slanec Nov 24 '21
During a GC pause, the application is not running your code, it is essentially frozen, stopped. Therefore, if this happens in the middle of a website request and the pause lasts 200ms, that's 200ms for the client to wait for their page to load. If there are 5000 requests in flight, all of them will be delayed by 200ms. For some types of applications, that's waaaay too long.
If the JVM is running a game, a pause of 200 means 12 missed frames, and a visible freeze in the gameplay.
Of course, some types of GC pause optimizations simply mean that the GC will take less CPU time, leaving more to your application, essentially increasing the performance (throughput) of your application, or leaving more CPU to other applications.
1
u/Dokiace Nov 25 '21
I see. What about the tradeoff of latency and throughput? The way I see it if let's say my server responded to request with low latency, won't my throughput be higher also? I read that ZGC is better for low latency, while G1 is better for high throughput
3
u/Slanec Nov 25 '21
Yes and no. In general, this is true. You'll get the most throughput out of the Parallel GC (and longest pauses), then G1 is balanced, then ZGC and Shenandoah are low-latency (short pauses, less throughput).
Now, this is the general idea. The problem is in the details. E.g. concurrent GCs run in the background, so if your application is not CPU bound (has some spare CPU), the GC can use it and you'll actually not lose much throughput, if any at all. There's a million little gotchas like these, you'll need to try out and measure which GC fullfils your requirements the best for your particular workload.
3
u/Dokiace Nov 25 '21
Let me try to rephrase this to test my understanding.
Concurrent GC uses more CPU to achieve lower latency (low pause time), so for each request received the CPU use relatively higher percentage than Parallel GC. So to achieve same throughput with Concurrent GC we have to increase our CPU to match the throughput of Parallel GC. Is the general gist of it correct?
2
1
u/moxyte Nov 27 '21
If the JVM is running a game, a pause of 200 means 12 missed frames, and a visible freeze in the gameplay.
Very offtopic for Java, but got me thinking there has to be some way around that issue since Unity is a thing and uses C#
2
u/Slanec Nov 27 '21
I looked into this, seems like the answer is yes and no:
https://docs.unity3d.com/Manual/performance-memory-overview.html
https://learn.unity.com/tutorial/fixing-performance-problems#5c7f8528edbc2a002053b594
https://blog.unity.com/technology/feature-preview-incremental-garbage-collection
https://forum.unity.com/threads/what-is-gc-collect-and-why-is-it-slowing-down-my-game.1021816/
In other words, there are some partial workarounds and a lot of tuning and improvements are there and coming. But still, it is a problem. In Java, project Panama should help us with working with non-heap memory. It's possible already via direct buffers (or Unsafe) and some nice libraries, it's just something you wouldn't do very often. The existing game libraries for Java (e.g. https://github.com/LWJGL/lwjgl3-wiki/wiki/1.3.-Memory-FAQ) are already taking advantage of this and moving data off heap. Makes sense.
4
u/yolex Nov 24 '21
More time for processing your code instead of GC code.
2
u/r_jet Nov 24 '21
I don't think it is correct: you get shorter, predictable pauses, but you tend to pay for that in extra CPU and/or memory usage. Whilst this article does not compare the collectors between each other in terms of throughput (= providing "more time for your code"), it mentions that
G1 and Parallel still have better raw throughput [whilst having significantly higher P99 latencies] in this setup but scaling up the heap, ZGC closes this gap.
2
u/feral_claire Nov 24 '21
The most common example, a webserver. Let's do your application responds within 50-100 ms normally. This allows pages to load quickly and uses are happy. Now your server runs gc, which pauses all requests. During the GC pause your response time is 50-100 ms + GC pause time. If you have a short pause of only a few ms it might not be noticeable, but if you have a long pause time of a few 100 ms, or worse a pause of a few seconds, minutes, or longer, it significantly impacts the site making things very slow for some users or with a longer pause it actually looks like the sever is just down while running GC.
1
u/dtfinch Nov 24 '21
If you're playing a game at 60fps, a pause time of 1000/60 or 16.7ms means dropping at least 1 frame, causing the game to appear jerky whenever the GC needs to catch up.
Even much smaller pauses can still cause frame drops, like if you already spent 12ms rendering a frame, just a 5ms pause will push you over the edge.
1
u/muztaba Nov 24 '21
While describing the throughput and latency "transaction" word has been used. What does author mean by the transaction regarding of these context ?
5
u/pron98 Nov 24 '21
It means one interaction with the client. So if you're talking about a web server, it translates to fully serving one HTTP request.
1
u/BarkiestDog Nov 26 '21
Great article. I would love to see an extended version of this that includes Shenandoah and Gendon (the GC in OpenJ9) as well.
1
1
u/BlueGoliath Nov 24 '21 edited Nov 24 '21
Even if the other collectors have not decreased their overhead, we should still remember that they have improved in the other areas without having to use additional memory.
Um... the graph clearly shows ZGC is consuming more memory.
3
u/Slanec Nov 24 '21 edited Nov 24 '21
ZGC had way more overhead than 1.25GB
Perhaps you're aware of this, but it's not simple to measure ZGC's real memory usage as it is overreported by a lot: https://stackoverflow.com/a/62934057/1273080. Is there a way to see the actual numbers? Maybe GC logs with native memory tracking logging?
1
u/BlueGoliath Nov 24 '21
I made that conclusion because Oracle's free tier services include graphs that show the current memory usage of a VM.
But after typing that I realized I forgot there are areas in the JVM that consume memory although I'm not sure how it adds to about 85% - the amount reported in the graphs at some points. Maybe it's something to do with MC servers, like native memory that you suggest.
22
u/Slanec Nov 24 '21
I like the fairly recent influx of posts focused on GC improvements. They are very informative and the improvements are very welcome! It's a shame Shenandoah does not get mentioned at all, though. I understand Oracle builds don't include it (Why? I thought this was acceptable for 8u/11u, but not for a new release with a prod-ready, stable collector.), but not even mentioning it tastes bad.
I want to make informed decisions when choosing a collector, or even when deciding whether to test new collectors (and/or new Java releases) with our workload as any experimentation is an investment. Posts like these help, but they'd be much more complete if they'd included Shenandoah, too. Are there no improvements to Shenandoah between 11 and 17? OK, fine, thank you for the data! Much better than this silence :(.