Interactively Update the JVM Maximum Heap Size

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").
split("\r\n")[0]

(use .split(“\n”)[0] 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:

print jvm

You should see something like this:

(cells/YOURCELLNAME/nodes/YOURNODENAME/servers/
YOURSERVERNAME|server.xml#
JavaVirtualMachine_1160406483174)

Next, type:

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:

AdminConfig.save()

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.

Advertisements

9 Responses to Interactively Update the JVM Maximum Heap Size

  1. mark says:

    splendid example, thanks!

  2. Valli says:

    Wonderful-A proper self explanatory example.thanks

  3. JP says:

    This is a great tip that I have used many times. What I am looking for is to now ‘list’ all the HEAP for all the JVM’s in my cluster. I would really like to be able to list what is actually being used. Is that possible?

  4. JP, if you mean how much of the heap is being used, I’m not sure that will be possible through wsadmin – that’s typically for modifying the configuration only, not giving real-time JVM info. You might find this does the job, I haven’t used it: http://www.alphaworks.ibm.com/tech/gcdiag?open&S_TACT=105AGX59&S_CMP=GR&ca=dgr-jw26awgcdiag.

  5. JP says:

    Is it possible to pass the list of servers through grep? I have a very large topology using XD. One Dynamic Cluster and one standard cluster. I would like to change the MaxHeap for ‘all’ JVM’s in the standard cluster.

    For instance the dynamic cluster members are named something like: XXX-A01-SIS-xxxx and the standard cluster is XXX-A01-XES-xxxxx. Is there a way for instance to use grep w/ the python script?

    Is this possible? Also where I can find a list of I can list w/ AdminConfig.list like in your example where you used JavaVirtualMachine?

  6. @JP, I suspect you could do what you want with Python regexs:

    http://www.amk.ca/python/howto/regex/

    Remember that jython is a fully-fledged programming language, so you should be able to cover most eventualities:

    http://www.jython.org/

    Try AdminConfig.help for interactive help on commands available.

  7. Deepika says:

    Very well explained! Hey…I was also trying the ‘minimumHeapSize’ attribute to change the minimumHeapSize as well, but did not work..any corrections, pls suggest? Thanks

  8. @Deepika, there is no such thing – only an initial heap size. The default for this is normally adequate and you shouldn’t need to change it.

    This page explains this a bit more: http://www.informix-zone.com/node/46

  9. JK says:

    Wow – this is simply a superb article. I was really messed up JVM heap size using the IBM WebSphere console and did not know how to set the correct value. This article helped me a lot.

    Thanks so much, JK

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: