TCP connection problems in a large number of state resolved Time_Wait and Close_Wait

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

We take the initiative to call close () is disconnected, the other party to confirm receipt of state to TIME_WAIT. TCP agreement TIME_WAIT status will continue 2MSL (ie twice the maximum lifetime of the segment), in order to ensure that the old connection status will not affect the new connection. Connection resources occupied in the TIME_WAIT state will not be a kernel release, so as a server, where possible, try not to take the initiative to disconnect, to reduce the waste of resources caused by the TIME_WAIT state.
 
So these are not releasable connection certainly takes up a lot of system resources, resulting in timely response to access the site can not be a vicious cycle
 
Solution:
1. modify windows registry, shorten the waiting time of TIME_WAIT
   In the HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ Tcpip \ Parameters, the right to add the name TcpTimedWaitDelay DWORD key, set to 20
 
  

 

 2. Modify configuration apache mpm, increasing the maximum number of concurrent server processing amount
 
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表示不限制请求总数(子进程永不结束)。

  该参数建议设为非零的值,可以带来以下两个好处:

    1. 可以防止程序中可能存在的内存泄漏无限进行下去,从而耗尽内存。
    2. 给进程一个有限寿命,从而有助于当服务器负载减轻的时候减少活动进程的数量。

     注意:在以上涉及到统计请求数量的参数中,对于KeepAlive的连接,只有第一个请求会被计数。

Guess you like

Origin www.cnblogs.com/Mr-10/p/10973854.html