I have a glassfish v4.0 set up on Ubuntu server running on oracle java virtual machine and jvm process resident memory size (got via "top" command) grows up until jvm doesnt have memory to create new thread.
What I have:
- VPS Server with 1Gb of ram and 1.4GHz processor (1Core)
- Ubuntu Server 12.04
- Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
- Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)
- Glassfish v4.0 running my Java EE webapp
- VM runs with folowwing parameters -XX:MaxPermSize=200m -XX:PermSize=100m -XX:Xmx=512m (I can add all if relevant)
What`s the problem:
Ram usage (res memory) grows all the time, depending on usage 10-100m per hour until jvm cannot allocate native memory.
What have i tried:
- I`ve lowered max heap space which only saves time until jvm crashes anyway
- I`ve attached plumbr (https://portal.plumbr.eu/) which does not detect any memory leak in heap
- I have also set max perm size to lower value.
I would like to have my JVM to be stable, as I measure heap space + perm gen takes only 400-600 mb while "top" command shows java process memory grows until 850mb and then kills itself. I know that JVM need more memory that perm space and heap, but do you think i have still given too much memory to heap space and perm gen? Any help or guide will be highly appreciated.
What else I tried (based on suggestions and my own findings):
- I have reduced and fixed heap space to 256m and then icreased while system is still stable, I noticed that maximum heap I can afford on my system is 512m and 128m perm gen space. (-Xmx512m,-Xms512m ,-XX:PermSize=128m, -XX:MaxPermSize=128m)
- Reduced java thread size -Xss256k, I was unable to reduce it less than 218k (jvm won`t start)
- Added -D64 so that jvm runs in 64 bit mode
- Added -XX:+AggressiveOpts (to enable performance optimization), -XX:+UseCompressedOops (to reduce heap space memory usage), -server flag to launch jvm in server mode
- As i have very limited heap space size I modified NewRatio to have a little bit bigger tenured generation (1/3 of heap space) -XX:NewRatio=3
- Added diagnostic options for GC so that i can inspect OOM errors -XX:+PrintTenuringDistribution -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+HeapDumpOnOutOfMemoryError -Xloggc:/home/myuser/garbage.log
Current status With these changes I have finally limited resident memory (RAM usage) for java process which was my target. In my case 512m heap space + 128m perm gen space results in around 750m of resident memory of java process which is stable. Even though I still have memory problems - heap memory gets full from time to time and causes web app to freeze due to continued garbage collection, but OS does not kill the process. So i need now either increase available memory (RAM) for the system or inspect heap usage and lower my application`s footprint. As my webapp is Java EE based (with EJB) i might not be able to reduce it significantly. Anyway thanks for suggestions and feel free to share any other suggestions if any.