JVM Heap size settings
Copy link to clipboard
Copied
Recently I got a VPS server and I'm running Coldfusion, the website was running fine until it got more and more traffic and I started to encounter 'OutOfMemory' exceptions.
I thought simply to rise the memory of the VPS server, but this didn't help.
After doing some Google searches I found a setting in de CF Admin settings to set the JVM Heap memory. It was on the standard: Max Heap size 512MB and Min Heap size was empty. After playing around a bit I have now set it to Min 50MB and Max 200MB, good things is that I'm not getting the 'OutOfMemory' exceptions anymore. So far so good!
But with about 50 active visitors on the website, the website starts to get slow. The CPU usage is only about 8% (Windows Taskmanager), also the taskmanager show only about 30% of the 3GB RAM in use.
So I'm thinking that my values could be tweaked to use more of the RAM. Honestly I don't understand these JVM Memory heap settings, so I have no clue what is a good setting for me.
I found a CF script that displays the memory usage, the details are:
Heap Memory Usage - Committed 194 MB Heap Memory Usage - Initial 50.0 MBHeap Memory Usage - Max 194 MBHeap Memory Usage - Used 163 MBJVM - Free Memory 31.2 MBJVM - Max Memory 194 MBJVM - Total Memory 194 MBJVM - Used Memory 163 MBMemory Pool - Code Cache - Used 13.0 MBMemory Pool - PS Eden Space - Used 6.75 MBMemory Pool - PS Old Gen - Used 155 MBMemory Pool - PS Perm Gen - Used 64.2 MBMemory Pool - PS Survivor Space - Used 1.07 MBNon-Heap Memory Usage - Committed 77.4 MBNon-Heap Memory Usage - Initial 18.3 MBNon-Heap Memory Usage - Max 240 MBNon-Heap Memory Usage - Used 77.2 MBFree Allocated Memory: 30mbTotal Memory Allocated: 194mbMax Memory Available to JVM: 194mb% of Free Allocated Memory: 16%% of Available Memory Allocated: 100%
My JVM arguments are:
-server -Dsun.io.useCanonCaches=false -XX:MaxPermSize=192m -XX:+UseParallelGC - Dcoldfusion.rootDir={application.home}/../ -Dcoldfusion.libPath={application.home}/../lib
Can I give the JVM more memory? If so, what settings should I use?
Thanks very much!!
Copy link to clipboard
Copied
Yes you can give the JVM more memory if you are only using 1GB out of the 3 GB on your server. I would set the max heap size (in cf administrator) to 1024mb (1gb) instead of 200mb. If you are running 64 bit then you can go above 1gb, but if you are running 32 bit you can't get the max heap. You might consider setting the min heap size equivalent to or just below the max heap size, so you aren't wasting resources shrinking or growing the heap at runtime. It's also worth noting that the slowness you are experiencing under load may not have anything to do with the heap size. The problem could be on the DB side of things, or elsewhere.
--
Pete Freitag
Copy link to clipboard
Copied
Just to add to Pete’s note, I didn’t see anything in s.filipowicz’s note that said he was running 32-bit, so let’s clarify to readers that Pete’s first 2 sentences refer to that specifically. (His third sentence implies it, but I just want to be clear.)
Also, s.filipowicz, you say you got “outofmemory” errors, but you don’t say what kind. There is a big difference between an OOM error that then says it’s related to “heap space”, versus one that says it’s related to “permgen”, or “out of swap space”, or “unable to create new native thread”. The latter three may well mean that you need to lower the heap, believe it or not.
Sometimes, the higher the heap the greater the contention with other things that leads especially to the “out of swap” or “new native thread” error. The “permgen” error generally means you need to increase the maxpermsize, but that’s not always clear—sometimes you need to fix the problem that’s stressing the permgen.
And indeed, you say that lowering the heap max made the errors go away, but performance got bad. One may suspect that you were then having something other than an “OOM heap space” error, and that lowering the heap made that go away. But then it could just be that whatever caused that error then is not happening since you restarted—and it may come back, so you may well still need to increase the heap.
Sadly, this subject is a lot more complex than you will generally find discussed on most blogs and even many Java resources. I started to address it as a blog entry here:
CF911: Lies, damned lies, and when memory problems not be at all what they seem, Part 1
http://www.carehart.org/blog/client/index.cfm/2010/11/3/when_memory_problems_arent_what_they_seem_part_1
While I never have finished the additional parts of a series I had anticipated, the introductory info there (fairly substantial) may still be of value.
Anyway, as a starting point, the key is to note which kind of OOM error you are getting when CF crashes, which as you may have found are discussed in the logs in the \runtime\logs\ dir (or \logs\), not the \logs viewable in the CF admin. Let us know what you find.
/charlie
/Charlie (troubleshooter, carehart. org)
Copy link to clipboard
Copied
From the JVM usage listed Heap maximum is 200Mb with 160Mb used only leaving 30Mb free. It is conceivable that 30Mb can be utilised or committed with objects quite easily.
JVM - Free Memory 31.2 MB
JVM - Max Memory 194 MB
JVM - Total Memory 194 MB
JVM - Used Memory 163 MB
Does not look like PermGen (-XX:MaxPermSize=192m) is being stressed:
PS Perm Gen - Used 64.2 MB
Having said that, setting an initial value to PermGen can benefit JVM performance eg -XX:PermSize=96m (the value could differ give more samples of JVM usage over time)
Ditto to other posters I also expect you can benefit by having a bigger maximum heap defined. While changing heap settings it can be a good idea to set a minimum setting.
CFadmin > Server Settings > Java and JVM
Minimum JVM Heap Size (MB) 512 Maximum JVM Heap Size (MB) 1024
HTH, Carl.
Copy link to clipboard
Copied
I know that this isn't what you originally were asking, but I noticed the following:
Heap Memory Usage - Max 194 MB
JVM - Max Memory 194 MBJVM - Total Memory 194 MB
Non-Heap Memory Usage - Max 240 MB
Does anyone know how the "JVM- Max Memory" is related to "Heap Memory Usage - Max
" and "Non-Heap Memory Usage - Max
"?
Intuitively it seems to me that the Max Memory should equal the Max Heap plus the Max Non-Heap, but the max memory seems always equal to the heap max memory.
Copy link to clipboard
Copied
Hello Bob-
Non Heap memory used would be made up of
Code Cache
Compressed Class Space
Metaspace
Non-Heap Memory Usage is the amount of memory allocated with objects for those above spaces.
JVM - Max Memory and Heap Memory Usage - Max are normally the same value. In CFadmin that is related to Server Settings > Java and JVM > Maximum JVM Heap Size (in MB) tho it can be different by a small amount according to Garbage Collector in use, what value is present for Minimum JVM Heap Size (in MB), how long CF has been up and if any full garbage collections have run.
Non-Heap Memory Usage - Max would be the memory taken for list above but not necessarily occupied with objects, free space ready to accept objects.
Note Metaspace for Java 8, Perm Gen for end of life Java 7.
Hope that helps, Carl.
Copy link to clipboard
Copied
I'm pretty sure that Perm Gen is part of the heap, and I would expect Metaspace to be as well.
Dave Watts, Fig Leaf Software
Copy link to clipboard
Copied
Hi Dave,
In CF Java memory Heap refers to the space allocated for and with objects to regions Old / Tenure plus New which is made up of Eden and Survivor spaces. Non-heap are the other regions like Perm Gen for Java 7 or Metaspace for Java 8 along with Code Cache and Compress classes.
Regards, Carl.
Copy link to clipboard
Copied
Well, that's very interesting! I always assumed that all three generations (young, tenured, and perm) were part of the heap, because of the very nature of how heap and stack space are differentiated. But it turns out that you're right about this as far as I can tell, and I've been working under this misunderstanding for years. So, thanks for pushing on this and getting me to do more research!
Dave Watts, Fig Leaf Software

