Remote Java Profiling using YourKit

This wiki gives insights into a java profiling tool called YourKit, how it works, how it helps in profiling JVM applications and how a user can connect YourKit profiler UI with the profiler agent in performance environment (remote application).

Note: YourKit is not free/opensource software - and requires a license to use. YourKit has been helpful to provide free licenses for Bahmni team to perform performance profiling. If you are interested in trying out YourKit, please reach out to them, so they can provide you with appropriate licenses for opensource projects. Read more here: https://www.yourkit.com/java/profiler/purchase/#os_license

What is YourKit?

YourKit is a JVM profiler that helps in monitoring and debugging performance issues in development and production environments. The tool can be of great help in debugging as well as in finding memory leaks in the application. Features such as CPU and memory profiling, deadlock detection, threads executed are provided by this tool which will be discussed in upcoming sections.

How does YourKit work?

YourKit Java Profiler consists of two parts interacting via the network: profiler agent and profiler UI.

Profiler agent (or simply agent) is a plugin for Java Virtual Machine and Profiler UI (or simply UI) is a desktop application that connects to the profiler agent to change profiling modes and obtain live performance data. The profiler UI has the ability to save performance data as snapshots for further offline analysis as well.

How does YourKit Java profiler help?

CPU and Memory profiling

The YourKit profiler allows users to profile CPU and Memory to understand the methods being invoked and the sequence of invocation in the form of call trees, the objects being allocated in the memory, insights into heap and non-heap memory, Garbage Collection and so on.

To get detailed information on the method calls and the call structure and memory usage with responsible classes/objects, profiling has to enabled from the toolbar and can be saved as snapshots for future references.

The following documentation gives insight into how to perform CPU profiling, different types of profiling that YourKit provides and how to take snapshots.

And to know more about how to perform memory profiling, different types of memory allocation recording and take snapshots, refer this documentation.

Visualisation of CPU usage and Threads used in the application

Deadlock Detection

This profiler tool shows all java-level deadlocks in the Deadlocks tab related to the application being profiled. Know more about deadlock detection here.

Performance Charts

With the help of this window, the users can compare multiple telemetries, which can be chosen from the window on the left, in a single window with time axis synchronised. The comparison can be made easily without having to switch between multiple windows such as CPU, memory etc. Know more about performance charts here.

Exception profiling

the Exceptions tab in the dashboard gives the list of exceptions being thrown by the application. The profiler gives info of the exception grouped by class or by thread in the upper window and gives exception stack traces in the window below the same.

In the next section, we will look into how we could connect the profiler UI to the profiler agent in Bahmni OpenMRS pod running in the performance environment.

Connecting YourKit profiler UI to agent in Performance environment

In order to make a connection with YourKit profiler agent in OpenMRS pod under performance namespace using the profiler UI, follow these steps:-

  1. In the YourKit profiler UI, select the option Profile remote Java server or application.

  2. Select Direct connect option and proceed to next step.

  3. In this window,

    1. Provide an appropriate Connection name to uniquely identify this connection that will be shown in Monitor applications section after successful connection.

    2. Under the Host column, provide profiling.lite.mybahmni.in as this is the route through which profiler UI can make connection with the agent.

    3. Set the Port as 443 and proceed to Next step.

  4. Hit Next, since there is no need of SSH tunnel for making this connection.

  5. Test the connection to see if the connection is fine and hit Finish to complete the process.

  6. Under Monitor applications section, a new entry with the Connection name set in step 3a will be show and Tomcat server will be shown under that connection name.

  7. On selecting the Tomcat server, a connection to the remote application is made and a new window pops up showing telemetries related to CPU and memory of the JVM, possible deadlocks in the application, insights into the threads being executed, options to monitor executions and take snapshots of CPU and resource allocation for further analysis in the future.

To profile Bahmni OpenMRS running on the machine using Docker using YourKit, please refer here

The performance environment is using profiling tagged Openmrs images which are created using the following Dockerfile. This Dockerfile uses bahminindiadistro/openmrs:latest image and adds YourKit agent, which helps YourKit UI to make the connection mentioned in Step 3b.

References

  1. YourKit Documentation

  2. YourKit Profiler architecture

  3. Download YourKit Profiler UI

 

The Bahmni documentation is licensed under Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)