性能测试对比
测试数据
java-aio
root@ping-Inspiron-3458:~# ab -c1000 -n10000000 http://localhost:8080/
This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient)
Completed 1000000 requests
Completed 2000000 requests
Completed 3000000 requests
Completed 4000000 requests
Completed 5000000 requests
Completed 6000000 requests
Completed 7000000 requests
Completed 8000000 requests
Completed 9000000 requests
Completed 10000000 requests
Finished 10000000 requests
Server Software:
Server Hostname: localhost
Server Port: 8080
Document Path: /
Document Length: 2 bytes
Concurrency Level: 1000
Time taken for tests: 908.218 seconds
Complete requests: 10000000
Failed requests: 0
Total transferred: 800000000 bytes
HTML transferred: 20000000 bytes
Requests per second: 11010.57 [#/sec] (mean)
Time per request: 90.822 [ms] (mean)
Time per request: 0.091 [ms] (mean, across all concurrent requests)
Transfer rate: 860.20 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 45 60.0 42 3095
Processing: 1 46 16.9 46 6842
Waiting: 0 32 16.7 31 6832
Total: 4 91 63.1 88 7882
Percentage of the requests served within a certain time (ms)
50% 88
66% 90
75% 91
80% 92
90% 94
95% 97
98% 103
99% 108
100% 7882 (longest request)
netty-boot
root@ping-Inspiron-3458:~# ab -c1000 -n10000000 http://localhost/im/json
This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient)
Completed 1000000 requests
Completed 2000000 requests
Completed 3000000 requests
Completed 4000000 requests
Completed 5000000 requests
Completed 6000000 requests
Completed 7000000 requests
Completed 8000000 requests
Completed 9000000 requests
Completed 10000000 requests
Finished 10000000 requests
Server Software:
Server Hostname: localhost
Server Port: 80
Document Path: /im/json
Document Length: 43 bytes
Concurrency Level: 1000
Time taken for tests: 1080.087 seconds
Complete requests: 10000000
Failed requests: 0
Total transferred: 1090000000 bytes
HTML transferred: 430000000 bytes
Requests per second: 9258.52 [#/sec] (mean)
Time per request: 108.009 [ms] (mean)
Time per request: 0.108 [ms] (mean, across all concurrent requests)
Transfer rate: 985.53 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 51 7.7 50 206
Processing: 12 57 13.3 55 651
Waiting: 8 42 13.2 40 651
Total: 63 108 12.4 106 674
Percentage of the requests served within a certain time (ms)
50% 106
66% 109
75% 111
80% 113
90% 119
95% 125
98% 134
99% 142
100% 674 (longest request)
tio-boot
root@ping-Inspiron-3458:~# ab -c1000 -n10000000 http://localhost/ok
This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient)
Completed 1000000 requests
Completed 2000000 requests
Completed 3000000 requests
Completed 4000000 requests
Completed 5000000 requests
Completed 6000000 requests
Completed 7000000 requests
Completed 8000000 requests
Completed 9000000 requests
Completed 10000000 requests
Finished 10000000 requests
Server Software: t-io
Server Hostname: localhost
Server Port: 80
Document Path: /ok
Document Length: 43 bytes
Concurrency Level: 1000
Time taken for tests: 1104.650 seconds
Complete requests: 10000000
Failed requests: 0
Total transferred: 1750000000 bytes
HTML transferred: 430000000 bytes
Requests per second: 9052.64 [#/sec] (mean)
Time per request: 110.465 [ms] (mean)
Time per request: 0.110 [ms] (mean, across all concurrent requests)
Transfer rate: 1547.08 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 64 197.9 31 15280
Processing: 1 46 95.3 45 54359
Waiting: 1 35 95.2 33 54350
Total: 1 110 223.0 78 55403
Percentage of the requests served within a certain time (ms)
50% 78
66% 84
75% 88
80% 91
90% 98
95% 107
98% 1087
99% 1104
100% 55403 (longest request)
对比分析
根据提供的测试数据,以下是 Java AIO、Netty、以及 Tio-Boot 三个 Web 中间件在 ApacheBench 压力测试下的性能分析与对比:
1. 基本性能数据
项目 | Java AIO | Netty | Tio-Boot |
---|---|---|---|
请求总数 | 10,000,000 | 10,000,000 | 10,000,000 |
并发数 | 1,000 | 1,000 | 1,000 |
总耗时 (秒) | 908.218 | 1080.087 | 1104.650 |
平均每秒请求数 | 11,010.57 | 9,258.52 | 9,052.64 |
平均每个请求耗时 | 90.822 ms | 108.009 ms | 110.465 ms |
数据传输率 | 860.20 KB/s | 985.53 KB/s | 1547.08 KB/s |
总结:
- Java AIO 在这三者中性能最优,平均每秒请求数最高,且每个请求的平均响应时间最短。
- Netty 和 Tio-Boot 的性能接近,但 Tio-Boot 的请求处理速度稍低,平均每秒请求数略低于 Netty。
- Tio-Boot 的数据传输率最高,可能与返回的内容长度和网络资源调配有关。
2. 请求延迟分析
Java AIO
- 50% 的请求在 88 ms 内完成,95% 的请求在 97 ms 内完成。
- 99% 的请求在 108 ms 内完成,最长请求时间为 7882 ms。
Netty
- 50% 的请求在 106 ms 内完成,95% 的请求在 125 ms 内完成。
- 99% 的请求在 142 ms 内完成,最长请求时间为 674 ms。
Tio-Boot
- 50% 的请求在 78 ms 内完成,95% 的请求在 107 ms 内完成。
- 99% 的请求在 1104 ms 内完成,最长请求时间为 55403 ms。
总结:
- Java AIO 在请求延迟上表现优异,中位数响应时间和 99% 响应时间均较低,整体延迟较小。
- Netty 的延迟相对中等,响应时间也相对均衡。
- Tio-Boot 的延迟有较大波动,虽然大部分请求时间较短,但也出现了少量长时间请求,可能与资源管理或长连接配置有关。
3. 请求处理效率与传输数据量分析
项目 | Java AIO | Netty | Tio-Boot |
---|---|---|---|
HTML 内容长度 | 2 bytes | 43 bytes | 43 bytes |
传输的总数据量 | 800 MB | 1090 MB | 1750 MB |
HTML 传输量 | 20 MB | 430 MB | 430 MB |
总结:
- Java AIO 返回的数据量最小,平均每秒传输量低,但适合处理小数据量的场景。
- Netty 和 Tio-Boot 返回的数据量更大(HTML 内容长度为 43 bytes),Tio-Boot 在传输效率上更高,能更好地处理大数据传输场景。
综合评价
- Java AIO 适用于小数据量、高并发的场景,具有较好的响应延迟和请求处理效率。
- Netty 更适合中等数据量和稳定请求处理需求的场景,延迟较低,数据传输量和效率适中。
- Tio-Boot 尽管在高并发下处理速度稍慢,但在数据传输率和整体吞吐上表现较好,适合对传输量有更高要求的场景。
选择哪个框架应根据具体业务需求来决定。