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
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
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

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • How to Read a Thread Dump
  • Free, Fast, Open, Production-Proven, and All Java: OpenJ9
  • Java and Low Latency
  • GraalVM — Byte Code to Bit Code

Trending

  • Wild West to the Agile Manifesto [Video]
  • Docker and Kubernetes Transforming Modern Deployment
  • Multi-Tenancy With Keycloak, Angular, and SpringBoot
  • Automate Migration Assessment With XML Linter
  1. DZone
  2. Coding
  3. Java
  4. Diagnose CPU Spikes in a Non-Intrusive Manner

Diagnose CPU Spikes in a Non-Intrusive Manner

In this post, we are going to discuss a non-intrusive approach (i.e., approach that doesn’t add any noticeable overhead to the application) to diagnose CPU spike.

Ram Lakshmanan user avatar by
Ram Lakshmanan
CORE ·
Aug. 30, 23 · Tutorial
Like (1)
Save
Tweet
Share
3.38K Views

Join the DZone community and get the full member experience.

Join For Free

In this post, we are going to discuss a non-intrusive approach (i.e., an approach that doesn’t add any noticeable overhead to the application) to diagnose CPU spikes. Thus, you can use this approach in your production environment to troubleshoot CPU spikes.

Works on all JVM languages:

This approach can be used to troubleshoot CPU spikes in all programming languages that run on Java Virtual Machine (JVM) like Java, Scala, Kotlin, JRuby, Jython, etc...

Step 1: Capture 360° Data

You can use the open-source yCrash data script to capture 360° data from your application stack. This script basically captures 16 different artifacts from your application stack (GC Log, thread dump, heap substitute, netstat, iostat...) and runs less than 30 seconds. Thus, it doesn’t add any measurable overhead to your application. You can trigger this script from any platform (all Linux flavors, Windows...) and any environment (bare metal, cloud, containers, k8…).

Fig: 360-degree data

Fig: 360-degree data

Here are the steps to run this script:

1. Download the latest yc-data-script 

2. Unzip the downloaded yc-agent-latest.zip file. (Say you are unzipping in ‘/opt/workspace/yc-agent-latest’ folder)

3. In the unzipped folder, you will find yc-data-script by operating system:

a) linux/yc – If you are running on Unix/Linux, then use this script.

b) windows/yc.exe – If you are running on Windows, then use this script.

c) mac/yc – If you are running on MAC, then use this script.

4. You can execute the yc script by issuing the following command:

./yc -j {JAVA_HOME} -onlyCapture -p {PID}


Where, JAVA_HOME is the home directory where JDK is installed, and PID is the target JVM’s process ID.

Example:

./yc -j /usr/java/jdk1.8.0_141 -onlyCapture -p 15326


When you pass the above arguments, yc-data-script will capture all the application-level and system-level artifacts/logs from your application stack for analysis. Captured artifacts will be compressed into a zip file and stored in the current directory where the above command was executed. The zip file will have the name in the format: ‘yc-YYYY-MM-DDTHH-mm-ss.zip‘. Example: ‘yc-2021-03-06T14-02-42.zip‘.

2. Analyze Captured Data

Once you have captured the data, you can analyze them using the yCrash server. You can upload the captured zip file to the yCrash server for analysis. The yCrash server analyzes all the captured data and generates one unified root cause analysis report instantly. Note: There is a free tier in the yCrash application, which you can use for CPU diagnosis purposes. In the yCrash incident report, you will see a ‘CPU consumption by thread’ section under the ‘Thread’ report (as shown below):

Fig: CPU consumption by threads reported by yCrash

Fig: CPU consumption by threads reported by yCrash

This section will show all the CPU-consuming threads and the exact lines of code they are working on. Equipped with this information, you can spot the ‘black sheep’ lines of code that are causing the CPU to spike up.

How Does It Work?

‘Thread dump’ and ‘top -H -p {PROCESS_ID}’ are the two artifacts that yCrash data script captures. Here ‘top -H -p {PROCESS_ID}’ command shows the list of thread Ids and the amount of CPU and memory it consumes within the specified PROCESS_ID. ‘Thread dump’ shows the code path in which threads are executing. yCrash tool marries these two data and produces the above report. For more details, refer to this post.

I hope this approach will help you to isolate CPU-consuming lines of code effectively. Happy Troubleshooting!!

Java Development Kit Java virtual machine Spike (software development) Virtual Machine

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

Opinions expressed by DZone contributors are their own.

Related

  • How to Read a Thread Dump
  • Free, Fast, Open, Production-Proven, and All Java: OpenJ9
  • Java and Low Latency
  • GraalVM — Byte Code to Bit Code

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • 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: