Over a million developers have joined DZone.

Introducing on-demand Java Profiling

Radu Gheorghe provides an introduction to SPM's On-demand Java Profiler.

· Java Zone

Learn more about the advantages of moving from a monolithic to microservices architecture.  Brought to you in partnership with IBM.

If you are running apps on top of JVM and want to be able to profile them in production, on-demand, without affecting your app’s performance and users, read on!  Screenshots, features, and other juicy stuff is further down.

Do you run any apps on the JVM?  How do you find bottlenecks in your apps once they are in production, so you can optimize them?  If they become slow, how do you find which part of the code in your app is slow?

Maybe you look at metrics like Garbage Collection.  Maybe you run commands like jstat to see if various memory pools are full or if there are too many FGCs (Full Garbage Collections).  Or perhaps you run jstack or do kill -SIGHUP PID and look at thread dumps?

All of these are reasonable approaches… until your infrastructure grows and/or you get tired of running around, sshing to machines, running jstat and jstack or kill with sudo so you have sufficient rights to execute those commands, and so on.

Another way to tackle this is to simply have your standard profiler attached to the process, or try to attach it on the fly, but that tends to be difficult, requires more manual work, and we all know full-blown profilers typically slow down apps to the point where they could become unusable.  In short, such profiling approach is not really suitable for production.

There’s Got to be a Better Way, Right?

Indeed, there is.  Meet SPM‘s On-demand Java Profiler!

This low-impact profiler is designed to help you identify bottlenecks in your production environment without slowing down your apps.  It provides a rich analysis of the running code, much like a typical profiler.

What Types of Apps Can You Profile?

The SPM profiler can profile anything that runs on top of the JVM.  This means it can profile Java apps, Scala apps, even things like Clojure and Groovy.  You are not limited to profiling only your own apps – the apps you developed.  You can also use it to profile any of the other SPM Integrations that run on the JVM – you profile your web apps running in TomcatJettyJBoss, or Glassfish, you can  profile Solr or ElasticsearchSpark, KafkaStorm, and so on.

How to Profile Your App With SPM

If your SPM agent version is 1.29.2 or newer, you’re set.  If you have an older version update it first.

You specify the application you want to profile by:

  • selecting the SPM agent that monitors it,
  • how long you want to profile it,
  • … and SPM does the rest.  
Start Java Profiler in SPM
Start Java Profiler (click the image for a bigger view)

The selected SPM agent will then start profiling.  When done, the profiler will show you things like time spent in various methods and in their children.  It will show you the call tree, which you can look at top-down or bottom-up, etc.  It is really quite useful — in our very first profiler test run we immediately identified a suboptimal piece of code in one of our own applications! Talking about instant gratification!

Profiling Features and Benefits

With SPM’s On-demand profiler you can:

  • Profile anything that runs on the JVM, such as JavaScalaClojureGroovy, etc.
  • Start the profiling on demand and without having to add anything to the Java command-line and without needing to restart the process/app you want to monitor.
  • Find the root cause of performance bottlenecks in your or in 3rd party apps.
  • Capture stack traces and view aggregated call trees that let you drill down to a specific line in a method.
  • View the profiled call stack using top-down or bottom-up fashion.  The former shows a standard call tree from the entry point/method down to the leaf methods being called while bottom-up surfaces the hottest methods and points out from where they are called.
  • See both CPU and Wall clock time.  The former shows how much CPU time is taken by each method while Wall clock time shows how much real time each method took.
  • Exclude specific classes and methods from profiling through easy to use filtering.  This helps reduce the noise and volume of output, thus making it easier and faster to analyze.
  • Hide outliers – methods which are either not called frequently or are super fast and thus not worth looking at.
View profiler results in SPM
View Profiler Results (click the image for a bigger view)

We hope you like this new addition to SPM.  Got ideas how we could make it more useful for you?  Let us know via comments, email or @sematext. Not using SPM yet? Check out the free 30-day trial by registering here. There’s no commitment and no credit card required.  We even offer On Premises SPM and Logsene packages in addition to SaaS if that’s more to your liking.  And, even better — combine SPM with Logsene to make the integration of performance metrics, logs, events and anomalies more robust for those looking for a single pane of glass.

From Idea to Application gives you the architecture to quickly build, manage and run a range of applications (web, mobile, big data, new smart devices, etc.) on an open-standard, cloud-based platform. See why developers are using IBM Bluemix. Brought to you in partnership with IBM.

java,profiling,spm performance monitoring,performance

Published at DZone with permission of Radu Gheorghe, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}