Customizing Heap Size in a Weblogic domain

We often come across cases where we require to modify the heap size according to our applications’s needs eg java.lang.OutOfMemoryError
Whenever we want to change the Heap size in WebLogic server (AdminServer or managed servers), we can customize setDomainEnv.sh in $DOMAIN_HOME/bin with required memory arguments.
Below are the two scenarios:

Scenario 1:
We need to change the memory arguments to a value same for all servers in a Domain. Suppose we want to keep Xmx 1024 M and Xms 1024 M for all server in an Domain (Admin and all managed servers).
We will edit setDomainEnv.sh in $DOMAIN_HOME/bin with our required values of Xmx and Xms.
Search for line “# IF USER_MEM_ARGS the environment variable” in setDomainEnv.sh
We will add line
USER_MEM_ARGS=”-Xms1024m -Xmx1024m”
export USER_MEM_ARGS
below line “ # IF USER_MEM_ARGS the environment variable is set, use it to override ALL MEM_ARGS values”
and above line “ if [ “${USER_MEM_ARGS}” != “” ] ; then”
Example :
# IF USER_MEM_ARGS the environment variable is set, use it to override ALL MEM_ARGS values
USER_MEM_ARGS=”-Xms1024m -Xmx1024m”
export USER_MEM_ARGS
if [ “${USER_MEM_ARGS}” != “” ] ; then
MEM_ARGS=”${USER_MEM_ARGS}”
export MEM_ARGS
fi

Scenario 2:
We need to change the memory arguments to values different for all servers in a Domain. Suppose we want to keep Xmx 512 M and Xms 512 M for Admin server and Xmx 1g and Xms 1g for ebsag_server and oam_server1 managed servers in a Domain
We will edit setDomainEnv.sh in $DOMAIN_HOME/bin with our required values of Xmx and Xms.
Search for line “# IF USER_MEM_ARGS the environment variable” in setDomainEnv.sh
We will add lines
case “${SERVER_NAME}” in
“AdminServer”) USER_MEM_ARGS=”-Xms512m -Xmx512m” ;;
“oam_server1″) USER_MEM_ARGS=”-Xms1g -Xmx1g” ;;
“ebsag_server”) USER_MEM_ARGS=”-Xms1g -Xmx1g” ;; *)
echo “Unknown Server Detected!!. Memory set as Xms1g Xmx2g.”;
USER_MEM_ARGS=”-Xms1g -Xmx2g” ;;
esac
USER_MEM_ARGS=”${USER_MEM_ARGS} -d64 -XX:PermSize=256m -XX:MaxPermSize=512m -Djava.awtheadless=true -Djbo.ampool.maxpoolsize=600000″
Below line “ # IF USER_MEM_ARGS the environment variable is set, use it to override ALL MEM_ARGS values” and above line “ if [ “${USER_MEM_ARGS}” != “” ] ; then”

Note that we are using Switch case programming concept in defining different memory arguments for different servers in this domain. We can edit this switch case as per our requirements.
Example :
# IF USER_MEM_ARGS the environment variable is set, use it to override ALL MEM_ARGS values

case “${SERVER_NAME}” in
“AdminServer”) USER_MEM_ARGS=”-Xms512m -Xmx512m” ;;
“oam_server1″) USER_MEM_ARGS=”-Xms1g -Xmx1g” ;;
“ebsag_server”) USER_MEM_ARGS=”-Xms1g -Xmx1g” ;; *)
echo “Unknown Server Detected!!. Memory set as Xms1g Xmx2g.”;
USER_MEM_ARGS=”-Xms1g -Xmx2g” ;;
esac
USER_MEM_ARGS=”${USER_MEM_ARGS} -d64 -XX:PermSize=256m -XX:MaxPermSize=512m -Djava.awtheadless=true -Djbo.ampool.maxpoolsize=600000″

if [ “${USER_MEM_ARGS}” != “” ] ; then
MEM_ARGS=”${USER_MEM_ARGS}”
export MEM_ARGS
fi

This change will be reflected when the Servers are bounced . The new heap size change can be confirmed from the Admin console of the domain (Click on servers -> server_name -> monitoring -> performance) or from server_name.log or server_name.out in $DOMAIN_HOME/servers/Server_Name/logs.

About the Author Masroof Ahmad

Leave a Comment: