ApacheBench 简单测试网络性能,Listening TCP Socket 需要优化

测试方式

http_server 设置backlog为3,分别测试 3 并发访问和 4 并发访问,1000次request,对比如下:

比较

DragonOS

三并发成功,但有request处理的特别慢

ab -n 1000 -c 3 http://localhost:12580/

# ...

Document Path:          /
Document Length:        75 bytes

Concurrency Level:      3
Time taken for tests:   10.020 seconds
Complete requests:      1000
Failed requests:        0
Non-2xx responses:      1000
Total transferred:      123000 bytes
HTML transferred:       75000 bytes
Requests per second:    99.80 [#/sec] (mean)
Time per request:       30.061 [ms] (mean)
Time per request:       10.020 [ms] (mean, across all concurrent requests)
Transfer rate:          11.99 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:     6   30 446.9     11   10012
Waiting:        6   30 446.8     11   10012
Total:          6   30 446.9     11   10012

Percentage of the requests served within a certain time (ms)
  50%     11
  66%     12
  75%     12
  80%     12
  90%     12
  95%     12
  98%     12
  99%     13
 100%  10012 (longest request)

四并发失败

ab -n 1000 -c 4 http://localhost:12580/
# Output:
This is ApacheBench, Version 2.3 <$Revision: 1903618 $>
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 100 requests
apr_socket_recv: Connection reset by peer (104)
Total of 102 requests completed

Linux

任何情况都很快,所有request都在1ms以内处理完毕。

ab -n 1000 -c 4 http://localhost:12581/
# Output
This is ApacheBench, Version 2.3 <$Revision: 1903618 $>
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 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:        
Server Hostname:        localhost
Server Port:            12581

Document Path:          /
Document Length:        75 bytes

Concurrency Level:      4
Time taken for tests:   0.051 seconds
Complete requests:      1000
Failed requests:        0
Non-2xx responses:      1000
Total transferred:      123000 bytes
HTML transferred:       75000 bytes
Requests per second:    19471.54 [#/sec] (mean)
Time per request:       0.205 [ms] (mean)
Time per request:       0.051 [ms] (mean, across all concurrent requests)
Transfer rate:          2338.87 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:     0    0   0.1      0       1
Waiting:        0    0   0.1      0       1
Total:          0    0   0.1      0       1

Percentage of the requests served within a certain time (ms)
  50%      0
  66%      0
  75%      0
  80%      0
  90%      0
  95%      0
  98%      0
  99%      1
 100%      1 (longest request)