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

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

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

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

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

Related

  • Power BI Embedded Analytics — Part 3: Power BI Embedded Demo
  • DGS GraphQL and Spring Boot
  • Auto-Instrumentation in Azure Application Insights With AKS
  • Deploying a Scala Play Application to Heroku: A Step-by-Step Guide

Trending

  • IoT and Cybersecurity: Addressing Data Privacy and Security Challenges
  • System Coexistence: Bridging Legacy and Modern Architecture
  • How to Convert XLS to XLSX in Java
  • After 9 Years, Microsoft Fulfills This Windows Feature Request

Profiling With JVisualVM

Learn more about profiling with the JVisualVM!

By 
Vishal Saxena user avatar
Vishal Saxena
·
Updated Feb. 07, 19 · Tutorial
Likes (11)
Comment
Save
Tweet
Share
26.2K Views

Join the DZone community and get the full member experience.

Join For Free

A few days back, I faced an issue on one of the Java service-hosted servers. The server load, resource consumption, and response time of service were too high.

Everyone was under the impression that the latest deployment of the JAR caused this issue, whereas the service code and performance on the local machine looked fine.

To be sure, we need data for the latest deployment to not cause this issue — that's where the use case of JVisualVM comes.

What Is the JVisualVM?

This is one of the useful, free utilities that come in the JDK bundle. It's basically a JMX client application. This utility shows stats like memory used, heap data, garbage collector, and CPU profiling.

It helps us to improve the application performance after analyzing memory leaks, heap data, and CPU consumption

With features like thread analysis and head dump analysis, it is very handy in solving run-time problems, too.

Adding JMX Properties

To enable JVisualVM to collect stats of application hosted on a remote server, we have to run our application with jmx system properties. They are as follows:

  • com.sun.management.jmxremote.port to specify the port number through which the application will be exposed
  • com.sun.management.jmxremote.ssl to specify whether secure sockets layer (SSL) encryption will be activated to secure the connection to the application
  • com.sun.management.jmxremote.authenticate to specify whether the connection will be password protected

Jar command looks like:

 java -jar -Dcom.sun.management.jmxremote.port=1098 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false my-service.jar

 

Running JVisualVM on a Local Machine

I am an Ubuntu user and jvisualvm is available at:

 /usr/lib/jvm/java-8-oracle/bin/jvisualvm 

We can run jvisualVM using the following command in bash terminal as follows:

The application will launch as follows:

Create SOCKS Proxy Connection

The SOCKS proxy can be created either by SOCKS client or ssh utility on Linux.

We usedthe following command to create a secure tunnel between localhost and remote server:

ssh -fN -D 1098 my-username@my-remote-server-IP -pXXXX

-f option forks the process and tunnel create command runs in the background

-N option tells ssh that we don’t send any command once the tunnel setup

completed

-D option used to select the listening port

 -p  Port to connect to on the remote host

You will be asked password to set up the SOCKS proxy.

Add Proxy Setting in JVisualVM

Use following steps from the tools menu:

Tools->Options->Network – Manual Proxy Settings – check it and configure SOCKS Proxy at localhost and port 1098

Add Remote Host in JVisualVM

Use the following steps from the JVisualVM sidebar.

Right click on the remote host -> Add remote host -- Type the IP of the server

Note: I have added display name myserver to hide the serverIP

Add JMX Connection

Use following steps to add the JMX connection

Right click on myserver->Type the jmx port (add 1098)

Note: I have added display name myservice-on-myserver to hide the serverIP.

Collecting Stats

Now, we can analyze the collected stats like CPU usage, system properties, detailed Threads report with access to stack traces, CPU sampling, etc.

Final snapshot will be like as follows:


All the best on your JVisualVM endeavors!

application

Opinions expressed by DZone contributors are their own.

Related

  • Power BI Embedded Analytics — Part 3: Power BI Embedded Demo
  • DGS GraphQL and Spring Boot
  • Auto-Instrumentation in Azure Application Insights With AKS
  • Deploying a Scala Play Application to Heroku: A Step-by-Step Guide

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!