|
| 1 | +--- |
| 2 | +title: Optimal baseline before tuning |
| 3 | +weight: 3 |
| 4 | + |
| 5 | +### FIXED, DO NOT MODIFY |
| 6 | +layout: learningpathall |
| 7 | +--- |
| 8 | + |
| 9 | +{{% notice Note %}} |
| 10 | +To achieve maximum performance, ulimit -n 65535 must be executed on both server and client! |
| 11 | +{{% /notice %}} |
| 12 | + |
| 13 | +## Optimal baseline before tuning |
| 14 | +- Baseline on Grace bare-metal (default configuration) |
| 15 | +- Baseline on Grace bare-metal (access logging disabled) |
| 16 | +- Baseline on Grace bare-metal (optimal thread count) |
| 17 | + |
| 18 | +### Baseline on Grace bare-metal (default configuration) |
| 19 | +{{% notice Note %}} |
| 20 | +To align with the typical deployment scenario of Tomcat, reserve 8 cores online and set all other cores offline |
| 21 | +{{% /notice %}} |
| 22 | + |
| 23 | +1. You can offline the CPU cores using the below command. |
| 24 | +```bash |
| 25 | +for no in {8..143}; do sudo bash -c "echo 0 > /sys/devices/system/cpu/cpu${no}/online"; done |
| 26 | +``` |
| 27 | +2. Use the following commands to verify that cores 0-7 are online and the remaining cores are offline. |
| 28 | +```bash |
| 29 | +lscpu |
| 30 | +``` |
| 31 | +You can check the following information: |
| 32 | +```bash |
| 33 | +Architecture: aarch64 |
| 34 | + CPU op-mode(s): 64-bit |
| 35 | + Byte Order: Little Endian |
| 36 | +CPU(s): 144 |
| 37 | + On-line CPU(s) list: 0-7 |
| 38 | + Off-line CPU(s) list: 8-143 |
| 39 | +Vendor ID: ARM |
| 40 | + Model name: Neoverse-V2 |
| 41 | +... |
| 42 | +``` |
| 43 | + |
| 44 | +3. Use the following command on the Grace bare-metal where `Tomcat` is on |
| 45 | +```bash |
| 46 | +~/apache-tomcat-11.0.9/bin/shutdown.sh 2>/dev/null |
| 47 | +ulimit -n 65535 && ~/apache-tomcat-11.0.9/bin/startup.sh |
| 48 | +``` |
| 49 | + |
| 50 | +4. And use the following command on the `x86_64` bare-metal where `wrk2` is on |
| 51 | +```bash |
| 52 | +tomcat_ip=10.169.226.181 |
| 53 | +``` |
| 54 | +```bash |
| 55 | +ulimit -n 65535 && wrk -c1280 -t128 -R500000 -d60 http://${tomcat_ip}:8080/examples/servlets/servlet/HelloWorldExample |
| 56 | +``` |
| 57 | + |
| 58 | +The result of default configuration is: |
| 59 | +```bash |
| 60 | + Thread Stats Avg Stdev Max +/- Stdev |
| 61 | + Latency 13.29s 3.25s 19.07s 57.79% |
| 62 | + Req/Sec 347.59 430.94 0.97k 66.67% |
| 63 | + 3035300 requests in 1.00m, 1.58GB read |
| 64 | + Socket errors: connect 1280, read 0, write 0, timeout 21760 |
| 65 | +Requests/sec: 50517.09 |
| 66 | +Transfer/sec: 26.84MB |
| 67 | +``` |
| 68 | + |
| 69 | +### Baseline on Grace bare-metal (access logging disabled) |
| 70 | +To disable the access logging, use a text editor to modify the `server.xml` file by commenting out or removing the **`org.apache.catalina.valves.AccessLogValve`** configuration. |
| 71 | + |
| 72 | +The file is at: |
| 73 | +```bash |
| 74 | +vi ~/apache-tomcat-11.0.9/conf/server.xml |
| 75 | +``` |
| 76 | + |
| 77 | +The configuratin is at the end of the file, and common out or remove it. |
| 78 | +```xml |
| 79 | +<!-- |
| 80 | + <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" |
| 81 | + prefix="localhost_access_log" suffix=".txt" |
| 82 | + pattern="%h %l %u %t "%r" %s %b" /> |
| 83 | +--> |
| 84 | +``` |
| 85 | + |
| 86 | +1. Use the following command on the Grace bare-metal where `Tomcat` is on |
| 87 | +```bash |
| 88 | +~/apache-tomcat-11.0.9/bin/shutdown.sh 2>/dev/null |
| 89 | +ulimit -n 65535 && ~/apache-tomcat-11.0.9/bin/startup.sh |
| 90 | +``` |
| 91 | + |
| 92 | +2. And use the following command on the `x86_64` bare-metal where `wrk2` is on |
| 93 | +```bash |
| 94 | +ulimit -n 65535 && wrk -c1280 -t128 -R500000 -d60 http://${tomcat_ip}:8080/examples/servlets/servlet/HelloWorldExample |
| 95 | +``` |
| 96 | + |
| 97 | +The result of access logging disabled is: |
| 98 | +```bash |
| 99 | + Thread Stats Avg Stdev Max +/- Stdev |
| 100 | + Latency 12.66s 3.05s 17.87s 57.47% |
| 101 | + Req/Sec 433.69 524.91 1.18k 66.67% |
| 102 | + 3572200 requests in 1.00m, 1.85GB read |
| 103 | + Socket errors: connect 1280, read 0, write 0, timeout 21760 |
| 104 | +Requests/sec: 59451.85 |
| 105 | +Transfer/sec: 31.59MB |
| 106 | +``` |
| 107 | + |
| 108 | +### Baseline on Grace bare-metal (optimal thread count) |
| 109 | +To minimize resource contention between threads and overhead from thread context switching, the number of CPU-intensive threads in Tomcat should be aligned with the number of CPU cores. |
| 110 | + |
| 111 | +1. When using `wrk` to perform pressure testing on `Tomcat`: |
| 112 | +```bash |
| 113 | +top -H -p$(pgrep java) |
| 114 | +``` |
| 115 | + |
| 116 | +You can see the below information |
| 117 | +```bash |
| 118 | +top - 12:12:45 up 1 day, 7:04, 5 users, load average: 7.22, 3.46, 1.75 |
| 119 | +Threads: 79 total, 8 running, 71 sleeping, 0 stopped, 0 zombie |
| 120 | +%Cpu(s): 3.4 us, 1.9 sy, 0.0 ni, 94.1 id, 0.0 wa, 0.0 hi, 0.5 si, 0.0 st |
| 121 | +MiB Mem : 964975.5 total, 602205.6 free, 12189.5 used, 356708.3 buff/cache |
| 122 | +MiB Swap: 0.0 total, 0.0 free, 0.0 used. 952786.0 avail Mem |
| 123 | + |
| 124 | + PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND |
| 125 | + 53254 yinyu01 20 0 38.0g 1.4g 28288 R 96.7 0.1 2:30.70 http-nio-8080-e |
| 126 | + 53255 yinyu01 20 0 38.0g 1.4g 28288 R 96.7 0.1 2:30.62 http-nio-8080-e |
| 127 | + 53256 yinyu01 20 0 38.0g 1.4g 28288 R 96.7 0.1 2:30.64 http-nio-8080-e |
| 128 | + 53258 yinyu01 20 0 38.0g 1.4g 28288 R 96.7 0.1 2:30.62 http-nio-8080-e |
| 129 | + 53260 yinyu01 20 0 38.0g 1.4g 28288 R 96.7 0.1 2:30.69 http-nio-8080-e |
| 130 | + 53257 yinyu01 20 0 38.0g 1.4g 28288 R 96.3 0.1 2:30.59 http-nio-8080-e |
| 131 | + 53259 yinyu01 20 0 38.0g 1.4g 28288 R 96.3 0.1 2:30.63 http-nio-8080-e |
| 132 | + 53309 yinyu01 20 0 38.0g 1.4g 28288 R 95.3 0.1 2:29.69 http-nio-8080-P |
| 133 | + 53231 yinyu01 20 0 38.0g 1.4g 28288 S 0.3 0.1 0:00.10 VM Thread |
| 134 | + 53262 yinyu01 20 0 38.0g 1.4g 28288 S 0.3 0.1 0:00.12 GC Thread#2 |
| 135 | +``` |
| 136 | + |
| 137 | +It can be observed that **`http-nio-8080-e`** and **`http-nio-8080-P`** threads are CPU-intensive. |
| 138 | +Since the __`http-nio-8080-P`__ thread is fixed at 1 in current version of Tomcat, and the current number of CPU cores is 8, the http-nio-8080-e thread count should be configured to 7. |
| 139 | + |
| 140 | +To configure the `http-nio-8080-e` thread count, use a text editor to modify the `context.xml` file by updating the `<Connector port="8080" protocol="HTTP/1.1"` configuration. |
| 141 | + |
| 142 | +The file is at: |
| 143 | +```bash |
| 144 | +vi ~/apache-tomcat-11.0.9/conf/server.xml |
| 145 | +``` |
| 146 | + |
| 147 | + |
| 148 | +```xml |
| 149 | +<!-- Before --> |
| 150 | + <Connector port="8080" protocol="HTTP/1.1" |
| 151 | + connectionTimeout="20000" |
| 152 | + redirectPort="8443" /> |
| 153 | +``` |
| 154 | + |
| 155 | +```xml |
| 156 | +<!-- After --> |
| 157 | + <Connector port="8080" protocol="HTTP/1.1" |
| 158 | + connectionTimeout="20000" |
| 159 | + redirectPort="8443" |
| 160 | + minSpareThreads="7" |
| 161 | + maxThreads="7" |
| 162 | + maxKeepAliveRequests="500000" |
| 163 | + maxConnections="100000" |
| 164 | + /> |
| 165 | +``` |
| 166 | + |
| 167 | +2. Use the following command on the Grace bare-metal where `Tomcat` is on |
| 168 | +```bash |
| 169 | +~/apache-tomcat-11.0.9/bin/shutdown.sh 2>/dev/null |
| 170 | +ulimit -n 65535 && ~/apache-tomcat-11.0.9/bin/startup.sh |
| 171 | +``` |
| 172 | + |
| 173 | +3. And use the following command on the `x86_64` bare-metal where `wrk2` is on |
| 174 | +```bash |
| 175 | +ulimit -n 65535 && wrk -c1280 -t128 -R500000 -d60 http://${tomcat_ip}:8080/examples/servlets/servlet/HelloWorldExample |
| 176 | +``` |
| 177 | + |
| 178 | +The result of optimal thread count is: |
| 179 | +```bash |
| 180 | + Thread Stats Avg Stdev Max +/- Stdev |
| 181 | + Latency 24.34s 9.91s 41.81s 57.77% |
| 182 | + Req/Sec 1.22k 4.29 1.23k 71.09% |
| 183 | + 9255672 requests in 1.00m, 4.80GB read |
| 184 | +Requests/sec: 154479.07 |
| 185 | +Transfer/sec: 82.06MB |
| 186 | +``` |
0 commit comments