您的位置:首页 > 运维架构

运行ab测试时socket: Too many open files (24)的解决办法

2015-04-22 10:25 651 查看
今天在配置nginx优化时,使用ab测试5000个并发报错,错误内容如下:

<span style="font-size:14px;">[root@localhost bin]# ./ab -n 5000 -c 5000 http://192.168.1.170/index.html This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 192.168.1.170 (be patient)
socket: Too many open files (24)</span>


根据提示,主要原因就是打开的文件太多了嘛。
根据提示,先学两个单词: benchmark :参照  ;be patient :耐心、忍耐。 

所以,基本确定是服务器端打开的文件太多了,超过了限制。google一下:

解决办法:

查看当前允许打开的文件个数:

[root@localhost bin]# ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 61769
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
<strong><span style="color:#ff0000;">open files (-n) 1024</span></strong>
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 61769
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited


调整可以打开的文件数,一调调到20w:
[root@localhost bin]# ulimit -n 204800
不放心,再查看一下:

[root@localhost bin]# ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 61769
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
<strong><span style="color:#ff0000;">open files (-n) 204800</span></strong>
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 61769
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited


重新执行ab测试命令 

[root@localhost bin]# ./ab -n 5000 -c 5000 http://192.168.1.170/index.html This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 192.168.1.170 (be patient)
Completed 500 requests
Completed 1000 requests
Completed 1500 requests
Completed 2000 requests
Completed 2500 requests
Completed 3000 requests
Completed 3500 requests
Completed 4000 requests
Completed 4500 requests
Completed 5000 requests
Finished 5000 requests

Server Software: nginx/1.7.1
Server Hostname: 192.168.1.170
Server Port: 80

Document Path: /index.html
Document Length: 612 bytes

Concurrency Level: 5000
Time taken for tests: 0.190 seconds
Complete requests: 5000
<strong><span style="color:#ff0000;">Failed requests: 0</span></strong>
Write errors: 0
Total transferred: 4295000 bytes
HTML transferred: 3060000 bytes
<strong><span style="color:#ff0000;">Requests per second: 26295.03 [#/sec] (mean)
Time per request: 190.150 [ms] (mean)
Time per request: 0.038 [ms] (mean, across all concurrent requests)</span></strong>
Transfer rate: 22058.04 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 39 50 7.4 49 63
Processing: 38 56 14.2 49 89
Waiting: 31 53 17.1 48 89
Total: 97 106 8.2 103 128

Percentage of the requests served within a certain time (ms)
50% 103
66% 107
75% 110
80% 113
90% 121
95% 124
98% 127
99% 127
100% 128 (longest request)


通过几个指标查看后,发现5k并发真的台太没压力了。因为ab测试最大只允许2w并发,所以,搞2w试试。
[root@localhost bin]# ./ab -n 20000 -c 20000 http://192.168.1.170/index.html This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 192.168.1.170 (be patient)
Completed 2000 requests
Completed 4000 requests
Completed 6000 requests
Completed 8000 requests
Completed 10000 requests
Completed 12000 requests
Completed 14000 requests
Completed 16000 requests
Completed 18000 requests
Completed 20000 requests
Finished 20000 requests

Server Software: nginx/1.7.1
Server Hostname: 192.168.1.170
Server Port: 80

Document Path: /index.html
Document Length: 612 bytes

Concurrency Level: 20000
Time taken for tests: 1.449 seconds
Complete requests: 20000
Failed requests: 0
Write errors: 0
Total transferred: 26971741 bytes
HTML transferred: 19216188 bytes
Requests per second: 13804.93 [#/sec] (mean)
Time per request: 1448.758 [ms] (mean)
Time per request: 0.072 [ms] (mean, across all concurrent requests)
Transfer rate: 18180.81 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 251 307 33.0 304 371
Processing: 286 549 194.9 447 792
Waiting: 153 345 151.3 248 537
Total: 657 856 166.4 752 1087

Percentage of the requests served within a certain time (ms)
50% 752
66% 1037
75% 1051
80% 1067
90% 1077
95% 1080
98% 1081
99% 1083
100% 1087 (longest request)


由于暂时还只是初步了解ab测试后各项指标的意义,并不会分析这些结果,暂时先留空在这里,后面再补充。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  linux ab测试 nginx