Today, the company opened a special website suddenly slow, the situation is not open sometimes appear, began to suspect a network problem, but the network investigation did not reveal any abnormalities, finally decided to issue an internal investigation at the site server
Middleware is the site with apache, listening on port 7080, first look at the case of listening 7080 port
It found that there was a large number of connections in the TIME_WAIT state and CLOSE_WAIT
CLOSE_WAIT
The other party take the initiative to close the connection or the network connection is lost resulting in abnormal, then we will become a state CLOSE_WAIT At this point we want to call close () to make the connection correctly closed
TIME_WAIT
The default MPM modules on different operating systems | ||
---|---|---|
operating system | MPM module | description |
Windows | mpm_winnt | Not have introduced it :) |
Unix/Linux | mpm_prefork | Not have introduced it :) |
BeOS | mpm_beos | From a multimedia operating system developed by Be, the official version has stopped updating. |
Netware | mpm_netware | NOVELL a company launched by the network operating system |
OS / 2 | mpmt_os2 | 一种最初由微软和IBM共同开发的操作系统,现由IBM单独开发(微软放弃OS/2,转而开发Windows) |
mpm_winnt
模块是专门针对Windows操作系统而优化设计的MPM模块。它只创建一个单独的子进程,并在这个子进程中轮流产生多个线程来处理请求。
(1)由于apache默认状态下mpm模块的代码是注释的,所以需要先修改apche核心配置
修改为
# Server-pool management (MPM specific)
Include conf/extra/httpd-mpm.conf
(2)修改httpd-mpm.conf
<IfModule mpm_winnt_module>
ThreadsPerChild 150 #推荐设置:小型网站=1000 中型网站=1000~2000 大型网站=2000~3500
MaxRequestsPerChild 0 #推荐设置:小=10000 中或大=20000~100000
<IfModule>
对应的配置参数作用如下:
- ThreadsPerChild
- 每个子进程的最大并发线程数。
- MaxRequestsPerChild
-
每个子进程允许处理的请求总数。如果累计处理的请求数超过该值,该子进程将会结束(然后根据需要确定是否创建新的子进程),该值设为0表示不限制请求总数(子进程永不结束)。
该参数建议设为非零的值,可以带来以下两个好处:
-
- 可以防止程序中可能存在的内存泄漏无限进行下去,从而耗尽内存。
- 给进程一个有限寿命,从而有助于当服务器负载减轻的时候减少活动进程的数量。
-
注意:在以上涉及到统计请求数量的参数中,对于KeepAlive的连接,只有第一个请求会被计数。