Skip to content

性能测试对比 ​

测试数据 ​

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 ​

This is ApacheBench, Version 2.3 <$Revision: 1913912 $>
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/ok
Document Length:        13 bytes

Concurrency Level:      1000
Time taken for tests:   785.573 seconds
Complete requests:      10000000
Failed requests:        0
Total transferred:      510000000 bytes
HTML transferred:       130000000 bytes
Requests per second:    12729.55 [#/sec] (mean)
Time per request:       78.557 [ms] (mean)
Time per request:       0.079 [ms] (mean, across all concurrent requests)
Transfer rate:          633.99 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   37   5.2     37     111
Processing:    12   41   9.6     40     584
Waiting:        7   30   9.3     29     583
Total:         44   79   8.5     77     599

Percentage of the requests served within a certain time (ms)
  50%     77
  66%     79
  75%     81
  80%     82
  90%     85
  95%     88
  98%     92
  99%     95
 100%    599 (longest request)

tio-boot ​

This is ApacheBench, Version 2.3 <$Revision: 1913912 $>
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:        -io
Server Hostname:        localhost
Server Port:            80

Document Path:          /hello
Document Length:        54 bytes

Concurrency Level:      1000
Time taken for tests:   808.676 seconds
Complete requests:      10000000
Failed requests:        0
Total transferred:      1850000000 bytes
HTML transferred:       540000000 bytes
Requests per second:    12365.89 [#/sec] (mean)
Time per request:       80.868 [ms] (mean)
Time per request:       0.081 [ms] (mean, across all concurrent requests)
Transfer rate:          2234.07 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   39   6.6     39     113
Processing:    13   42   7.3     41     306
Waiting:        7   30   7.3     29     278
Total:         48   81   6.1     79     309

Percentage of the requests served within a certain time (ms)
  50%     79
  66%     82
  75%     84
  80%     85
  90%     89
  95%     92
  98%     94
  99%     96
 100%    309 (longest request)

对比分析 ​

根据提供的测试数据,以下是 Java AIO、Netty-Boot 以及 Tio-Boot 三个 Web 中间件在 ApacheBench 压力测试下的性能分析与对比:

1. 基本性能数据 ​

项目Java AIONetty-BootTio-Boot
请求总数10,000,00010,000,00010,000,000
并发数1,0001,0001,000
总耗时 (秒)908.218785.573808.676
平均每秒请求数11,010.5712,729.5512,365.89
平均每个请求耗时90.822 ms78.557 ms80.868 ms
数据传输率860.20 KB/s633.99 KB/s2234.07 KB/s

2. 请求延迟分析 ​

Java AIO ​

  • 50% 的请求在 88 ms 内完成
  • 95% 的请求在 97 ms 内完成
  • 99% 的请求在 108 ms 内完成
  • 最长请求时间:7882 ms

Netty-Boot ​

  • 50% 的请求在 77 ms 内完成
  • 95% 的请求在 88 ms 内完成
  • 99% 的请求在 95 ms 内完成
  • 最长请求时间:599 ms

Tio-Boot ​

  • 50% 的请求在 79 ms 内完成
  • 95% 的请求在 92 ms 内完成
  • 99% 的请求在 96 ms 内完成
  • 最长请求时间:309 ms

3. 请求处理效率与传输数据量分析 ​

项目Java AIONetty-BootTio-Boot
HTML 内容长度2 bytes13 bytes54 bytes
传输的总数据量800 MB510 MB1850 MB
HTML 传输量20 MB130 MB540 MB

总结:

  • Java AIO:虽然总体耗时略长,但平均每个请求的响应时间和延迟指标较低,适用于小数据量、高并发且对延迟较敏感的场景。
  • Netty-Boot:在测试中表现出更高的吞吐量和更低的平均响应时间,适合对响应速度要求较高的应用,但其数据传输率相对较低。
  • Tio-Boot:尽管在平均响应时间上与 Netty-Boot 相近,但其数据传输率显著更高,适合对大数据量传输有较高要求的场景。

选择具体的中间件应根据实际业务需求和应用场景进行综合考量。

MIT Licensed