4 Replies Latest reply on Apr 16, 2018 2:25 PM by bobaafettt.40673866

    JVM Heap size settings

    s.filipowicz Level 1

      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 MB
      Heap Memory Usage - Max  194 MB
      Heap Memory Usage - Used     163 MB
      - Free Memory    31.2 MB
      - Max Memory     194 MB
      - Total Memory   194 MB
      - Used Memory    163 MB
      Memory Pool - Code Cache - Used  13.0 MB
      Memory Pool - PS Eden Space - Used   6.75 MB
      Memory Pool - PS Old Gen - Used  155 MB
      Memory Pool - PS Perm Gen - Used     64.2 MB
      Memory Pool - PS Survivor Space - Used   1.07 MB
      Non-Heap Memory Usage - Committed    77.4 MB
      Non-Heap Memory Usage - Initial  18.3 MB
      Non-Heap Memory Usage - Max  240 MB
      Non-Heap Memory Usage - Used     77.2 MB
      Free Allocated Memory: 30mb
      Total Memory Allocated: 194mb
      Max 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!!

        • 1. Re: JVM Heap size settings
          pete_freitag Adobe Community Professional

          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

          Foundeo Inc. | HackMyCF.com

          • 2. Re: JVM Heap size settings
            charlie@carehart.org Adobe Community Professional & MVP

            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_th ey_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.





            • 3. Re: JVM Heap size settings
              carl type3 Level 4

              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. 

              • 4. Re: JVM Heap size settings
                bobaafettt.40673866 Level 1

                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 MB
                - 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.