Application performance is a key domain that has to be monitored, as it’s always essential to keep one’s application on pace. With things around the globe running faster every day, there is a demand for the improved performance of the developed applications. When an application slows down, questions like ‘why is it slow?’ ‘since when?’ and ‘what is causing it?’ arise, and this is where the profiling techniques come into play. With a perfect diagnosis, troubleshooting, and correction, delay in application performance can be curbed away. Furthermore, analyzing the performance more often can support it well.
Battling Silo Legacy System Integration & Performance Issues: A Case Study
We had developed a custom web and mobile Field Service Application for a Service & Equipment rental company with tight integration to legacy ERP systems. The field service technicians relied on the application in their mobile and computers to view the service tickets, update parts & labor, report van inventory, add a new work order, and more. The application with a rich set of GPS & google map location features, technician tracking, real-time customer & ticket updates was serving as a handy tool for hundreds of field technicians of the company. However, the enterprise ERP was old, and the architecture was not supporting the enhancement of an external web or mobile using APIs, and the APIs from the ERP system needed complex joints and orchestration to get to the correct structure that we needed. Hence, we developed our own Integration Middleware using Java.
The major problems that we had faced in our Field Service Application during the last few months were a connection close out issue and the slowness of performance from our application. The case here is, as and when bulk data is being parsed, the field service application fails, and hence we started to analyze the performance of the current system. Each time when the connection closed out, the server had to be restarted manually, and thus, we began to troubleshoot.
While traditional approaches include telnetting to application ports, server-level metrics (CPU, memory, disk), ping tests, etc, in today’s distributed application environments, these measures are not sufficient to locate the bottlenecks. We should be able to connect to the user journey with the application infrastructure and understand when, where, and why the user experience is affected during application access. Thus we decided to enable routine monitoring and analysis of performance using a profiling tool. As a part of our analysis, we took up Visual VM to monitor, and the following are the very basic details associated with it, which can be imparted for any Java application.
VisualVM: An Overview
VisualVM is a powerful tool that provides a visual interface to view deep and detailed information about local and remote Java applications while they are running on a Java Virtual Machine (JVM). Some of its features are as mentioned below.
- It helps in tracking memory leaks, analyzing the heap data, performing CPU profiling, and monitoring the garbage collector.
- It helps to improve the application performance and ensures that the memory usage is optimized. With features like thread analysis and head dump analysis, it comes handy while solving run-time problems.
Let us quickly run you through the installation process of VisualVM. It is available in the JDK bin directory. It’s available after JDK 1.6 update 7.
- JDK< BIN< jVisualVM.exe
- Click on it and the application starts up.
- Open up the application, on the left pane Local, Remote, and Snapshots are available.
- Local contains two options Local Application and VisualVM
- Remote is used for remote application profiling. Connect to the remote server and add that application.
VisualVM Configuration Details
create setenv.sh in <tomcat setup path>/bin location
Contents of setenv.sh is
Export JAVA_OPTS=”-Dcom.sun.management.jmxremote=true \ -Dcom.sun.management.jmxremote.port=9090 \-Dcom.sun.management.jmxremote.ssl=false \ -Dcom.sun.management.jmxremote.authenticate=false \ -Djava.rmi.server.hostname=<hostname like *****.com>”
VisualVM Configuration Steps
* Open visualvm < Remote< Right click on Remote < Add remote host < Hostname: *****.com
* Right click ******.com< Add JMX Connection< connection name:******.com:9090
* Right click the ******.com:9090 < Thread dump/ Heap dump
Benefits of VisualVM
- It provides a visual interface for local and remote Java applications running on JVM.
- Monitors the application’s memory usage and runtime behavior. It also monitors application threads.
- Analyzes the memory allocations to different applications.
- Thread dumps – very handy in case of deadlocks and race conditions.
- Heap dumps – very handy in analyzing the heap memory allocation.
Basic Working of Visual VM
VisualVM focuses on a tab type arrangement, containing two panes on the left and right with a list of applications. The important tab here is the Monitor tab that gives you a detailed analysis of heap space and utilization, classes, and threads. It can read and interpret binary heap dump files. You can either generate a heap dump, or you can read the one that you have generated outside this application. As a whole, on pointing it to the local servers and triggering each API, it is possible to observe the time taken for execution, the memory used (whether it took more than expected), and so on.
Given below are the screenshots of the different tabs obtained while carrying out the analysis.
Overview: This shows the configuration details like process ID, host, thread/dump details, etc.
Monitor: This tab provides information regarding the CPU, Memory, Classes, and Threads usages. The spikes represent the data usage at a specific instant.
Threads: Provides information regarding the threads in different states used at a particular instance.
Reading a thread dump: A thread dump contains a list of all threads with stack trace and metadata. It generally contains your project’s package name(try to start the analysis from there), and also includes thread number, thread IDs that indicate the cause for the JVM to shut down or not, priorities, identifiers, states such as new, runnable, blocked, etc and its address.
Monitoring Application Performance with VisualVM
The performance of the application can be monitored using a profiling tool such as VisualVM. Following the above procedures and monitoring the same using this profiling tool in our field service application helped us to trigger memory issues, CPU loads as well as the irregularities in the average response time of APIs. Taking this into consideration helped us in implementing several techniques (such as splitting up the API into two), which helped us to improve the performance of our system.
It is safe to say that VisualVM is a valuable tool that can provide in-depth details of application performance in terms of CPU, memory, and threads while providing details on utilizing this information to improve the performance and scalability of their applications. It is also very useful in supporting applications and solving complex run-time problems. With performance improvement and memory utilization steadily gaining importance, these types of profiling tools are in high demand. The other tools available in the market serving the same purpose are Yourkit, Profiler, and JConsole.
Software Engineer, RapidValue