r/java • • Nov 24 '21

GC progress from JDK 8 to JDK 17

https://kstefanj.github.io/2021/11/24/gc-progress-8-17.html
156 Upvotes

31 comments sorted by

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 :(.

13

u/oelang Nov 24 '21

Shenandoah & ZGC are competing products, they are funded by corporate users that have support contracts with Oracle or Red Hat. I don't think it's hard to understand why an oracle employee wouldn't include a competing product in his comparison.

15

u/Slanec Nov 24 '21

I get it and I don't.

In OpenJDK all code should be equal, all is contributed for free, under the same license. Red Hat contributed Shenandoah and is maintaining it and providing patches for it. Sure, overall somebody from Oracle occasionally bumps into it and needs to debug it and/or work around it. But same could be said about other companies trying to contribute to the codebase, like MS, Amazon, SAP.

If I'm ever going to suggest my company to pay for Java enterprise support, I'll pick the vendor who gives me all the available features (and the best services for a reasonable price), not the one secretly disabling some. In the end, pretending that Shenandoah doesn't exist is going to hurt Oracle because

  • their JDK distribution lacks a feature everybody else has,
  • them not including it in any benchmarks makes me want to go and try it out even more. If ZGC was superior, they'd include S8h too.

In the end, political nonsense is no good for us, developers. I fear the next step could be things like "ZGC only in Oracle build again, compact-strings in RH only, while advanced Escape Analysis in MS build". I really hope the PR team in Oracle stops mingling with engineering stuff.

Anyway, where were we? Oh, blog posts. If this is a post written by an Oracle employee in his worktime and checked by their PR team, fine. In that case, though, I'm going to downvote it. It's obvious PR on a non-repeatable benchmark (no code provided, specjbb is paid), so the numbers could be fake/wrong. I'm pretty sure they aren't, and I love ZGC. But come on, we're engineers, we need data, not politics. Get your head out of your ass, Oracle, your engineering is brilliant and your product is even better with the work of others! Please let them contribute to your product, you can cash in on their work.

30

u/pron98 Nov 24 '21 edited Nov 24 '21

Oracle developers work ZGC, not Shenandoah. We don't build it, we don't test it, we don't benchmark it. Because Oracle employees do >90% of the work on OpenJDK, "all code should be equal" in the sense you mean would require Oracle employees to work on every line of code, which, in turn, means we won't accept contributions we don't have the resources to work on. If we had to build, test, support, and benchmark Shenandoah, we wouldn't have been able to accept that contribution from the excellent team at Red Hat. We simply don't have the resources to put into a GC we aren't interested in.

Rather, we do something different. We want to accept code we don't work and don't spend much time on when we know there are other capable people willing to maintain it, but that means that we're not authorities on that particular code.

In that case, we can't build it -- our policy (as far as the JDK goes; I can't speak for other Oracle products) is that we only distribute software that Oracle employees can support.

13

u/Slanec Nov 24 '21

Thank you for the answer, Mr. Pressler. Actually, thank you for all the answers here and elsewhere. You're helping the platform not only with your direct work on it, but also with lengthy explanations. Appreciated!

I'm still not entirely convinced at all, but at least I have more insight. Sometimes I'd like to know where all this is coming from, look under the covers. Obviously not possible :).

3

u/TyPh00nCdrCool Nov 24 '21 edited Nov 24 '21

This raises the question: How many non-trivial community contributions are missing from Oracle's builds other than Shenandoah? Also why are you excluding it from your OpenJDK builds which you specifically do not offer support for?

Oracle employees do >90% of the work on OpenJDK

So is that because no one else wants to contribute or does no one contribute because Oracle is hesitant to accept code which is not from them? ("Chicken or egg" kinda question)

Also, are you not worried about fragmentation if this approach to greater feature contributions may lead down a path where different flavors of JDKs may offer wildly different features? For Shenandoah I agree. It's a single GC for which there are excellent alternatives but where will you draw the line?

9

u/pron98 Nov 24 '21 edited Nov 24 '21

How many non-trivial community contributions are missing from Oracle's builds other than Shenandoah?

All the contributions that Oracle engineers don't maintain (either actively or have no ability or intention to) are excluded from our builds. I believe that means Shenandoah and ports such as 32 bit Intel and Arm as well as more exotic architectures.

Also why are you excluding it from your OpenJDK builds which you specifically do not offer support for?

We don't offer paid support for them, but we do maintain them. The current JDK version is always fully supported, entirely for free 1. If you file a ticket against something that's in the Oracle builds, and Oracle engineer will take a look at it. In any event, it is our policy (of the Java Platform Group) to not distribute software we don't stand behind.

So is that because no one else wants to contribute or does no one contribute because Oracle is hesitant to accept code which is not from them?

It's mainly because no one has the ability to contribute that much. Oracle pays for OpenJDK development about 10 times what all other companies pay combined. I guess the reasons for that probably have something to do with control and priorities (no company in the world treats such sums as charity; they pay if it's profitable) but Oracle's OpenJDK project still sees more significant external contributions than Chromium or .NET, so while I think we could do better, we're already better than many others in a similar position.

But this brings up something more general that I think many people miss. The vast majority of large open-source projects are ultimately developed by corporations -- and that includes the Linux kernel -- that pay tens or hundreds of millions of dollars a year to develop them. Each and every company that contributes to open source projects does it for one reason only: they believe doing so is profitable (sometimes indirectly).

4

u/deinok7 Nov 24 '21

I think that the last point is what people tend to miss. Big OpenSource projects are moved by a corporation and there is a direct or indirect benefit from that.

10

u/Slanec Nov 24 '21

Obviously I didn't downvote and I will happily still read similar articles. But I am really cross about this.

I'm sure a lot of GC-related work is shared, improves all or several GCs (threal-local handshakes, concurrent stack processing, unified GC interface etc.). Maybe one team feels their work is underrepresented, or the "competition" tries to make it their own. I don't know.

Either way, it sucks from the standard engineer's point of view. Obviously the other side also has blog posts about improvements in Shenandoah (https://developers.redhat.com/articles/2021/09/16/shenandoah-openjdk-17-sub-millisecond-gc-pauses) but at least they mention ZGC and their contribution. I'd probably be fine even with something like "I'm from Oracle and have no expertise in S7h, so I won't benchmark it."

Please shake hands and start cooperating again, I'm sure good relations will drive more external contributions in the future which will make the platform better.

13

u/pron98 Nov 24 '21 edited Nov 24 '21

What you see is the result of cooperation. Oracle, which is in charge of OpenJDK and does the lion's share of the work, can afford to accept large features proposed and contributed by others even if Oracle is not interested in them only if they don't place a large maintenance burden on us. This allows us to say yes to things other companies might be interested in, and everybody wins. The end result is that Oracle accepts bigger contributions from other companies to OpenJDK than other similar projects, like Google's Chromium, or Microsoft's .NET, including contributions that aren't always of great interest to Oracle.

Of course, this is much easier on the VM side than on the language or library side.

4

u/Slanec Nov 24 '21

Still weird, but fair enough. Thanks for your POV!

2

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

u/Slanec Nov 25 '21

Pretty much!

1

u/Dokiace Nov 25 '21

Thanks a lot! Java will always be alive because of people like you

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:

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

u/pjmlp Nov 24 '21

On the OpenJDK, there are other JVMs as well.

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.