阅读本文需要读者至少有C/C++
网络编程基础, 并且了解基本的Socket API
是如何使用的.
同时需要读者至少使用过cfadmin
框架、并且能熟练使用内置库来完成简单的业务逻辑编写.
对本文有兴趣的同学也可以从官网与文档来了解更多关于框架的更多使用方法.
测试准备
1. 硬件清单
名称 | 型号 | 内容 | 数值 |
---|---|---|---|
CPU | Intel | I5-10400 | 6核12线程 |
MEM | Micron | DDR4-2666 | 16G |
OS | WSL | Linux | Kernel 5.4 |
SCRIPT | Lua | Lua 5.4.3 | 分代GC |
2. 启动方式
-
-w
启动多进程,auto
让框架自动判断启动的进程数量. -
注释所有
server.lua
的调试代码, 消除影响可能存在的影响.
3. 操作系统
本文所有测试都是在WSL2 - Debain
下完成.
root@server:~/cfadmin$ uname -a
Linux 5.4.72-microsoft-standard-WSL2 #1 SMP Wed Oct 28 23:40:43 UTC 2020 x86_64 GNU/Linux
所有测试均为命令行实测, 出
开始测试
选择多个不同类型的软件来对数值进行评估, 得出的参考值将会接近大家的心里预期.
注意: 数值并不可比较实际生产环境数值, 对于这一点请大家理性对待.
1. wrk
测试内容: 分别尝试开启4个线程后的10
秒内在启动500
、1000
、2000
长连接下的不同表现.
root@server:~/cfadmin$ wrk -t4 -c500 -d10s http://localhost:8080/view
Running 10s test @ http://localhost:8080/view
4 threads and 500 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 2.01ms 2.47ms 38.22ms 89.75%
Req/Sec 49.39k 8.21k 68.27k 70.18%
1978125 requests in 10.09s, 243.36MB read
Requests/sec: 195982.55
Transfer/sec: 24.11MB
root@server:~/cfadmin$ wrk -t4 -c1000 -d10s http://localhost:8080/view
Running 10s test @ http://localhost:8080/view
4 threads and 1000 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 4.09ms 4.03ms 41.24ms 89.03%
Req/Sec 41.40k 7.20k 63.97k 67.68%
1658362 requests in 10.10s, 204.02MB read
Requests/sec: 164252.30
Transfer/sec: 20.21MB
root@server:~/cfadmin$ wrk -t4 -c2000 -d10s http://localhost:8080/view
Running 10s test @ http://localhost:8080/view
4 threads and 2000 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 9.19ms 7.30ms 62.57ms 84.56%
Req/Sec 35.65k 5.30k 53.27k 70.10%
1417799 requests in 10.04s, 174.42MB read
Requests/sec: 141234.26
Transfer/sec: 17.38MB
2. Apache Benchmark
测试的内容: 总共发送100万次请求, 分别测试在500
、1000
、2000
长连接下的表现.
root@server:~/cfadmin$ ab -c 500 -n 1000000 -k http://localhost:8080/view
Concurrency Level: 500
Time taken for tests: 11.278 seconds
Complete requests: 1000000
Failed requests: 0
Keep-Alive requests: 1000000
Total transferred: 129000000 bytes
HTML transferred: 12000000 bytes
Requests per second: 88670.45 [#/sec] (mean)
Time per request: 5.639 [ms] (mean)
Time per request: 0.011 [ms] (mean, across all concurrent requests)
Transfer rate: 11170.40 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.2 0 14
Processing: 1 6 2.7 5 36
Waiting: 0 6 2.7 5 36
Total: 1 6 2.8 5 36
Percentage of the requests served within a certain time (ms)
50% 5
66% 6
75% 6
80% 7
90% 8
95% 10
98% 12
99% 18
100% 36 (longest request)
root@server:~/cfadmin$ ab -c 1000 -n 1000000 -k http://localhost:8080/view
Concurrency Level: 1000
Time taken for tests: 12.305 seconds
Complete requests: 1000000
Failed requests: 0
Keep-Alive requests: 1000000
Total transferred: 129000000 bytes
HTML transferred: 12000000 bytes
Requests per second: 81265.18 [#/sec] (mean)
Time per request: 12.305 [ms] (mean)
Time per request: 0.012 [ms] (mean, across all concurrent requests)
Transfer rate: 10237.51 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.7 0 29
Processing: 2 12 5.4 11 66
Waiting: 0 12 5.4 11 66
Total: 2 12 5.5 11 66
Percentage of the requests served within a certain time (ms)
50% 11
6