Running JVM in minimal memory footprint


Performance and scalability: Running JVM in minimal memory footprint

  1. Running JVM in minimal memory footprint (1 messages)

    For years - I've been using JVM's with webservers where we just increased the amount of memory so as to improve performance, and included the JVM startup parameters
    export JAVA_OPTS='-server -Xms512m -Xmx512m' - and kept adding more memory to the webservers, as it was cheap and easy to do.

    However, we have recently started using java web applications in systems with limited memory (such as Linux running UML, where an entire server, holding 2Gb of RAM, is subdivided into a dozen or more 'virtual linux machines' each having a slice of the total memory available. Often, this yields 'linux virtual servers' with memory restriced to 96M or even only 128M of available memory max).

    This isn't too bad, and we have modified how we start our JVM's with the following, to restrict memory usage to 32M of memory.
       export JAVA_OPTS='-server -Xmx32m'

    Which actually works quite well for applications using struts / hibernate.

    However, we are noticing that the RSS (resident set size), measured using either 'top' or 'ps aux' within linux, keeps growing, settling up to (or beyond in some cases) 64Mb of memory, and the virtual memory size VMS to above 200Mb of memory.

    Example using 'top auwwxx'
    root 1155 0.0 50.8 204680 63012 ? S Jun27 0:00 /usr/local/java/bin/java -Xmx32m -Dserver.hostname=tibor2 -Djava.endorsed.dirs=/usr/local/tomcat/ ....
    (Note here, we have removed the '-server' option to see if the hotspot compiler was contributing to the memory usage)

    (Version of JVM being used is SUN (build 1.4.2_03-b02)

    Although it would appear that most of this would be swapped out - is there a better way to restrict JVM's for running in memory-starved environments?

    Can anyone recommend ideal settings / configurations / advice for running JVM's in minimal memory configurations?

    Thanks in advance for any advice / suggestions,

    Andrew McGhee
  2. 1-
    I heard bad tings about top on some linux gentoo: invalid VIRT values, as well as swap space usage. VIRT values were always equal to RSS. It was a broken /proc/statm problem.

    "ps" can reports threads, I guess you saw it, all of them have the same mem sizes but they shouldn't be added. Just thought I should remind it to you. I use "ps -e v f" or "ps -e j f" for the most complete while intuitive results.

    For all I have read, and I read a lot, the -server MAY mostly only changes some core routines about threads and memory management. But in terms of memory usage, you may want to disable JIT, because the JIT code, for all I know, will not be allocated on the heap.

    FYI: -server uses -XX:CompileThreshold=10000 while -client uses -XX:CompileThreshold=1500 (the number of invocations before jit compiling).
    You may raise that bar high enought to so not too many method are compiled. It depends on the life duration these jvm. If they die before hitting your threshold, you can save some jit code space without disabling jit entirely.

    you should profile your app to eliminate abuses in data structures.
    That's always a good thing.

    Good luck.