DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Java Virtual Threads and Scaling
  • Java’s Next Act: Native Speed for a Cloud-Native World
  • The Energy Efficiency of JVMs and the Role of GraalVM
  • Understanding Root Causes of Out of Memory (OOM) Issues in Java Containers

Trending

  • How to Format Articles for DZone
  • Using Python Libraries in Java
  • Caching 101: Theory, Algorithms, Tools, and Best Practices
  • Designing Fault-Tolerant Messaging Workflows Using State Machine Architecture
  1. DZone
  2. Coding
  3. Java
  4. Diving Into JVM Metrics

Diving Into JVM Metrics

Familiarize yourself with important components of the JVM, including garbage collection, heap and non-heap memory, and threads.

By 
Eugen Paraschiv user avatar
Eugen Paraschiv
·
Updated Oct. 30, 17 · Tutorial
Likes (16)
Comment
Save
Tweet
Share
22.3K Views

Join the DZone community and get the full member experience.

Join For Free

In this article, we’ll cover how you can monitor an application that runs on the Java Virtual Machine by going over some of the critical metrics you need to track. And, as a monitoring tool, we’ll use Stackify Retrace.

The application we’ll monitor to exemplify these metrics is a real-world Java web application built using the Spring Framework. Users can register, login, connect their Reddit account and schedule their posts to Reddit.

How JVM Memory Works

There are two important types of JVM memory to watch: heap and non-heap memory, each of these with its own purpose.

The heap memory is where the JVM stores runtime data represented by allocated instances. This is where memory for new objects comes from, and is released when the Garbage Collector runs.

When the heap space runs out, the JVM throws an OutOfMemoryError. Therefore, it’s very important to monitor the evolution of free and used heap memory to prevent the JVM from slowing down and eventually crashing.

The non-heap memory is where the JVM stores class-level information such as the fields and methods of a class, method code, runtime constant pool and internalized Strings.

Running out of non-heap memory can indicate there is a large number of Strings being internalized or a classloader leak.

Garbage Collection

In conjunction with JVM memory, it’s important you monitor the garbage collection process, since this is the process that reclaims used memory.

If the JVM spends more than 98% of the time doing garbage collection and reclaims less than 2% memory, it will throw an OutOfMemoryError with the message “GC Overhead limit exceeded”.

This can be another indication of a memory leak, or it can simply mean the application needs more heap space.

Retrace can show you how many times the GC runs per minute and how long each run lasts on average:

Retrace can show you how many times the GC runs per minute and how long each run lasts on average

These metrics are also based on JMX beans and split between minor and major collections.

The minor collections free up memory from Young Space. The major collections reclaim memory from Tenured Space, which contains objects older than 15 GC cycles.

You can then verify each metric in more detail:

Here, minor JVM garbage collections take a maximum time of 9 ms

Here, minor collections take a maximum time of 9 ms.

The GC runs are not very frequent, nor do they take a long time. Therefore, the conclusion, in this case, is that there is no heap allocation issue in the application.

JVM Threads

Another JVM metric to monitor is the number of active threads. If this is too high, it can slow down your application, and even the server it runs on.

Let’s verify JVM threads status in the Retrace Dashboard:

verify JVM threads status in the Retrace Dashboard

Currently, there are 35 active threads.

The dashboard displays the same information as a graph over a period of time:

JVM Threads

In this case, the JVM uses 34 active threads on average.

A higher number of threads means an increase in processor utilization caused by the application. This is mainly due to the processing power required by each thread. The need for the processor to frequently switch between threads also causes additional work.

On the other hand, if you expect to receive a lot of concurrent requests, then an increase in number of threads used can be helpful to decrease the response time for your users.

You can use this information in association with the CPU utilization percentage to verify if the application is causing high CPU load:

You can use this information in association with the CPU utilization percentage to verify if the application is causing high CPU load

In the graph above, the CPU utilization is less than 1% so there is no reason for concern.

Of course, you can set monitors for each of these metrics in the same way as the JVM memory monitor.

Conclusion

The JVM is a complex process that requires monitoring for several key metrics that indicate the health and performance of your running application.

APM tools can make this task a lot easier by recording data on the most important metrics and displaying it in a helpful format that’s more convenient to read and interpret. As a consequence, choosing the right APM tool is vital for successfully running and maintaining your application.

Java virtual machine Java (programming language) Metric (unit)

Published at DZone with permission of Eugen Paraschiv, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Java Virtual Threads and Scaling
  • Java’s Next Act: Native Speed for a Cloud-Native World
  • The Energy Efficiency of JVMs and the Role of GraalVM
  • Understanding Root Causes of Out of Memory (OOM) Issues in Java Containers

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!