LNMPA的并发连接问题
使用lnmp 可以修改php-fpm里面的max-children 限制php-cgi的并发数目,有效的防止了服务器负载过高卡死。最近使用LNMPA之后,nginx瞬间把N多的php处理事物推给了apache,导致apache的并发数达到了90多个,命令如下
total=0; ii=0; for i in `ps -C httpd -o rss=`; do total=$(($total+$i)); ii=$(($ii+1));echo $ii; echo $i; done; echo "httpdMemory usage: $total kb"
导致服务器负载达到50以上
求教军哥 如何处理这个问题啊。
经测试 LNMPA几乎不出现502错误了,处理php的能力高了不少。 /usr/local/apache/conf/extra/httpd-mpm.conf
<IfModule mpm_prefork_module>
StartServers 5 //启动时生成的进程数
MinSpareServers 5 //最小空闲线程数,用于处理可能到来的突发请求。
MaxSpareServers 10 //最大空闲线程数,用于处理可能到来的突发请求。
MaxClients 150 //客户端最大并发连接数
MaxRequestsPerChild 0 //子进程可处理的请求数,0意味着无限可能会出现内存溢出,建议不要使用0,根据实际情况进行调整。
</IfModule> # prefork MPM
# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare
# MaxSpareServers: maximum number of server processes which are kept spare
# MaxClients: maximum number of server processes allowed to start
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 24
MaxRequestsPerChild 0
</IfModule>
# worker MPM
# StartServers: initial number of server processes to start
# MaxClients: maximum number of simultaneous client connections
# MinSpareThreads: minimum number of worker threads which are kept spare
# MaxSpareThreads: maximum number of worker threads which are kept spare
# ThreadsPerChild: constant number of worker threads in each server process
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_worker_module>
StartServers 2
MaxClients 150
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild1000
</IfModule>
# BeOS MPM
# StartThreads: how many threads do we initially spawn?
# MaxClients: max number of threads we can have (1 thread == 1 client)
# MaxRequestsPerThread: maximum number of requests each thread will process
<IfModule mpm_beos_module>
StartThreads 10
MaxClients 50
MaxRequestsPerThread 10000
</IfModule>
# NetWare MPM
# ThreadStackSize: Stack size allocated for each worker thread
# StartThreads: Number of worker threads launched at server startup
# MinSpareThreads: Minimum number of idle threads, to handle request spikes
# MaxSpareThreads: Maximum number of idle threads
# MaxThreads: Maximum number of worker threads alive at the same time
# MaxRequestsPerChild: Maximumnumber of requests a thread serves. It is
# recommended that the default value of 0 be set for this
# directive on NetWare.This will allow the thread to
# continue to service requests indefinitely.
<IfModule mpm_netware_module>
ThreadStackSize 65536
StartThreads 250
MinSpareThreads 25
MaxSpareThreads 250
MaxThreads 1000
MaxRequestsPerChild 0
MaxMemFree 100
</IfModule>
这么多啊 具体都控制什么呢? prefork模式配置详解
<IfModule mpm_prefork_module>
ServerLimit 256
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 256
MaxRequestsPerChild 0
</IfModule>
ServerLimit
默认的ServerLimit最大是256个线程,如果想设置更大的值,就的加上ServerLimit这个参数。20000是ServerLimit这个参数的最大值。如果需要更大,则必须编译apache,此前都是不需要重新编译Apache。
生效前提:必须放在其他指令的前面
StartServers
指定服务器启动时建立的子进程数量,prefork默认为5。
MinSpareServers
指定空闲子进程的最小数量,默认为5。如果当前空闲子进程数少于MinSpareServers ,那么Apache将以最大每秒一个的速度产生新的子进程。此参数不要设的太大。
MaxSpareServers
设置空闲子进程的最大数量,默认为10。如果当前有超过MaxSpareServers数量的空闲子进程,那么父进程将杀死多余的子进程。此参数不要设的太大。如果你将该指令的值设置为比MinSpareServers小,Apache将会自动将其修改成”MinSpareServers+1″。
MaxClients
限定同一时间客户端最大接入请求的数量(单个进程并发线程数),默认为256。任何超过MaxClients限制的请求都将进入等候队列,一旦一个链接被释放,队列中的请求将得到服务。要增大这个值,你必须同时增大ServerLimit。
MaxRequestsPerChild
每个子进程在其生存期内允许伺服的最大请求数量,默认为10000.到达MaxRequestsPerChild的限制后,子进程将会结束。如果MaxRequestsPerChild为”0″,子进程将永远不会结束。将MaxRequestsPerChild设置成非零值有两个好处:
1.可以防止(偶然的)内存泄漏无限进行,从而耗尽内存。
2.给进程一个有限寿命,从而有助于当服务器负载减轻的时候减少活动进程的数量。 LZ的MaxClients值有没上到1000 标记一下。。。
经常内存耗尽死机,看来这个是个大问题!! 也收藏一下。。。。。。。。。。。 这个不错,的:lol :lol :lol
页:
[1]