Increasing the JVM Heap Size
The Java Virtual Machine (JVM) heap size is one of those things I've read about but never thought I'd need to mess with. My dilettante Java programs have always run just fine with the defaults... until that is I tried sending 160,000 data points to a JFreeChart scatter graph running in ZK on Tomcat.
A Java Virtual Machine on 32-bit operating systems typically has a maximum heap size of 64Mb. The JVM heap space is where all Java objects are stored, as well as memory used by the garbage collector. Sun recommends increasing this value for server applications, see Tuning Garbage Collection with the 5.0 Java[tm] Virtual Machine:
Large server applications often experience two problems with these defaults. One is slow startup, because the initial heap is small and must be resized over many major collections. A more pressing problem is that the default maximum heap size is unreasonably small for most server applications.
While watching my graph fail with a heap error and wondering what to do it seemed a review of how to set the JVM heap size might be in order. Here's how to set the heap size for standalone JDBC programs, Tomcat applications and Informix Java UDRs.
Standalone Java Applications
The Java Virtual Machine takes two command line arguments which set the initial and maximum heap sizes:
-Xms and -Xmx. For example if you want to give your Java program needs a 64Mb initial and 256Mb maximum heap size you could launch it as follows:
java -Xms64m -Xmx256m jdbc_prog
Setting the heap size for Tomcat and Java UDRs are variations on the theme and involve figuring out where to pass these arguments to the JVM.
To increase minimum and maximum heap size for Tomcat applications set the CATALINA_OPTS environment variable before starting Tomcat. To set the same heap sizes, on UNIX edit the Tomcat startup.sh script and add a line:
export CATALINA_OPTS=-Xms16m -Xmx256m;
Tomcat 5.5 on Windows has a GUI Configure Tomcat program with a section for the Java heap configuration. Initial and maximum heap size can be set by selecting the Java tab and setting Initial memory pool and Maximum memory pool.
Annoyingly the Tomcat monitor program needs to be closed before the Configure Tomcat program can be run.
Informix Java UDRs
You can set any Java command line arguments for Java UDRs running in Krakatoa (aka J/Foundation) using the JVPARGS Onconfig parameter. For heap size Informix Dynamic Server has two dedicated Onconfig parameters:
JVM_MAX_HEAP_SIZE and the undocumented JVM_MIN_HEAP_SIZE which specify the maximum and initial heap sizes in Mb.
Increasing the maximum JVM heap size settings to 256Mb in Tomcat worked for my scatter graph which duly coughed
up the pretty pattern after thinking about it for a while.
Mental note: next time I need to graph 160K data points, create and stream an image using the points as pixels.