Interactively Update the JVM Maximum Heap Size
November 14, 2006 9 Comments
If you’re using a product based on WebSphere Application Server, such as WebSphere Enterprise Service Bus or WebSphere Process Server, you might sometimes find that you run into problems relating to ‘OutOfMemoryErrors’ – these might appear in your SystemErr.log, or perhaps as an FFDC. They are likely to be caused by the Java Virtual Machine (JVM) heap running out of memory, and are more likely to happen if you have a lot of applications installed or you are stressing the server in some other way.
There are two values used by the JVM that runs your Application Server to control its heap size – the initial size and the maximum size. Most likely, you want to increase the maximum size. You’ll probably find that the default is 256MB, but to be sure, run:
startServer.bat server1 -script C:\temp\heapSize.bat
Replace server1 with the name of your server, and c:\temp with the name of any scratch directory. If you’re using a UNIX-based platform, replace .bat with .sh as appropriate. Now look at the generated batch file and search for -Xmx. It might look like -Xmx256m. This indicates your current maximum heap size is 256MB.
To increase this, let’s work with wsadmin interactively.
Run wsadmin.bat or wsadmin.sh:
wsadmin.bat -lang jython
-lang jython means that we want to use jython as the scripting language, rather than the default of JACL. jython is based on Python, which is simpler to learn and use than JACL. If your server is stopped, you should add -conntype none to ensure wsadmin can reach it. You’ll see a bunch of startup messages, then the wsadmin> prompt. Type the following command all on one line:
jvm = AdminConfig.list("JavaVirtualMachine").
(use .split(“\n”) on Linux/UNIX)
AdminConfig.list(“JavaVirtualMachine”) returns a list of JVMs, separated by newlines. If you’re using a standalone server, there probably will be only one, so you can omit the rest of the command. However, I’m using a clustered configuration, so I wanted to alter the heap size of only the first JVM in the list, which was a cluster member (I actually carried out these steps for each member of the cluster). Thus, I added the split method and the array subscript, which got me just the first JVM in the list. You can verify the JVM you’re using by typing:
You should see something like this:
AdminConfig.modify(jvm, '[[maximumHeapSize 1024]]')
This will set the maximum heap size to 1024MB. Obviously, you can use a different value. As always, you must save your changes to the AdminConfig object:
You can now exit wsadmin by typing exit. Restart your server and you’re done. This entire procedure could be scripted instead (you can use the -f parameter to wsadmin to pass in a script), and that’s worth doing if you have to apply this change to a lot of servers.