Use AB and WRK to conduct a stress test on Tencent cloud log service CLS, and take AB and WRK as an example to illustrate
ab
Ab, full name is Apache Benchmark, is the official launch of Apache tool. This tool is used to test the performance of the Apache server. Check the capacity of the installed Apache server to handle requests per second. The following table lists the options commonly used by ab:
options | role |
---|---|
-c | Concurrency: The total number of requests sent at a time. The default is one request at a time. |
-k | Open keep-alive and request multiple times in an HTTP Session. The default is off. |
-n | Number of requests, the number of requests sent during the entire Benchmark test. The default is once, and the performance parameters obtained by default are not representative. |
-t | Maximum time: The maximum time for a benchmark test. There is no default limit. |
-u | This parameter is used when uploading files. You need to set the -t option |
-T | Set the content-type of the uploaded file |
-p | Postfile, specifies the file that contains the post data |
-r | Ab does not exit when a socket error is received |
The installation
apt-get install apache2-utils
Copy the code
Matters needing attention
- Observe that the CPU, memory, and network of the machine where the test tool AB resides and the front-end machine to be tested do not exceed 75% of the maximum limit.
- The test may fail due to insufficient ports
Kernel parameters need to be adjusted to support port reuse. On Linux, add the following content to the /etc/sysctl.conf file
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 30
kernel.printk = 7 4 1 7
Copy the code
Then run sudo sysctl -p to take effect
Use the sample
ab -c 50 -t 60 -n 300000 -k -T 'application/x-protobuf' -p /tmp/post_data.txt -H 'Host: ap-shanghai.cls.myqcloud.com' -H 'Authorization: q-sign-algorithm=sha1&q-ak=AKIDMfonbuXfqpcFicn3YrzwivMelfNwFWcW&q-sign-time=1517472219; 1517493819&q-key-time=1517472219; 1517493819&q-header-list=content-type; host&q-url-param-list=&q-signature=4a4ed6ddc8ba1dfea73d2bee62def9dce8b0ca3c' http://ap-shanghai.cls.myqcloud.com/logCopy the code
/ TMP /post_data. TXT Data is in the Google Protocol buffer format
Results analysis
This is ApacheBench, Version 2.3 <$Revision: 1796539 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, https://www.apache.org/ Benchmarking ap-shanghai.cls.myqcloud.com (be patient) Completed 30000 requests Completed 60000 requests Completed 90000 requests Completed 120000 requests Completed 150000 requests Completed 180000 requests Completed 210000 requests Finished 223877 requests Server Software: openresty Server Hostname: ap-shanghai.cls.myqcloud.com Server Port: 80 Document Path: /log Document Length: 0 bytes Concurrency Level: 50 Time taken for tests: 60.001 seconds Complete requests: 223877 Failed requests: 0 keep-alive requests: 223027 Total transferred: 38726471 bytes Total body sent: 108604595 HTML transferred: 0 bytes Requests per second: 3731.24 [#/ SEC] (mean) Time per request: 13.400 [ms] (mean) Time per request: 0.268 [MS] (mean, across all concurrent requests) Transfer rate: 630.31 [Kbytes/ SEC] Received 1767.63 KB /s sent 2397.94 KB /s Total Connection Times (ms) min Mean [+/-sd] Median Max Connect: 0 0 0.5 0 34 Processing: 9 13 3.8 13 164 Waiting: 8 13 3.8 13 164 Total: 9 13 3.8 13 164 Percentage of the requests served within a certain time (MS) 50% 13 66% 14 75% 14 80% 14 90% 15 95% 17 98% 22 99% 26 100% 164 (longest request)Copy the code
From the test results, we can see that
- In the case of 50 concurrent requests for 60 seconds, an average of 3731 times per second can be processed (i.e., the client sees 3731 QPS under this pressure)
- The average Latency per request is 13.4ms
- With keep-alive enabled, the connection takes almost no time
- 99% of requests are completed in 26ms, with the longest request being 164ms
The test results using Tencent cloud host are as follows
This is ApacheBench, Version 2.3 <$Revision: 1706008 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, https://www.apache.org/ Benchmarking ap-shanghai.cls.myqcloud.com (be patient) Completed 30000 requests Completed 60000 requests Completed 90000 requests Completed 120000 requests Completed 150000 requests Completed 180000 requests Completed 210000 requests Completed 240000 requests Completed 270000 requests Completed 300000 requests Finished 300000 requests Server Software: openresty Server Hostname: ap-shanghai.cls.myqcloud.com Server Port: 80 Document Path: /log Document Length: 0 bytes Concurrency Level: 50 Time taken for tests: 40.095 seconds Complete requests: 300000 Failed requests: 0 Keep-Alive requests: 298850 Total transferred: 51894250 bytes Total body sent: 145500000 HTML transferred: 0 bytes Requests per second: 7482.21 [#/ SEC] (mean) Time per request: 145500000 HTML transferred: 0 Bytes Requests per second: 7482.21 [#/ SEC] (mean) Time per request: 6.683 [MS] (mean) Time per request: 0.134 [MS] (mean, across all concurrent requests) Transfer rate: 1263.94 [Kbytes/ SEC] Received 3543.82 KB /s sent 4807.77 KB /s Total Connection Times (ms) min Mean [+/-sd] Median Max Connect: 0 0 0.1 0 6 Processing: 4 7 2.9 6 157 Waiting: 4 7 2.9 6 157 Total: 4 7 2.9 6 157 Percentage of the requests served within a certain time (ms) 50% 6 66% 7 75% 7 80% 8 90% 9 95% 10 98% 14 99% 18 100% 157 (longest request)Copy the code
From the results, we can see that QPS is 2 times of non-Tencent cloud host, 7482
wrk
WRK is a tool for doing HTTP benchmark testing. Can create significant pressure.
The installation
apt-get install libssl-dev
git clone https://github.com/wg/wrk.git
cd wrk
make
cp wrk /usr/sbin
Copy the code
Use the sample
wrk -c 50 -d 60 -t 5 -s /tmp/wrk_post.lua http://ap-shanghai.cls.myqcloud.com
Copy the code
The request is specified in/TMP /wrk_post.lua with 5 threads, 50 open connections, running for 60 seconds
The content in/TMP /wrk_post.lua is
request = function(a)
mypath = "/tmp/post_data.txt";
local file = io.open(mypath, "r");
assert(file);
local body = file:read("*a"); -- Read everything
file:close(a); wrk.body = bodypath = "/log"
wrk.headers["Content-Type"] = "application/x-protobuf"
wrk.headers["Host"] = "ap-shanghai.cls.myqcloud.com"
wrk.headers["Authorization"] = "q-sign-algorithm=sha1&q-ak=AKIDMfonbuXfqpcFicn3YrzwivMelfNwFWcW&q-sign-time=1517472219; 1517493819&q-key-time=1517472219; 1517493819&q-header-list=content-type; host&q-url-param-list=&q-signature=4a4ed6ddc8ba1dfea73d2bee62def9dce8b0ca3c"
return wrk.format("POST".path)
end
Copy the code
Results analysis
Running 1m test @ http://ap-shanghai.cls.myqcloud.com 5 threads and 50 connections Thread Stats Avg Stdev Max +/- Stdev Latency 15.91 ms 25.52 ms 880.85 ms 98.05% the Req 221561 requests/Sec 745.32 105.11 848.00 94.79% in 1.00 m, 36.55MB Read Requests/ SEC: 3688.17 Transfer/ SEC: 623.03KBCopy the code
From the test results, we can see that
- In the case of 5 concurrent requests, 50 connections opened for 60 seconds can process 3688 times per second on average (that is, the client sees 3688 QPS under this pressure)
- The average Latency per request is 15.91ms
The test results using Tencent cloud host are as follows
Running 1m test @ http://ap-shanghai.cls.myqcloud.com 5 threads and 50 connections Thread Stats Avg Stdev Max +/- Stdev Requests in 1.11m for 1.11m Req/Sec 11.11k 11.11k 79.27%457574 requests in 1.11m, 75.48MB Read Requests/ SEC: 7623.03 Transfer/ SEC: 1.26MBCopy the code
As can be seen from the results, QPS is 7623 times that of non-Tencent cloud hosts
conclusion
This is to use the open source Benchmark tool to measure QPS and Latency from a client perspective. However, the performance seen from the client can be affected by various factors, such as the mode of request, native resources (CPU, memory, network), CLS network state, CLS load, etc. Depending on the situation, you need to see whether the performance bottleneck is from CLS or native.
Reference:
- Benchmark OSS using AB and WRK
Please give me a thumbs up!
Carefully organized the computer from all directions from the entry, advanced, actual combat video courses and e-books, according to the catalog reasonable classification, always can find you need to learn information, what are still waiting for? Go to download!!
Can’t forget, there will be echoes, friends to help me like it, thank you very much.
I am a senior software engineer of YY with four years of work experience. I refuse to be a slashes programmer.
Listen to me. It’s a lot of progress
If lucky enough to be able to help you, please help me [like], give a attention, if you can along with comments to encourage, will be very grateful.
List of articles: More
All my articles, answers and copyright protection platform cooperation, copyright belongs to the workplace Liangge all, unauthorized, reproduced will investigate!