7 JVM arguments of Highly Effective Applications

View Reddit by mike_jackView Source

Categories: JAVA


brunocborges · September 10, 2020 at 6:38 am

Nice article, but item #6 is pointless.

`sun.net.client.defaultConnectTimeout` and `sun.net.client.defaultReadTimeout` are only used by java.net.URLConnection, which is a pretty basic API that in reality very few developers use in production.

In newer versions of Java (I believe Java 11+), this property is no longer documented. Developers should really use the new HttpClient API, or a 3rd-party library (which is mostly the case).

armarz · September 10, 2020 at 7:09 am


giorgiga · September 10, 2020 at 11:08 am

Here’s the TOC, in case you are unsure you want to read the article:

1. -Xmx and -XX:MaxMetaspaceSize
2. GC Algorithm
3. Enable GC Logging
4. -XX:+HeapDumpOnOutOfMemoryError, -XX:HeapDumpPath
5. -Xss
6. -Dsun.net.client.defaultConnectTimeout and -Dsun.net.client.defaultReadTimeout
7. -Duser.timeZone

pmarschall · September 10, 2020 at 12:59 pm

I disagree with 7:

– `java.util.Date` has no time zone
– I would strongly recommend against using `java.util.Calendar` on any Java 8+ application and recommend using the `java.time` types instead
– If your application requires a specific time zone then that should be in the code, not a no JVM wide flag. Relying on `user.timeZone` feels like relying on `file.encoding` rather than explicitly passing the required file encoding.

jangirakah · September 10, 2020 at 1:28 pm

This is a helpful article. Thanks for sharing!

PM-ME-GOOD-NEWS · September 10, 2020 at 3:11 pm

Can someone give me a reason why its not best practice to put business logic in vm arguments vs program arguments?

cogman10 · September 10, 2020 at 6:01 pm

I’m going to disagree that all these settings need setting.

1. Xmx should only be set if you are running the JVM outside of a container environment. Otherwise, the JVM will pick up the container’s max memory setting and use that.MaxMetaspaceSize is another that I don’t know the utility of setting.
2. The GC algorithm selected should be based on the application type. This article, for example says ” we are observing excellent performance results with Z GC algorithm ” But what does that mean? There are two critical performance metrics, throughput and latency that are in conflict with each other. ZGC has excellent latency with poor throughput. On the flip side, the parallel collector has excellent throughput with poor latency. G1GC is a middle ground between the two. Saying “It has high performance” is meaningless as there are multiple metrics that really matter!If your app is doing batch processing, you probably don’t care so much about a 1 second pause, you care more that your apps is crushing data as fast as possible. On the flip side, if your app is a webservice, 10ms of latency might be too much, which makes ZGC a good option.Even further, if your app is running on a docker container with only 1 core assigned to it, then the serial collector might be the best option for you generally as you don’t (or aren’t supposed to) have access to multiple cores.
3. IMO, Flight recorder is far more important than GC logging. It contains the same information with a LOT more detail (if you want it). You should use and be familiar with that instead.
4. I agree, always save off heap dumps.
5. Xss should only be set when you know you need it! The default setting (1mb) is really reasonable for 90% of applications. Don’t screw with a setting like this until you have evidence that you need it.

6 and 7 don’t seem like essential settings. I’ve never set them and have never ran into scenarios where my app would have been way better with them.

In general, the JVM often works best if you don’t screw with settings. They are constantly updating and tweaking heuristics which will benefit your app simply by staying up to date on the JVM you are using. Developers that know, know that you shouldn’t touch any flags in the JVM until you’ve got good evidence it is a useful thing to touch.

Leave a Reply

Your email address will not be published. Required fields are marked *