How to reduce STOP-THE-WORLD time in Java GC
We know that in Java a full GC can hang the JVM, which can also be called STOP-THE-WORLD. In many applications, the JVM hangs for too long, which will cause a lot of problems. I want to know how to reduce the STOP-THE-WORLD time in GC? What are the potential disadvantages caused by reduced STOP-THE-WORLD times? (excluding JVM without stop-world behavior)
source to share
There are many approaches
- Create less trash. A memory profiler will help.
- Use a smaller heap. A profiler can help reduce memory usage.
- Use heap memory instead. There are many libraries for storing data from the heap. for example the Chronicle.
- Use more memory and GCs will happen less often, possibly less severe, when they do. If you are using less than 32GB of heap this can be a quick win.
- Use a fully parallel collector like Azul Zing. It has no STW collector.
I would start with a memory profiler to reduce garbage and heap usage and tune the GC.
source to share
If your objects live for a long time, you can try using DirectBuffers from the new I / O package. Creating and reclaiming them is more expensive than creating and reclaiming heap-based indirect buffers because the direct buffers are managed using native OS-specific code. This added management cost makes direct buffers a poor choice for one-off or infrequently used cases.
Direct buffers are also outside the scope of the Javas garbage collector.
source to share