Java performance testing — Epsilon garbage collector

For many people that may be a trivial issue, but I have just learned that there is a special kind of garbage collector in JVM that is useful during performance testing (available since Java 11).

What does a garbage collector in JVM do?

The JVM garbage collector is responsible for allocating memory and releasing it. The second task is kind of what we expect, but it is worth noting that the garbage collector also allocates the memory.

Epsilon garbage collector

The Epsilon garbage collector only allocates memory. It cannot release any allocated memory, so the application is very likely to crash because of an OutOfMemoryError. It is a terrible idea in production, but it has some significant advantages when we are doing a performance test of an application.

The most significant advantage is no GC overhead. The JVM does not pause to clear the memory because it does not even try to release any memory. The garbage collector does not affect the result of the test.

It means that for the first time on JVM, when we do a performance test, and we see terrible results, we no longer have an excuse: “probably GC stopped the process for a while.” Now, a bad outcome of a test is our fault exclusively.

How to use the Epsilon garbage collector?

It is one of the experimental features, so first of all, we need to unlock the experimental features using this JVM runtime parameter:

1
-XX:+UnlockExperimentalVMOptions

Then we can add another JVM parameter which changes the garbage collector used by the process:

1
-XX:+UseEpsilonGC

Did you enjoy reading this article?
Would you like to learn more about software craft in data engineering and MLOps?

Subscribe to the newsletter or add this blog to your RSS reader (does anyone still use them?) to get a notification when I publish a new essay!

Newsletter

Do you enjoy reading my articles?
Subscribe to the newsletter if you don't want to miss the new content, business offers, and free training materials.

Bartosz Mikulski

Bartosz Mikulski

  • Data/MLOps engineer by day
  • DevRel/copywriter by night
  • Python and data engineering trainer
  • Conference speaker
  • Contributed a chapter to the book "97 Things Every Data Engineer Should Know"
  • Twitter: @mikulskibartosz
Newsletter

Do you enjoy reading my articles?
Subscribe to the newsletter if you don't want to miss the new content, business offers, and free training materials.