|
| 1 | +--- |
| 2 | +title: Setup Tomcat Benchmark Environment |
| 3 | +weight: 2 |
| 4 | + |
| 5 | +### FIXED, DO NOT MODIFY |
| 6 | +layout: learningpathall |
| 7 | +--- |
| 8 | + |
| 9 | + |
| 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 LP (Learning Path) focuses on introducing two simple and easy-to-use methods: async-profiler and Java Agent. |
| 14 | + |
| 15 | + |
| 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. |
| 19 | + |
| 20 | +1. So you should install Java Development Kit (JDK) first. |
| 21 | +```bash |
| 22 | +sudo apt update |
| 23 | +sudo apt install -y openjdk-21-jdk |
| 24 | +``` |
| 25 | + |
| 26 | +2. Second, 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) |
| 27 | +```bash |
| 28 | +wget -c https://dlcdn.apache.org/tomcat/tomcat-11/v11.0.9/bin/apache-tomcat-11.0.9.tar.gz |
| 29 | +tar xzf apache-tomcat-11.0.9.tar.gz |
| 30 | +``` |
| 31 | + |
| 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. |
| 33 | +```bash |
| 34 | +vim apache-tomcat-11.0.9/webapps/examples/META-INF/context.xml |
| 35 | +# change <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" /> |
| 36 | +# to |
| 37 | +# <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow=".*" /> |
| 38 | + |
| 39 | +# now you can start Tomcat Server |
| 40 | +./apache-tomcat-11.0.9/bin/startup.sh |
| 41 | +``` |
| 42 | + |
| 43 | +4. If you can access the page at "http://${tomcat_ip}:8080/examples" via a browser, congratulations-you can proceed to the next benchmarking step. |
| 44 | + |
| 45 | + |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | +## Setup Benchmark Client - [wrk2](https://github.com/giltene/wrk2) |
| 50 | +- wrk2 is a high-performance HTTP benchmarking tool specialized in generating constant throughput loads and measuring latency percentiles for web services. |
| 51 | +- As an enhanced version of wrk, wrk2 provides accurate latency statistics under controlled request rates, ideal for performance testing of HTTP servers. |
| 52 | + |
| 53 | +1. If you intend to use wrk2, you should install some essential tools before build it. |
| 54 | +```bash |
| 55 | +sudo apt-get update |
| 56 | +sudo apt-get install -y build-essential libssl-dev git zlib1g-dev |
| 57 | +``` |
| 58 | + |
| 59 | +2. Now you can clone and build it from source. |
| 60 | +```bash |
| 61 | +sudo git clone https://github.com/giltene/wrk2.git |
| 62 | +cd wrk2 |
| 63 | +sudo make |
| 64 | +# move the executable to somewhere in your PATH |
| 65 | +sudo cp wrk /usr/local/bin |
| 66 | +``` |
| 67 | + |
| 68 | +3. Finally, you can run the benchamrk of Tomcat through wrk2. |
| 69 | +```bash |
| 70 | +wrk -c32 -t16 -R50000 -d60 http://${tomcat_ip}:8080/examples/servlets/servlet/HelloWorldExample |
| 71 | +``` |
| 72 | + Below is the output of wrk2 |
| 73 | +```console |
| 74 | +Running 1m test @ http://172.26.203.139:8080/examples/servlets/servlet/HelloWorldExample |
| 75 | + 16 threads and 32 connections |
| 76 | + Thread calibration: mean lat.: 0.986ms, rate sampling interval: 10ms |
| 77 | + Thread calibration: mean lat.: 0.984ms, rate sampling interval: 10ms |
| 78 | + Thread calibration: mean lat.: 0.999ms, rate sampling interval: 10ms |
| 79 | + Thread calibration: mean lat.: 0.994ms, rate sampling interval: 10ms |
| 80 | + Thread calibration: mean lat.: 0.983ms, rate sampling interval: 10ms |
| 81 | + Thread calibration: mean lat.: 0.989ms, rate sampling interval: 10ms |
| 82 | + Thread calibration: mean lat.: 0.991ms, rate sampling interval: 10ms |
| 83 | + Thread calibration: mean lat.: 0.993ms, rate sampling interval: 10ms |
| 84 | + Thread calibration: mean lat.: 0.985ms, rate sampling interval: 10ms |
| 85 | + Thread calibration: mean lat.: 0.990ms, rate sampling interval: 10ms |
| 86 | + Thread calibration: mean lat.: 0.987ms, rate sampling interval: 10ms |
| 87 | + Thread calibration: mean lat.: 0.990ms, rate sampling interval: 10ms |
| 88 | + Thread calibration: mean lat.: 0.984ms, rate sampling interval: 10ms |
| 89 | + Thread calibration: mean lat.: 0.991ms, rate sampling interval: 10ms |
| 90 | + Thread calibration: mean lat.: 0.978ms, rate sampling interval: 10ms |
| 91 | + Thread calibration: mean lat.: 0.976ms, rate sampling interval: 10ms |
| 92 | + Thread Stats Avg Stdev Max +/- Stdev |
| 93 | + Latency 1.00ms 454.90us 5.09ms 63.98% |
| 94 | + Req/Sec 3.31k 241.68 4.89k 63.83% |
| 95 | + 2999817 requests in 1.00m, 1.56GB read |
| 96 | +Requests/sec: 49997.08 |
| 97 | +Transfer/sec: 26.57MB |
| 98 | +``` |
| 99 | + |
| 100 | + |
0 commit comments