笺注:这是在 CentOS8安装LAMP+phpMyAdmin 的基础上进行的。
查看Apache的版本:
[root@centos8 ~]# httpd -v
Server version: Apache/2.4.37 (centos)
Server built: Jun 8 2020 20:14:33
查看Apache现在使用的MPM模式:
[root@centos8 ~]# httpd -V
Server version: Apache/2.4.37 (centos)
Server built: Jun 8 2020 20:14:33
Server's Module Magic Number: 20120211:83
Server loaded: APR 1.6.3, APR-UTIL 1.6.1
Compiled using: APR 1.6.3, APR-UTIL 1.6.1
Architecture: 64-bit
Server MPM: event
threaded: yes (fixed thread count)
forked: yes (variable process count)
Server compiled with....
-D APR_HAS_SENDFILE
-D APR_HAS_MMAP
-D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
-D APR_USE_SYSVSEM_SERIALIZE
-D APR_USE_PTHREAD_SERIALIZE
-D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
-D APR_HAS_OTHER_CHILD
-D AP_HAVE_RELIABLE_PIPED_LOGS
-D DYNAMIC_MODULE_LIMIT=256
-D HTTPD_ROOT="/etc/httpd"
-D SUEXEC_BIN="/usr/sbin/suexec"
-D DEFAULT_PIDLOG="run/httpd.pid"
-D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
-D DEFAULT_ERRORLOG="logs/error_log"
-D AP_TYPES_CONFIG_FILE="conf/mime.types"
-D SERVER_CONFIG_FILE="conf/httpd.conf"
笺注:Apache2.4有三种稳定的MPM(Multi-Processing Module,多进程处理模块)模式,分别是prefork、worker、event。
event是通过线程来处理请求,一个父进程建立多个子进程,而子进程又会建立多个线程;对高并发的支持较好;
创建PHP测试页:
[root@centos8 ~]# cat /var/www/html/phpinfo.php
<?php
phpinfo();
?>
[root@centos8 ~]# ab -n 1000 -c 300 http://192.168.168.154/phpinfo.php #指定并发请求数为300,总请求数为1000,对http://192.168.168.154/phpinfo.php进行压力测试
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 192.168.168.154 (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: Apache/2.4.37
Server Hostname: 192.168.168.154
Server Port: 80
Document Path: /phpinfo.php
Document Length: 82221 bytes
Concurrency Level: 300
Time taken for tests: 3.014 seconds
Complete requests: 1000
Failed requests: 343
(Connect: 0, Receive: 0, Length: 343, Exceptions: 0)
Total transferred: 82409626 bytes
HTML transferred: 82236626 bytes
Requests per second: 331.75 [#/sec] (mean)
Time per request: 904.300 [ms] (mean)
Time per request: 3.014 [ms] (mean, across all concurrent requests)
Transfer rate: 26698.48 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 103 84.8 93 1144
Processing: 52 681 586.6 452 2964
Waiting: 6 569 504.8 428 2338
Total: 52 784 549.4 578 2982
Percentage of the requests served within a certain time (ms)
50% 578
66% 807
75% 953
80% 986
90% 1181
95% 2359
98% 2360
99% 2737
100% 2982 (longest request)
笺注:可以看到每秒最大处理请求次数为331.75次,每个请求响应时间是3.014毫秒。
加大并发请求数、总请求数进行测试:
#指定并发请求数为3800,总请求数为4000
[root@centos8 ~]# ab -n 4000 -c 3800 http://192.168.168.154/phpinfo.php
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 192.168.168.154 (be patient)
socket: Too many open files (24)
操作系统的“进程最大可打开文件数”的查询方法:
[root@centos8 ~]# ulimit -n
1024
操作系统的“进程最大可打开文件数”的修改方法:
[root@centos8 ~]# tail -5 /etc/security/limits.conf
# End of file
* soft nproc 65535
* hard nproc 65535
* soft nofile 65535
* hard nofile 65535
重启服务器:
[root@centos8 ~]# reboot
服务器重启后,更改生效:
[root@centos8 ~]# ulimit -n
65535
加大并发请求数、总请求数进行测试:
#指定并发请求数为3800,总请求数为4000
[root@centos8 ~]# ab -n 4000 -c 3800 http://192.168.168.154/phpinfo.php
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 192.168.168.154 (be patient)
Completed 400 requests
Completed 800 requests
Completed 1200 requests
Completed 1600 requests
Completed 2000 requests
Completed 2400 requests
Completed 2800 requests
Completed 3200 requests
Completed 3600 requests
Completed 4000 requests
Finished 4000 requests
Server Software: Apache/2.4.37
Server Hostname: 192.168.168.154
Server Port: 80
Document Path: /phpinfo.php
Document Length: 82221 bytes
Concurrency Level: 3800
Time taken for tests: 33.754 seconds
Complete requests: 4000
Failed requests: 402
(Connect: 0, Receive: 0, Length: 402, Exceptions: 0)
Total transferred: 329208095 bytes
HTML transferred: 328516095 bytes
Requests per second: 118.51 [#/sec] (mean)
Time per request: 32065.873 [ms] (mean)
Time per request: 8.438 [ms] (mean, across all concurrent requests)
Transfer rate: 9524.70 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 654 1291.5 269 8032
Processing: 110 4286 6050.1 1557 33242
Waiting: 36 2288 4442.6 425 23205
Total: 138 4940 6265.9 1796 33658
Percentage of the requests served within a certain time (ms)
50% 1796
66% 4075
75% 6798
80% 9241
90% 14094
95% 18524
98% 23156
99% 26691
100% 33658 (longest request)
笺注:可以看到每秒最大处理请求次数为118.51次,每个请求响应时间是8.438毫秒。
相关文章:
Apache2.4的MPM模式(event/prefork) |