Monitoring
About
Monitoring Java performance involves observing and examining how Java applications run in real-time to find and fix performance bottlenecks. This practice assists developers in guaranteeing that Java applications operate seamlessly, effectively meeting performance expectations. Important components of Java performance monitoring encompass metrics, profiling, heap dump analysis, garbage collection analysis, thread analysis, and continuous real-time monitoring. Without proper tools, identifying and resolving the root causes becomes challenging, leading to recurring problems in your application.
In this guide, we'll explore the utilization of VisualVM as the selected tool for monitoring.
VisualVM as IntelliJ plugin
In Leapwise, backend developers are using IntelliJ as IDE - this is important because it is easy to add the profiling plugin - VisualVM (note: VisualVM is part of JDK8. Starting from JDK9, it needs to be installed as a standalone application). Image 1. shows the options (marked red) that will be available in the IntelliJ Toolbar after the plugin is installed - from left to right options are Run application with VisualVM, Debug application with VisualVM, and Start VisualVM. Run and Debug options VisualVM variations of classic Run/Debug application options.
The third option opens the GUI in which we can use several useful features on both local and remote running applications.
VisualVM features
The most useful VisualVM features include:
Monitoring and Profiling: allows monitoring of various aspects of a Java application, such as memory usage, CPU usage, thread activity, and garbage collection. It also provides profiling capabilities, enabling developers to analyze the performance of their code and identify bottlenecks.
Visual Representation: The tool presents data in a visually intuitive way, using charts, graphs, and tables to help developers quickly grasp the performance characteristics of their applications. This visual representation is particularly useful for identifying patterns and trends over time.
Thread and Heap Dump Analysis: VisualVM supports the generation and analysis of thread and heap dumps. Thread dumps help developers understand the state of threads in the application, while heap dumps provide insights into memory usage, allowing for efficient memory management.
Remote Monitoring: VisualVM supports remote monitoring, allowing developers to connect to and monitor Java applications running on remote machines. This is particularly beneficial for analyzing and optimizing applications in production environments.
VisualVM Dashboards
Monitor
Image 2. shows the main dashboard of VisualVM that provides a graphical representation of key metrics split into different sections:
CPU Section:
The CPU section displays information about the application's CPU usage, both in terms of total usage and usage by individual threads.
This data can be used to identify CPU-intensive methods and optimize code for better performance.
Heap Section:
This section provides detailed information about the Java heap, including heap usage, garbage collection activity, and heap dump options.
Developers can analyze the composition of the heap, identify memory leaks, and take heap dumps for further inspection.
Classes Section:
This section provides details about loaded classes, unloaded classes, and class loading activity. It helps developers understand the class lifecycle and identify any issues related to class loading.
Threads Section:
The Threads section offers insights into thread activity within the application. It displays information about the number of active threads, their states, and any thread dumps that have been generated.
This information can be used to identify thread contention, deadlocks, or inefficient thread usage.
Threads
Image 3. shows the VisualVM Threads dashboard. The main section of the Threads tab displays a list of all threads currently running in the Java Virtual Machine (JVM). Each thread is represented by a row with information such as thread name, ID, state, and priority. Visual representation of thread states through color-coded icons makes it easy to identify threads that are actively executing, waiting, blocked, or sleeping.
VisualVM allows users to capture thread dumps, which provide a snapshot of the current state of all threads in the JVM. Thread dumps are crucial for diagnosing thread-related issues such as deadlocks or thread contention.
Last updated