One of the most important testing in software field is Load Testing, everyone wants to know how much his application can scale, what's the breaking point, is there any memory leak any deadlock happening,
how much cpu is being utilized?? There are lots of ways to generate load and test, but we are not talking about any testing methodologies or any testing tool here, rather we will talk about monitoring. How to monitor a running java application to determine its performance??
One very nice monitoring tool provided by JDK is JConsole. Its a GUI tool which monitors a JVM, all you need is to start your application with jmx management agent and connect jconsole to it. Lets have a look.
How to start JMX Management Agent on an Application
To start JMX agent you need to set following java options before starting application.
-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=<some port> -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false
if you want authentication and ssl you need to set following options
-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=<some port> -Dcom.sun.management.jmxremote.authenticate=true -Dcom.sun.management.jmxremote.ssl=true -Dcom.sun.management.jmxremote.access.file=<path to access file>
-Dcom.sun.management.jmxremote.password.file=<path to password>
To start jconsole type jconsole on cmd, make sure JAVA_HOME is set on your machine. You will see something like this on your monitor.
If you have any JVM running local you can see it under local process tab, you can connect directly double clicking the process.
You can even connect to some remote JVM using host:port combination or using following complete URL service:jmx:rmi:///jndi/rmi://hostName:portNum/jmxrmi
Once you are connected to a JVM you will see four blank graphs, you are done, Now sit back and relax and let your application run(Make some dummy requests, calls to your app). After some time you will see graphs getting generated.
At the top you can find tabs (overview, memory,threads classes, vm summary, Mbeans). These are basically different resources you can monitor.
Memory tab shows you the heap utilization, you can even select type of memory you want to monitor ie eden space, survivor space, permanent space. If after a long time any memory graph's base line is going up it means your application has a memory leak and it will crash after some time. Usually a memory graph is an up and down graph about a flat baseline. See the graph below
Same you can monitor Threads, CPU utilization, VM summary etc.
Jconsole is not about only monitoring you can even manage your VM. You can even pause your service, perform GC, kill threads. For all the information I suggest play with it. You will enjoy.
When You are done playing with jconsole try to play with yourkit.