WebSphere Administration: Setting Heap Size

Setting maximum heap size and changing other JVM parameters is a fairly common administration task. JVM configuration might be changing quite often during application development, usually as a result of performance testing.

Typically JVM parameters have to be updated for all application servers in a cell or at least for application servers that belong to a particular cluster.

Conveniently, WebSphere Application Server (WAS) supports updating JVM parameters using its administration APIs, specifically, AdminConfig object. This is illustrated by the script below.


import sys

"""
Change JVM heap size for all application servers in a cell
"""
# New heap size is passed as a parameter to the script
max_heap_size=sys.argv[0]

# Get the string with config ids of all serves
server_confids=AdminConfig.list("Server")
# Iterate over all servers - config ids are separated by \n 
for server_confid in server_confids.split("\n"):
    server_confid=server_confid.strip()
    # obtain the type - types are APPLICATION_SERVER, DEPLOYMENT_MANAGER, NODE_AGENT, WEB_SERVER
    server_type=AdminConfig.showAttribute(server_confid, "serverType")
    # we're changing the heap size for application servers - we want to exclude node agents, etc.
    if server_type == "APPLICATION_SERVER":
        server_name=AdminConfig.showAttribute(server_confid, "name")
        # this is the query to get JavaVirtualMachine configuration object for a particular server
        jvm_path="/Server:%s/JavaProcessDef:/JavaVirtualMachine:/" % server_name
        jvm_confid=AdminConfig.getid(jvm_path)
        # "modify" accepts  a list of lists - each list contains name and value (odd choice I must say, why not use tuples?)
        AdminConfig.modify(jvm_confid, [["maximumHeapSize", max_heap_size]])

# Commit our changes to the repository        
AdminConfig.save()

This post is part of the series on WebSphere Application Server administration. Please subscribe to our blog if you'd like to receive updates.

Note: We offer professional services in the area of WebSphere architecture, implementation and operations. If you're looking for help with any of these tasks, please let us know.

5 Responses to “WebSphere Administration: Setting Heap Size”

#35017 | August 1st, 2009 | Kevin McGrath

There is no question that the code you supply will work. There are, however, much easier ways to change JVM parameters — approaches that require a lot less string manipulation. If you want to change heap size, you could call one of several AdminTask methods.
# Assume n holds the name of a node and s holds the name of a server in that node
# those are names, NOT configuration IDs
# n is not needed if the server name is unique within the cell

AdminTask.setJVMInitialHeapSize( ‘[ -nodeName ‘ + n + ‘ -serverName ‘ + s + ‘ -initialHeapSize ‘ + str( 384 ) + ‘ ]’ )
AdminTask.setJVMMaxHeapSize( ‘[ -nodeName ‘ + n + ‘ -serverName ‘ + s + ‘ -maximumHeapSize ‘ + str( 944 ) + ‘ ]’ )

# or you could set a bunch of JVM properties in one call
AdminTask.setJVMProperties( ‘[ -nodeName ‘ + n + ‘ -serverName ‘ + s + ‘ -initialHeapSize ‘ + str( 384 ) + ‘ -maximumHeapSize ‘ + str( 944 ) + ‘ -verboseModeGarbageCollection true ‘ + ‘ ]’ )

#35022 | August 3rd, 2009 | Alexander Ananiev

Kevin,
Thanks for the tip. Using AdminTask is certainly shorter, but scripting it from scratch gives you more flexibility. Also, I was trying to give a good example of how to use AdminConfig, I think that the WAS documentation is lacking in this area.

#35098 | November 18th, 2009 | Bob Gibson

Alexander:

As you pointed out in your response to Kevin, the documentation for the WebSphere Application Server Scripting objects is a bit lacking. ;-)

Hence the need for a book like this “WebSphere Application Server Administration using Jython” (http://www.ibmpressbooks.com/bookstore/product.asp?isbn=9780137009527).

I was pleased to see that your example specifically verifies the serverType before changing the heapsize. I have seen too many scripts that don’t take that kind of thing into account.

Instead of using split( ‘\n’ ) to separate the lines of text returned by the AdminConfig.list(), I prefer to use splitlines() string method, so my loops tend to look like this:

# Iterate over all servers – config ids (1 per line)
for serverID in AdminConfig.list( ‘Server’ ).splitlines() :

And to answer your question:
# (odd choice I must say, why not use tuples?)

– tuples are a python construct/data structure.
– Remember that the scripting object API must be usable by both Jacl, and Jython…

Bob

#35105 | November 19th, 2009 | Alexander Ananiev

Bob, thanks for all your comments, I will certainly check out the book.
I still think that IBM python APIs are far from perfect to put it mildly. OK, they don’t want to use tuples, but what about dictionaries or keyword arguments? They should provide separate wrapper objects for python and JACL if the languages are so vastly different. Especially since JACL was deprecated.

#35520 | November 16th, 2011 | ugg boots blog

ugg boots blog…

[…]WebSphere Administration: Setting Heap Size[…]…