Skip to content

Commit 4751a7f

Browse files
authored
Merge pull request #2200 from pareenaverma/content_review
Tech review of Java Flamegraph LP
2 parents ded180c + c2afe85 commit 4751a7f

File tree

4 files changed

+47
-33
lines changed

4 files changed

+47
-33
lines changed

content/learning-paths/servers-and-cloud-computing/java-perf-flamegraph/1_setup.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ layout: learningpathall
77
---
88

99

10-
## Before You Begin
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`.
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`.
1414

1515

1616
## Setup Benchmark Server - Tomcat
1717
- [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.
1818
- As a core component in Java web development, Apache Tomcat supports Servlet, JSP, and WebSocket technologies, providing a lightweight runtime environment for web apps.
1919

20-
1. Start by installing Java Development Kit (JDK) on your Arm-based server:
20+
1. Start by installing Java Development Kit (JDK) on your Arm-based server running Ubuntu:
2121
```bash
2222
sudo apt update
2323
sudo apt install -y openjdk-21-jdk
@@ -31,13 +31,13 @@ tar xzf apache-tomcat-11.0.9.tar.gz
3131

3232
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:
3333
```bash
34-
vim apache-tomcat-11.0.9/webapps/examples/META-INF/context.xml
34+
vi apache-tomcat-11.0.9/webapps/examples/META-INF/context.xml
3535
```
36-
Then change the values:
37-
```console
36+
Then change the allow value as shown and save the changes:
37+
```output
3838
# change <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
3939
# to
40-
# <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow=".*" />
40+
<Valve className="org.apache.catalina.valves.RemoteAddrValve" allow=".*" />
4141
```
4242
Now you can start Tomcat Server:
4343
```bash
@@ -62,9 +62,14 @@ Tomcat started.
6262

6363
![example image alt-text#center](./_images/lp-tomcat-examples.png "Tomcat-Examples")
6464

65+
Make sure port 8080 is open in the security group of the IP address for your Arm-based Linux machine.
66+
6567
## Setup Benchmark Client - [wrk2](https://github.com/giltene/wrk2)
6668
`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.
6769

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.
71+
72+
6873
1. To use `wrk2`, you will need to install some essential tools before you can build it:
6974
```bash
7075
sudo apt-get update

content/learning-paths/servers-and-cloud-computing/java-perf-flamegraph/2_async-profiler.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ weight: 3
66
layout: learningpathall
77
---
88

9-
## Java Flame Graph Generation via async-profiler [async-profiler](https://github.com/async-profiler/async-profiler) (Recommended)
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.
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.
1212

13-
You should deploy async-profiler on the same machine where Tomcat is running to ensure accurate performance profiling.
13+
You should deploy `async-profiler` on the same Arm Linux machine where Tomcat is running to ensure accurate performance profiling.
1414
1. Download async-profiler-4.0 and uncompress
1515
```bash
1616
wget -c https://github.com/async-profiler/async-profiler/releases/download/v4.0/async-profiler-4.0-linux-arm64.tar.gz
@@ -21,10 +21,12 @@ tar xzf async-profiler-4.0-linux-arm64.tar.gz
2121
```bash
2222
cd async-profiler-4.0-linux-arm64/bin
2323
./asprof -d 10 -f profile.html $(jps | awk /Bootstrap/'{print $1}')
24-
# or
24+
```
25+
You can also run:
26+
```
2527
./asprof -d 10 -f profile.html ${tomcat_process_id}
2628
```
2729

28-
3. Launch profile.html in a browser to analyse the profiling result
30+
3. Now launch `profile.html` in a browser to analyse your profiling result
2931

3032
![example image alt-text#center](_images/lp-flamegraph-async.png "Java Flame Graph via async-profiler")

content/learning-paths/servers-and-cloud-computing/java-perf-flamegraph/3_agent.md

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,42 @@ weight: 4
77
layout: learningpathall
88
---
99

10-
## Java Flame Graph Generation via 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+
## 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.
1414

15-
1. Find and add libperf-jvmti.so to Java option
15+
1. Find where `libperf-jvmti.so` is installed on your Arm-based Linux server:
16+
```bash
17+
pushd /usr/lib
18+
find . -name libperf-jvmti.so`
19+
```
20+
The output will show the path of the library that you will then include in your Tomcat setup file:
1621
```bash
1722
vi apache-tomcat-11.0.9/bin/catalina.sh
18-
# add JAVA_OPTS="$JAVA_OPTS -agentpath:/usr/lib/linux-tools-6.8.0-63/libperf-jvmti.so -XX:+PreserveFramePointer"
23+
```
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.
25+
26+
Now shutdown and restart Tomcat:
27+
```bash
1928
cd apache-tomcat-11.0.9/bin
2029
./shutdown.sh
2130
./startup.sh
2231
```
2332

24-
2. Use perf to profile Tomcat, and restart wrk if necessary
33+
2. Use perf to profile Tomcat, and restart wrk that running on your x86 instance if necessary:
2534
```bash
2635
sudo perf record -g -k1 -p $(jps | awk /Bootstrap/'{print $1}') -- sleep 10
2736
```
37+
This command will record the collected data in a file named `perf.data`
2838

29-
3. Convert the collected perf.data file into a Java flame graph using FlameGraph
39+
3. Convert the collected `perf.data` into a Java flame graph using FlameGraph
3040
```bash
3141
git clone https://github.com/brendangregg/FlameGraph.git
32-
export PATH=$PATH:/root/FlameGraph
42+
export PATH=$PATH:`pwd`/FlameGraph
3343
sudo perf inject -j -i perf.data | perf script | stackcollapse-perf.pl | flamegraph.pl &> profile.svg
3444
```
3545

36-
4. Launch profile.svg in a browser to analyse the profiling result
46+
4. You can now successfully launch `profile.svg` in a browser to analyse the profiling result
3747

3848
![example image alt-text#center](_images/lp-flamegraph-agent.png "Java Flame Graph via Java agent and perf")

content/learning-paths/servers-and-cloud-computing/java-perf-flamegraph/_index.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ learning_objectives:
1515
- How to generate flame graphs for Java applications using Java agent
1616

1717
prerequisites:
18-
- Basic familiarity with Java applications
19-
- Basic familiarity with flame graphs
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
2020

2121
author: Ying Yu, Martin Ma
2222

@@ -42,16 +42,13 @@ further_reading:
4242
link: https://wiki.openjdk.org/
4343
type: documentation
4444
- resource:
45-
title: PLACEHOLDER BLOG
46-
link: PLACEHOLDER BLOG LINK
47-
type: blog
48-
- resource:
49-
title: PLACEHOLDER GENERAL WEBSITE
50-
link: PLACEHOLDER GENERAL WEBSITE LINK
45+
title: Java FlameGraphs
46+
link: https://www.brendangregg.com/flamegraphs.html
5147
type: website
5248

5349

5450

51+
5552
### FIXED, DO NOT MODIFY
5653
# ================================================================================
5754
weight: 1 # _index.md always has weight of 1 to order correctly

0 commit comments

Comments
 (0)