Too many open files
Centos7.5 提示Too many open files
进行压力测试的时候提示Too many open files
[root@web01 code]# ab -n100000 -c200 http://127.0.0.1/tt.html This is ApacheBench, Version 2.3 <$Revision: 1430300 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 127.0.0.1 (be patient) socket: Too many open files (24)
产生的原因:文件句柄(文件描述符)不够
解决方法:
方式一:临时修改
[root@nginx ~]# ulimit -n 2048
方式二:永久修改
[root@nginx ~]# vim /etc/security/limits.conf #永久修改
#方式一 系统全局性修改
# *代表所有用户,soft仅提醒,hard限制,nofile打开最大文件数
* soft nofile 25535 #所有用户运行的进程打开最大的文件数为25535,达到这个限制后会提醒
* hard nofile 25535 #所有用户运行的进程打开最大的文件数为25535,达到这个限制后会限制打开
#方式二 用户局部性修改
#针对root用户,soft仅提醒,hard限制,nofile打开最大文件数
root soft nofile 65535 #root用户运行的进程打开最大的文件数为65535,达到这个限制后会提醒
root hard nofile 65535 #root用户运行的进程打开最大的文件数为65535,达到这个限制后会限制打开
#重启生效
#查看是否生效
[root@web01 ~]# ulimit -a
[root@web01 ~]# ulimit -n
#方式三
针对Nginx进程
[root@web01 code]# vim /etc/nginx/nginx.conf
user nginx;
worker_processes 1;
worker_rlimit_nofile 65535;
...
[root@web01 code]# nginx -t
[root@web01 code]# systemctl restart nginx
示例:
方式一:临时修改
[root@web01 ROOT]# ab -n100000 -c200 http://127.0.0.1/tt.html This is ApacheBench, Version 2.3 <$Revision: 1430300 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 127.0.0.1 (be patient) socket: Too many open files (24) [root@web01 ROOT]# ulimit -n 300 #临时修改 [root@web01 ROOT]# ab -n100000 -c200 http://127.0.0.1/tt.html This is ApacheBench, Version 2.3 <$Revision: 1430300 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 127.0.0.1 (be patient) Completed 10000 requests Completed 20000 requests Completed 30000 requests Completed 40000 requests Completed 50000 requests Completed 60000 requests Completed 70000 requests Completed 80000 requests Completed 90000 requests Completed 100000 requests Finished 100000 requests Server Software: nginx/1.14.2 Server Hostname: 127.0.0.1 Server Port: 80 Document Path: /tt.html Document Length: 10 bytes Concurrency Level: 200 Time taken for tests: 26.754 seconds Complete requests: 100000 Failed requests: 0 Write errors: 0 Total transferred: 24600000 bytes HTML transferred: 1000000 bytes Requests per second: 3737.73 [#/sec] (mean) Time per request: 53.508 [ms] (mean) Time per request: 0.268 [ms] (mean, across all concurrent requests) Transfer rate: 897.93 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 4 50.4 1 1008 Processing: 10 48 99.3 35 3049 Waiting: 5 46 99.4 34 3048 Total: 10 52 112.6 37 3050 Percentage of the requests served within a certain time (ms) 50% 37 66% 42 75% 45 80% 46 90% 54 95% 69 98% 126 99% 1030 100% 3050 (longest request)
方式二:永久修改
[root@web01 ~]# ab -n100000 -c300 http://127.0.0.1/tt.html This is ApacheBench, Version 2.3 <$Revision: 1430300 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 127.0.0.1 (be patient) socket: Too many open files (24) [root@web01 ~]# vim /etc/security/limits.conf * soft nofile 400 [root@web01 ~]# reboot [root@web01 ~]# ab -n100000 -c300 http://127.0.0.1/tt.html This is ApacheBench, Version 2.3 <$Revision: 1430300 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 127.0.0.1 (be patient) Completed 10000 requests Completed 20000 requests Completed 30000 requests Completed 40000 requests Completed 50000 requests Completed 60000 requests Completed 70000 requests Completed 80000 requests Completed 90000 requests Completed 100000 requests Finished 100000 requests Server Software: nginx/1.14.2 Server Hostname: 127.0.0.1 Server Port: 80 Document Path: /tt.html Document Length: 173 bytes Concurrency Level: 300 Time taken for tests: 8.985 seconds Complete requests: 100000 Failed requests: 0 Write errors: 0 Non-2xx responses: 100000 Total transferred: 32500000 bytes HTML transferred: 17300000 bytes Requests per second: 11129.77 [#/sec] (mean) Time per request: 26.955 [ms] (mean) Time per request: 0.090 [ms] (mean, across all concurrent requests) Transfer rate: 3532.40 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 15 131.5 2 3012 Processing: 1 10 10.1 9 613 Waiting: 1 8 10.0 8 610 Total: 3 25 133.7 11 3026 Percentage of the requests served within a certain time (ms) 50% 11 66% 12 75% 12 80% 12 90% 13 95% 14 98% 17 99% 1019 100% 3026 (longest request)