Hi Everyone,
Today we will talk about how to collect Garbage Collection (GC) forcefully with WLST.
At the time of month end, my server utilization was too high, and we all know that many times JVM misbehaves, and we may have to do force GC too freed up unused memory. So i tried from console, it works for me. But after goggling and talking to all my seniors, I have got an idea about WLST scripting.
The Script:
Step 1. Open a text editor and Copy – paste the text given below into the editor.
# WLST script which calls GC.
from java.util import *
from javax.management import *
import javax.management.Attribute
print 'starting the script .... '
#Script by Ajinkya
# please replace userid and password with your AdminServer userid and password
# plz change the IP adresss and port number accordingly
connect('userid','password',url='t3://localhost:7001')
state('AdminServer')
# For Force GC ....
domainRuntime()
cd('/ServerRuntimes/AdminServer/JVMRuntime/AdminServer')
print ' Performing Force GC...'
cmo.runGC()
disconnect()
print 'End of script ...'
exit()
Step 2. Save the file as ‘RunForceGC.py’
Step 3. Open a new command window à Run ‘setDomainEnv.cmd/.sh’ localted in the ‘domain\bin’ directory
Step 4. Run the python script using WLST.
java weblogic.WLST RunForceGC.py
Following result will display after running above script :
G:\Oracle\Middleware\user_projects\domains>java weblogic.WLST RunForceGC.py.txt
Initializing WebLogic Scripting Tool (WLST) ...
Welcome to WebLogic Server Administration Scripting Shell
Type help() for help on available commands
starting the script ....
Connecting to t3://localhost:7001 with userid weblogic ...
Successfully connected to Admin Server 'AdminServer' that belongs to domain 'bas
e_domain'.
Warning: An insecure protocol was used to connect to the
server. To ensure on-the-wire security, the SSL port or
Admin port should be used instead.
Current state of 'AdminServer' : RUNNING
Location changed to domainRuntime tree. This is a read-only tree with DomainMBea
n as the root.
For more help, use help(domainRuntime)
Performing Force GC...
Disconnected from weblogic server: AdminServer
End of script ...
Exiting WebLogic Scripting Tool.
G:\Oracle\Middleware\user_projects\domains>
Step 5. This should have freed up some memory on your server.
Step 6. The above script runs ‘GC’ on ‘AdminServer’ to run the script of managed server replace the ‘AdminServer’ from the script with the name of the ‘Managed Server’.
Hope this helps :)
And Enjoy Working With Middleware.
Regards,
Ajinkya Vichare
http://ajinkya-vichare.blogspot.com
your script giving me error, here i am attaching the error will you please let me know where i making mistake , as i am new to python scripting.
ReplyDeleteyour script giving me error, here i am attaching the error will you please let me know where i making mistake , as i am new to python scripting
ReplyDeleteInitializing WebLogic Scripting Tool (WLST) ...
Welcome to WebLogic Server Administration Scripting Shell
Type help() for help on available commands
starting the script ....
Connecting to t3://90.168.24.175:9001 with userid graniteadmin ...
Successfully connected to Admin Server 'granite' that belongs to domain 'granitedomain'.
Warning: An insecure protocol was used to connect to the
server. To ensure on-the-wire security, the SSL port or
Admin port should be used instead.
Current state of 'granite' : RUNNING
Location changed to domainRuntime tree. This is a read-only tree with DomainMBean as the root.
For more help, use help(domainRuntime)
Performing Force GC...
Problem invoking WLST - Traceback (innermost last):
File "/opt/app/bea/wls103_64/user_projects/domains/granitedomain/bin/GC_SCRIPT.py", line 13, in ?
AttributeError: runGc
Hi..,
DeletePlease provide me ur script and whole log for the same.
Also make sure before running .py script, run setDomainEnv.sh.
Regards,
Ajinkya
hi aju..
ReplyDeleteI am new in osb I want in-depth material.
bye...
Please use runGC() it will not give error. I hope you have tried with runGc()
ReplyDeletewant to run Garbage collection only if percentage of heap memory usage is greater than 80%.Can we have a script for this.
ReplyDelete