1 准备环境
1.1 环境信息
web Server = www.cmdschool.org
web Client = xxx
1.1 安装压力测试工具
In Web Client
yum install -y httpd-tools
1.2 使用工具测试服务器
In Web Client
ab -c 1000 -n 1000 https://www.cmdschool.org/
如果收到如下错误,
apr_socket_recv: Connection reset by peer (104)
需要在Web端修改如下参数进行临时更改(重启系统后会失效),
sysctl net.ipv4.tcp_syncookies=0 sysctl net.ipv4.tcp_max_syn_backlog=1024
– 第一个参数0关闭防范洪水攻击功能(默认1)
– 第二个参数定义SYN_RECV状态队列的数量(默认512)
另外,如果收到如下错误,
socket: Too many open files (24)
需要在Client端修改如下参数进行临时更改(重启系统后会失效),
ulimit -n 204800
如果收到如下错误,
apr_pollset_poll: The timeout specified has expired (70007)
另外,需要增加ab命令的运行参数,
ab -c 20000 -n 20000 -k https://www.cmdschool.org/
如果收到如下错误,
apr_socket_recv: Connection timed out (110)
需要在Web端修改如下参数进行临时更改(重启系统后会失效),
sysctl net.ipv4.tcp_invalid_ratelimit=0
– 参数控制发送ACK确认报文的最大速率(单位毫秒,0表示关闭控制,默认值500毫秒)
2 错误处理
2.1 错误提示
tail -f /var/log/httpd/*error_log
可见如下错误,
[Thu May 16 08:51:21.382369 2019] [mpm_event:error] [pid 19028:tid 140535511639872] AH03490: scoreboard is full, not at MaxRequestWorkers.Increase ServerLimit. [Thu May 16 08:51:22.383432 2019] [mpm_event:error] [pid 19028:tid 140535511639872] AH03490: scoreboard is full, not at MaxRequestWorkers.Increase ServerLimit. [Thu May 16 08:51:23.384764 2019] [mpm_event:error] [pid 19028:tid 140535511639872] AH03490: scoreboard is full, not at MaxRequestWorkers.Increase ServerLimit. [Thu May 16 08:51:24.385433 2019] [mpm_event:error] [pid 19028:tid 140535511639872] AH00484: server reached MaxRequestWorkers setting, consider raising the MaxRequestWorkers setting
2.2 修改httpd的性能参数
vim /etc/httpd/httpd.conf
定义以下配置,
<IfModule event.c> ServerLimit 16 ThreadsPerChild 25 MaxClients 400 StartServers 3 ThreadLimit 64 #MaxRequestsPerChild 0 // Default value is 0 GracefulShutdownTimeout 5 </IfModule>
注:
– 以上需要根据机器的内存和CPU等资源的情况进行调整
– MaxClients = ServerLimit x ThreadsPerChild(即16*25=400)
– 先调整ServerLimit、ThreadsPerChild、MaxClients三个参数
– 以上三个参数如果达到极限,再调整StartServers参数
2.3 检查配置符合要求
httpd -t
2.4 重启服务使配置生效
systemctl restart httpd
2.5 监视日志
tail -f /var/log/httpd/*error_log
2.6 再次发起压力测试
ab -c 1000 -n 1000 https://www.cmdschool.org/
3 辅助性指令
3.1 查看内存
free -lh
3.2 查看cpu
top -d 1
注:运行命令后按“1”查看多核CPU的负载
3.3 查看内核缓冲区系统控制信息
dmesg
参阅文档:
==================
https://httpd.apache.org/docs/2.4/mod/event.html
https://www.tectut.com/2016/04/workaround-for-scoreboard-is-full-not-at-maxrequestworkers/
https://www.cmdschool.org/archives/1964
没有评论