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

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Using Heap Dumps to Find Memory Leaks
  • Understanding Root Causes of Out of Memory (OOM) Issues in Java Containers
  • Charge Vertical Scaling With the Latest Java GCs
  • Java Thread Dump Analysis

Trending

  • Agile and Quality Engineering: A Holistic Perspective
  • A Guide to Developing Large Language Models Part 1: Pretraining
  • Stateless vs Stateful Stream Processing With Kafka Streams and Apache Flink
  • Breaking Bottlenecks: Applying the Theory of Constraints to Software Development
  1. DZone
  2. Data Engineering
  3. Data
  4. Troubleshooting Microservices OutOfMemoryError: Metaspace

Troubleshooting Microservices OutOfMemoryError: Metaspace

Confronted with an interesting java.lang.OutOfMemoryError: Metaspace problem in a microservice application? Learn the steps taken to troubleshoot the problem.

By 
Ram Lakshmanan user avatar
Ram Lakshmanan
DZone Core CORE ·
Aug. 19, 22 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
6.5K Views

Join the DZone community and get the full member experience.

Join For Free

Recently we confronted an interesting java.lang.OutOfMemoryError: Metaspace problem in a microservice application. This microservice application will run smoothly for the initial few hours, but later it will start to throw java.lang.OutOfMemoryError: Metaspace. In this post, let me share the steps we pursued to troubleshoot this problem.

Different Types of OutOfMemoryError

JVM memory has the following regions: 

  • Young generation
  • Old generation
  • Metaspace
  • Others region

When you encounter java.lang.OutOfMemoryError: Metaspace, it indicates that the Metaspace region in the JVM memory is getting saturated. Metaspace is the region where metadata details that are required to execute your application are stored. In a nutshell, it contains class definitions, method definitions, and other metadata of your application. To learn more about what gets stored in each of the JVM memory regions, you may refer to this video clip: JVM Memory - Learn Easily.

Note: There are 9 different types of java.lang.OutOfMemoryErrors. You can learn about those in the post "Flavors of OutOfMemoryErrors." java.lang.OutOfMemroyError: Metaspace is one type of them, but not a common type.

Diagnose java.lang.OutOfMemoryError: Metaspace

Best place to start debugging the java.lang.OutOfMemoryError is the garbage collection log. If you haven’t enabled the garbage collection log for your application, you may consider enabling it by passing the JVM arguments mentioned here. Enabling a garbage collection log doesn’t add noticeable overhead to your application. Thus it’s recommended to enable garbage collection logs on all production JVM instances. Learn more about how to see the great benefits of a garbage collection log here.

We uploaded the garbage collection log of this troubled microservice application to the GCeasy-GC log analysis tool. Here is the GC log analysis report generated by the tool. Below is the Heap usage graph reported by the tool.

Heap usage graph reported by GCeasy

Heap usage graph reported by GCeasy

I would like to highlight a few observations from this graph:

  1. The red triangle in the graph indicates the occurrence of the Full Garbage Collection event. When the Full Garbage Collection event runs, it pauses your entire application. It tries to free up memory from all the regions (Young, Old, Metaspace) in the memory. You can see Full Garbage Collection events to be running consecutively from 12:30 am.
  2. Even though the maximum heap memory size is 2.5GB, Full Garbage Collection events were consecutively triggered even when heap memory usage is only at 10% (i.e., 250MB) of its maximum size. Typically, Full Garbage Collection events are consecutively triggered when heap memory grows to its maximum size. To understand why this happens, please review the next point.
  3. Below is the Metaspace region’s memory consumption graph from the report:

Metaspace usage graph reported by GCeasy

Metaspace usage graph reported by GCeasy

You can notice the Metaspace region’s memory consumption growing and dropping in a saw-tooth pattern until 12:30 am. After 12:30 am, the Metaspace region’s memory consumption isn’t dropping at all, even though Full GCs are consecutively running. It indicates garbage collection events aren’t able to free up Metaspace. It clearly indicates there is a memory leak in the Metaspace region.

Root Cause of java.lang.OutOfMemoryError: Metaspace 

Now we have confirmed that a memory leak is happening in the Metaspace region. Therefore, the next logical step is to inspect the Metaspace region and try to understand what objects occupy this region. There are 5 different approaches to studying the contents in the Metaspace region. We went for the heap dump analysis approach.

Basically, we used the yCrash tool to capture the heap dump and analyze it. The tool instantly pointed out the problem: it was reporting a thread that was experiencing OutOfMemoryError. Apparently, this thread was experiencing OutOfMemoryError when invoking a 3rd party library. Due to a bug, this 3rd party library was creating new class definitions for every new request. This application was running on an older version of this 3rd party library. However, this bug was fixed in the latest version of the library. Once the 3rd party library was upgraded to the latest version, this problem got resolved. 

Video



Java virtual machine garbage collection microservice

Published at DZone with permission of Ram Lakshmanan, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Using Heap Dumps to Find Memory Leaks
  • Understanding Root Causes of Out of Memory (OOM) Issues in Java Containers
  • Charge Vertical Scaling With the Latest Java GCs
  • Java Thread Dump Analysis

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!