You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/learning-paths/servers-and-cloud-computing/java-perf-flamegraph/1_setup.md
+59-29Lines changed: 59 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
---
2
-
title: Setup Tomcat Benchmark Environment
2
+
title: Set up Tomcat benchmark environment
3
3
weight: 2
4
4
5
5
### FIXED, DO NOT MODIFY
@@ -8,43 +8,57 @@ layout: learningpathall
8
8
9
9
10
10
## Overview
11
-
There are numerous performance analysis methods and tools for Java applications, among which the call stack flame graph method is regarded as a conventional entry-level approach. Therefore, generating flame graphs is considered a basic operation.
12
-
Various methods and tools are available for generating Java flame graphs, including `async-profiler`, `Java Agent`, `jstack`, `JFR` (Java Flight Recorder), etc.
13
-
This Learning Path focuses on introducing two simple and easy-to-use methods: `async-profiler` and `Java Agent`.
14
11
12
+
Flame graphs are a widely used entry point for analyzing Java application performance. Tools for generating flame graphs include `async-profiler`, Java agents, `jstack`, and Java Flight Recorder (JFR). This Learning Path focuses on two practical approaches: using `async-profiler` and a Java agent.
15
13
16
-
## Setup Benchmark Server - Tomcat
17
-
-[Apache Tomcat](https://tomcat.apache.org/) is an open-source Java Servlet container that enables running Java web applications, handling HTTP requests and serving dynamic content.
18
-
- As a core component in Java web development, Apache Tomcat supports Servlet, JSP, and WebSocket technologies, providing a lightweight runtime environment for web apps.
14
+
In this section, you'll set up a benchmark environment using Apache Tomcat and `wrk2` to simulate HTTP load and evaluate performance on an Arm-based server.
15
+
16
+
## Set up the Tomcat benchmark server
17
+
[Apache Tomcat](https://tomcat.apache.org/) is an open-source Java Servlet container that runs Java web applications, handles HTTP requests, and serves dynamic content. It supports technologies such as Servlet, JSP, and WebSocket.
18
+
19
+
## Install the Java Development Kit (JDK)
20
+
21
+
Install OpenJDK 21 on your Arm-based Ubuntu server:
19
22
20
-
1. Start by installing Java Development Kit (JDK) on your Arm-based server running Ubuntu:
21
23
```bash
22
24
sudo apt update
23
25
sudo apt install -y openjdk-21-jdk
24
26
```
25
27
26
-
2. Next, you can install Tomcat by either [building it from source](https://github.com/apache/tomcat) or downloading the pre-built package simply from [the official website](https://tomcat.apache.org/whichversion.html)
Alternatively, you can build Tomcat [from source](https://github.com/apache/tomcat).
37
+
38
+
## Enable access to Tomcat examples
39
+
40
+
To access the built-in examples from your local network or external IP, modify the `context.xml` file:
31
41
32
-
3. If you intend to access the built-in examples of Tomcat via an intranet IP or even an external IP, you need to modify a configuration file as shown:
33
42
```bash
34
43
vi apache-tomcat-11.0.9/webapps/examples/META-INF/context.xml
35
44
```
36
-
Then change the allow value as shown and save the changes:
{{% notice Note %}}Make sure port 8080 is open in the security group of the IP address for your Arm-based Linux machine.{{% /notice%}}
64
84
65
-
Make sure port 8080 is open in the security group of the IP address for your Arm-based Linux machine.
85
+
## Set up the benchmarking client using wrk2
86
+
[Wrk2](https://github.com/giltene/wrk2) is a high-performance HTTP benchmarking tool specialized in generating constant throughput loads and measuring latency percentiles for web services. `wrk2` is an enhanced version of `wrk` that provides accurate latency statistics under controlled request rates, ideal for performance testing of HTTP servers.
`wrk2` is a high-performance HTTP benchmarking tool specialized in generating constant throughput loads and measuring latency percentiles for web services. `wrk2` is an enhanced version of `wrk` that provides accurate latency statistics under controlled request rates, ideal for performance testing of HTTP servers.
88
+
{{% notice Note %}}
89
+
Currently `wrk2` is only supported on x86 machines. Run the benchmark client steps below on an `x86_64` server running Ubuntu.
90
+
{{%/notice%}}
69
91
70
-
Currently `wrk2` is only supported on x86 machines. You will run the Benchmark Client steps shown below on an x86_64 server running Ubuntu.
92
+
## Install dependencies
71
93
94
+
Install the required packages:
72
95
73
-
1. To use `wrk2`, you will need to install some essential tools before you can build it:
title: Generate Java flame graphs using async-profiler
3
3
weight: 3
4
4
5
5
### FIXED, DO NOT MODIFY
6
6
layout: learningpathall
7
7
---
8
8
9
-
## Java Flame Graph Generation using [async-profiler](https://github.com/async-profiler/async-profiler)
10
-
`async-profiler` is a low-overhead sampling profiler for JVM applications, capable of capturing CPU, allocation, and lock events to generate actionable performance insights.
11
-
A lightweight tool for Java performance analysis, `async-profiler` produces flame graphs and detailed stack traces with minimal runtime impact, suitable for production environments. In this section, you will learn how to install and use it to profile your Tomcat instance being benchmarked.
9
+
## Overview
10
+
11
+
[Async-profiler](https://github.com/async-profiler/async-profiler) is a low-overhead sampling profiler for JVM applications. It can capture CPU usage, memory allocations, and lock events to generate flame graphs and detailed stack traces.
12
+
13
+
14
+
This tool is well-suited for production environments due to its minimal runtime impact. In this section, you'll install and run `async-profiler` to analyze performance on your Tomcat instance under benchmark load.
15
+
16
+
{{%notice Note%}}
17
+
Install and run `async-profiler` on the same Arm-based Linux machine where Tomcat is running to ensure accurate profiling.
18
+
{{%/notice%}}
19
+
20
+
## Install async-profiler
21
+
22
+
Download and extract the latest release:
12
23
13
-
You should deploy `async-profiler` on the same Arm Linux machine where Tomcat is running to ensure accurate performance profiling.
title: Generate Java flame graphs using a Java agent
3
3
weight: 4
4
4
5
5
6
6
### FIXED, DO NOT MODIFY
7
7
layout: learningpathall
8
8
---
9
9
10
-
## Java Flame Graph Generation using Java agent and perf
11
-
To profile a Java application with perf and ensure proper symbol resolution, you must include `libperf-jvmti.so` when launching the Java application.
12
-
-`libperf-jvmti.so` is a JVM TI agent library enabling perf to resolve Java symbols, facilitating accurate profiling of Java applications.
13
-
- A specialized shared library, `libperf-jvmti.so` bridges perf and the JVM, enabling proper translation of memory addresses to Java method names during profiling.
10
+
## Overview
11
+
12
+
You can profile a Java application using `perf` by including a Java agent that enables symbol resolution. This allows `perf` to capture meaningful method names instead of raw memory addresses.
13
+
14
+
The required library is `libperf-jvmti.so`, a JVM Tool Interface (JVMTI) agent that bridges `perf` and the JVM. It ensures that stack traces collected during profiling can be accurately resolved to Java methods.
15
+
16
+
In this section, you'll configure Tomcat to use this Java agent and generate a flame graph using the FlameGraph toolkit.
17
+
18
+
## Locate the Java agent
19
+
20
+
Locate the `libperf-jvmti.so` library:
14
21
15
-
1. Find where `libperf-jvmti.so` is installed on your Arm-based Linux server:
16
22
```bash
17
23
pushd /usr/lib
18
24
find . -name libperf-jvmti.so`
19
25
```
20
-
The output will show the path of the library that you will then include in your Tomcat setup file:
26
+
The output will show the path to the shared object file:
27
+
28
+
## Modify Tomcat configuration
29
+
30
+
Open the Tomcat launch script:
31
+
21
32
```bash
22
33
vi apache-tomcat-11.0.9/bin/catalina.sh
23
34
```
24
-
Add JAVA_OPTS="$JAVA_OPTS -agentpath:/usr/lib/linux-tools-6.8.0-63/libperf-jvmti.so -XX:+PreserveFramePointer" to `catalina.sh`. Make sure the path matches the location on your machine from the previous step.
35
+
Add the following line (replace the path if different on your system):
4. You can now successfully launch `profile.svg`in a browser to analyse the profiling result
70
+
You can now launch `profile.svg`in a browser to analyse the profiling result:
47
71
48
-

72
+

title: Analyze Java Performance on Arm servers using FlameGraphs
3
-
4
-
draft: true
5
-
cascade:
6
-
draft: true
7
-
2
+
title: Analyze Java performance on Arm servers using flame graphs
8
3
minutes_to_complete: 30
9
4
10
-
who_is_this_for: This is an introductory topic for software developers looking to analyze the performance of their Java applications on the Arm Neoversebased servers using flame graphs.
5
+
who_is_this_for: This is an introductory topic for developers who want to analyze the performance of Java applications on Arm Neoverse-based servers using flame graphs.
11
6
12
7
learning_objectives:
13
-
- How to set up tomcat benchmark environment
14
-
- How to generate flame graphs for Java applications using async-profiler
15
-
- How to generate flame graphs for Java applications using Java agent
8
+
- Set up a benchmarking environment using Tomcat and wrk2
9
+
- Generate flame graphs using async-profiler
10
+
- Generate flame graphs using a Java agent
16
11
17
12
prerequisites:
18
-
- An Arm-based and x86 computer running Ubuntu. You can use a server instance from a cloud service provider of your choice.
19
-
- Basic familiarity with Java applications and flame graphs
13
+
- Access to both Arm-based and x86-based computers running Ubuntu (you can use cloud-based server instances)
14
+
- Basic familiarity with Java applications and performance profiling using flame graphs
0 commit comments