@
lesismal 我要接的不是 bind 和 listening 的一个 listen fd 连接,而是 accept(listen_fd)出来的几十万个 client_fd 连接。我也无法区分。
另外:试了在每个 socket_fd 同时绑定一个 timer_fd ,文件描述符会膨胀 2 两倍。普通使用没有感觉,但是高并发测试下性能急剧下降。
------------------结帖-----------------
## 之前的奇淫技巧在 TCP 并发数超过 30 万+的时候指针会莫名其妙的跑飞,导致程序卡死无法退出。只能去掉这个。
之中发现百度的服务器也没有进行超时处理,运行:
`nc
www.baidu.com 443`
发现一直不发送数据,连接会一直保持。
## 百度也没处理,我也不处理了,就这样吧。
另外,nginx 也可以加入
```ini
client_body_timeout 5s;
client_header_timeout 5s;
```
来进行连接超时。
使用 ab 测试,发现性能会略微下降
# nginx 未加入超时
```txt
Document Path: /
Document Length: 146 bytes
Concurrency Level: 2000
Time taken for tests: 0.950 seconds
Complete requests: 20000
Failed requests: 14144
(Connect: 0, Receive: 0, Length: 7072, Exceptions: 7072)
Non-2xx responses: 12928
Total transferred: 3736192 bytes
HTML transferred: 1887488 bytes
Requests per second: 21052.99 [#/sec] (mean)
Time per request: 94.998 [ms] (mean)
Time per request: 0.047 [ms] (mean, across all concurrent requests)
Transfer rate: 3840.72 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 40 7.8 40 60
Processing: 16 50 12.4 51 76
Waiting: 0 28 21.4 37 57
Total: 58 90 8.7 90 104
Percentage of the requests served within a certain time (ms)
50% 90
66% 93
75% 97
80% 98
90% 101
95% 103
98% 103
99% 103
100% 104 (longest request)
```
# nginx 加入 timeout 超时
```ini
client_body_timeout 5s;
client_header_timeout 5s;
```
```txt
Document Path: /
Document Length: 146 bytes
Concurrency Level: 2000
Time taken for tests: 0.971 seconds
Complete requests: 20000
Failed requests: 14464
(Connect: 0, Receive: 0, Length: 7232, Exceptions: 7232)
Non-2xx responses: 12768
Total transferred: 3689952 bytes
HTML transferred: 1864128 bytes
Requests per second: 20604.20 [#/sec] (mean)
Time per request: 97.068 [ms] (mean)
Time per request: 0.049 [ms] (mean, across all concurrent requests)
Transfer rate: 3712.33 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 41 8.7 42 71
Processing: 20 51 14.7 51 94
Waiting: 0 29 22.9 38 74
Total: 50 93 11.9 92 120
Percentage of the requests served within a certain time (ms)
50% 92
66% 99
75% 101
80% 102
90% 105
95% 109
98% 119
99% 120
100% 120 (longest request)
```
## 进行多次高并发测试,发现性能都低于。暂时没有探究原因
# 就这样了,不处理了,结帖。谢谢大家的回答