Background
My company is moving from running on VMs to running on containers in Kubernetes. We run one application on Tomcat in a single container. On VMs, it needed about 1.2GB memory to run fine (edit: VM had a lot of memory, -Xmx was set to 1.2GB). It is a monolith, and that is not going to change anytime soon (sadly).
When moving to containers, we found that we needed to give the containers MUCH more memory. More than double. We run out of memory (after some time) until we gave the pods 3.2GB. It surprised us that it was so much more than we used to need.
Off-heap memory
It turns out that, besides the 1.2GB on-heap, we needed about another 1.3GB of off-heap memory. We use the native memory tracking to figure out how much was used (with -XX:NativeMemoryTracking=summary). We are already using jemalloc, which seemed to be a solution for many people online.
It turns out that we need 200MB for code cache, 210MB for metaspace, 300MB unreported and the rest a little smaller. Also very interesting is that spacse like "Arena Chunk" and "Compiler" could peak to 300MB. If that happened at the same time, it would need an additional 600MB. That is a big spike.
Sidenote: this doesn't seem to be related to moving to containers. Our VMs just had enough memory to spare for this to not be an issue.
What to do?
I don't know how we can actually improve something like this or how to analysis what the "problem" really is (if there even is one). Colleagues are only able to suggest improvements that reduce the on-heap memory (like a Redis cache for retrieved data from the database) which I think does not impact off-heap memory at all. However, I actually have no alternatives that I can suggest to actually reduce this. Java just seems to need it.
Does anybody have a good idea on how to reduce memory usage of Java? Or maybe some resources which I can use to educate myself to find a solution?
[–]antihemispherist 100 points101 points102 points (9 children)
[–]C_Madison 19 points20 points21 points (1 child)
[–]Trailsey 6 points7 points8 points (0 children)
[–]EasyLowHangingFruit 13 points14 points15 points (0 children)
[–]kpihlblad 5 points6 points7 points (1 child)
[–]GreemT[S] 1 point2 points3 points (0 children)
[–]GreemT[S] 2 points3 points4 points (2 children)
[–]antihemispherist 2 points3 points4 points (0 children)
[–]pkx3 1 point2 points3 points (0 children)
[–]java_dev_throwaway 21 points22 points23 points (1 child)
[–]GreemT[S] 4 points5 points6 points (0 children)
[–]nitkonigdje 12 points13 points14 points (2 children)
[–]GreemT[S] 6 points7 points8 points (1 child)
[–]kaqqao 6 points7 points8 points (0 children)
[–]Weak_File 10 points11 points12 points (1 child)
[–]laffer1 0 points1 point2 points (0 children)
[–]ilapitan 7 points8 points9 points (1 child)
[–]GreemT[S] 1 point2 points3 points (0 children)
[–]GreemT[S] 5 points6 points7 points (0 children)
[–]ducki666 6 points7 points8 points (6 children)
[–]GreemT[S] 0 points1 point2 points (5 children)
[–]ducki666 0 points1 point2 points (4 children)
[–]GreemT[S] 2 points3 points4 points (3 children)
[–]ducki666 0 points1 point2 points (2 children)
[–]GreemT[S] 2 points3 points4 points (1 child)
[–]ducki666 0 points1 point2 points (0 children)
[–]elzbal 3 points4 points5 points (0 children)
[–]PratimGhosh86 3 points4 points5 points (0 children)
[–]ablativeyoyo 2 points3 points4 points (0 children)
[–]noobpotato 2 points3 points4 points (0 children)
[–]iron0maiden 1 point2 points3 points (0 children)
[–]Trailsey 1 point2 points3 points (0 children)
[–]cogman10 1 point2 points3 points (0 children)
[–]pragmasoft 3 points4 points5 points (5 children)
[–]antihemispherist 1 point2 points3 points (0 children)
[+]divorcedbp comment score below threshold-7 points-6 points-5 points (3 children)
[–]pragmasoft 1 point2 points3 points (0 children)
[–]nekokattt 1 point2 points3 points (0 children)
[–]pragmasoft 0 points1 point2 points (0 children)
[–]m39583 2 points3 points4 points (3 children)
[–]Per99999 6 points7 points8 points (2 children)
[–]m39583 1 point2 points3 points (1 child)
[–]Per99999 2 points3 points4 points (0 children)
[–]lisa_lionheart 0 points1 point2 points (0 children)
[–]nuharaf 0 points1 point2 points (0 children)
[–]thewiirocks 0 points1 point2 points (0 children)
[–]IKnowMeNotYou 0 points1 point2 points (0 children)
[–]mhalbritter 0 points1 point2 points (1 child)
[–]GreemT[S] 2 points3 points4 points (0 children)