Profiling Java process on Azure web apps

There are certain situations when your Java web application is not performing as you expect it to. To understand where the problem lies, you may need to profile your application and understand its behavior for different flows.

Azure App Service environment being a sandbox environment, does not support to install JProfiler and not even expose the JMX information, which can be read by Jconsole to profile your application. The way to profile you application on Azure App Service environment is by using the New Relic tool.

Follow these steps -

1. Create a New Relic APM account on Azure portal.

[caption id="attachment_1303" align="alignnone" width="909"]New Relic account New Relic account[/caption]

Make sure you select at least the Small Pro in the pricing tier.

2. Open the New Relic APM and click on the View at New Relic link as highlighted.

[caption id="attachment_1312" align="alignnone" width="247"]View at New Relic View at New Relic[/caption]

3. Click on Browser and Install a New Relic APM agent.

[caption id="attachment_1321" align="alignnone" width="927"]New Relic Java agent New Relic Java agent[/caption]

4. Select "Java" and then Download the Java agent mentioned at step 2.

5. Unzip the downloaded file and copy the newrelic folder to your wwwroot folder or any folder within your application.

[caption id="attachment_1322" align="alignnone" width="493"]newrelic folder newrelic folder[/caption]

6. Add the Application Settings for CATALINA_OPTS in your webapp on Azure Portal with value as
-Djavaagent:"D:\home\site\wwwroot\newrelic\newrelic.jar" .
Make sure you modify the path accordingly.

Note - Please add the letter "D" before javaagent only if you are using Tomcat 8 or earlier. For Tomcat 8.5 onwards, don't use the letter "D" before javaagent.

 

[caption id="attachment_1332" align="alignnone" width="881"]App Setting for Catalina options App Setting for Catalina options[/caption]

7. Once your website is accessed, you should see the JVM listed on your New Relic Dashboard.

[caption id="attachment_1341" align="alignnone" width="344"]New Relic Dashboard with JVMs info New Relic Dashboard with JVMs info[/caption]

8. Using the Profile JVM link, you can profile your Java process and take thread dumps.

[caption id="attachment_1361" align="alignnone" width="907"]JVM Information JVM Information[/caption]

Sample Profiled data

[caption id="attachment_1371" align="alignnone" width="1532"]Tree View for Profiled data Tree View for Profiled data[/caption]

Hope this helps you debugging issues with your webapp!