哪个php5-fpm设置为高并发连接数nginx

前端之家收集整理的这篇文章主要介绍了哪个php5-fpm设置为高并发连接数nginx前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
请帮我调整PHP5-fpm和Nginx的配置.

问题是我的PHP5-fpm日志不断报告慢脚本并杀死子线程.

专用服务器,quad xeon,32Gb Ram. 1个PHP应用程序/站点运行.

PHP应用程序:Nutshell,搜索引擎,结果触发curl请求.每次搜索页面加载时间通常为2-3秒.

这就是我认为正在发生的事情
我有750个并发的PHP用户执行搜索.由于RAM限制,我只能设置pm.max_children = 400.我假设每个用户50Mb(子线程),所以= 20GB.我假设每个用户= 1个子线程.因此,pm.max_children不足以覆盖那些需要3秒钟进行搜索的750个活跃PHP用户.

所以我认为我看到用户排队,因为我看到3秒变成4-7秒.由于用户排队我认为脚本越来越慢触发错误日志消息而PHP5-fpm pm会杀死孩子?

这就是我认为正在发生的事情.我在下面提供了我的错误日志输出,Nginx,PHP5-fpm配置.

我真的很感激任何关于我是否可以调整我的配置的建议,如果确实pm.max_children应该至少等于你的最大并发用户,请记住我的PHP搜索打开大约3秒钟.我需要更多内存还是其他服务器?

这是我的记忆,但我只在大约30分钟前重新启动了Nginx

:/var/log# free -m
             total       used       free     shared    buffers     cached
Mem:         32151      26175       5975          0        186      13334
-/+ buffers/cache:      12654      19496
Swap:        32739          5      32734

PHP5-fpm:www.conf:
进程管理器设置为静态

我正在使用静态,因为我认为所有的孩子都可以立即使用,而不是产生时间,我只在盒子上运行1个应用程序.

;pm = dynamic
pm = static

;pm.max_children = 10
pm.max_children = 400


;pm.start_servers = 4
pm.start_servers = 150


;pm.min_spare_servers = 2
pm.min_spare_servers = 32


;pm.max_spare_servers = 6
pm.max_spare_servers = 64


;pm.max_requests = 500
pm.max_requests = 10000

PHP5-fpm日志中的错误

我应该澄清,我在高负载下看到的行为,一次有750个用户是缓存的搜索结果而不是缓存开始需要更长的时间.即>缓存为1秒,非缓存为4到7秒.因此,当用户排队等待时,我认为搜索时间会增加,并且它会在负载下缓慢运行到脚本运行缓慢的程度.触发通知,孩子被杀.

例如刚刚重启之后

[04-Jun-2013 20:11:07] NOTICE: Finishing ...
[04-Jun-2013 20:11:11] NOTICE: exiting,bye-bye!
[04-Jun-2013 20:11:12] NOTICE: fpm is running,pid 17899
[04-Jun-2013 20:11:12] NOTICE: ready to handle connections
[04-Jun-2013 20:27:28] WARNING: [pool www] child 18200,script '/home/site/public_html/index.PHP' (request: "POST /index.PHP") executing too slow (10.827363 sec),logging
[04-Jun-2013 20:27:28] WARNING: [pool www] child 18138,script '/home/site/public_html/index.PHP' (request: "POST /index.PHP") executing too slow (10.827034 sec),logging
[04-Jun-2013 20:27:28] NOTICE: child 18138 stopped for tracing
[04-Jun-2013 20:27:28] NOTICE: about to trace 18138
[04-Jun-2013 20:27:28] NOTICE: finished trace of 18138
[04-Jun-2013 20:27:28] NOTICE: child 18200 stopped for tracing
[04-Jun-2013 20:27:28] NOTICE: about to trace 18200
[04-Jun-2013 20:27:28] NOTICE: finished trace of 18200
[04-Jun-2013 20:52:52] WARNING: [pool www] child 17948,script '/home/site/public_html/index.PHP' (request: "GET /index.PHP") executing too slow (11.724081 sec),logging
[04-Jun-2013 20:52:52] NOTICE: child 17948 stopped for tracing
[04-Jun-2013 20:52:52] NOTICE: about to trace 17948
[04-Jun-2013 20:52:52] ERROR: Failed to ptrace(PEEKDATA) pid 17948: Input/output error (5)
[04-Jun-2013 20:52:52] NOTICE: finished trace of 17948
[04-Jun-2013 20:58:22] WARNING: [pool www] child 18287,script '/home/site/public_html/index.PHP' (request: "POST /index.PHP") executing too slow (10.701504 sec),logging
[04-Jun-2013 20:58:22] NOTICE: child 18287 stopped for tracing
[04-Jun-2013 20:58:22] NOTICE: about to trace 18287
[04-Jun-2013 20:58:22] NOTICE: finished trace of 18287
[04-Jun-2013 21:19:22] WARNING: [pool www] child 18224,script '/home/site/public_html/index.PHP' (request: "GET /index.PHP") executing too slow (10.005466 sec),logging
[04-Jun-2013 21:19:22] WARNING: [pool www] child 18197,script '/home/site/public_html/index.PHP' (request: "GET /index.PHP") executing too slow (12.141221 sec),logging
[04-Jun-2013 21:19:22] WARNING: [pool www] child 17946,script '/home/site/public_html/index.PHP' (request: "GET /index.PHP") executing too slow (11.107080 sec),logging
[04-Jun-2013 21:19:22] NOTICE: child 17946 stopped for tracing
[04-Jun-2013 21:19:22] NOTICE: about to trace 17946
[04-Jun-2013 21:19:22] NOTICE: finished trace of 17946
[04-Jun-2013 21:19:22] NOTICE: child 18197 stopped for tracing
[04-Jun-2013 21:19:22] NOTICE: about to trace 18197
[04-Jun-2013 21:19:22] NOTICE: finished trace of 18197
[04-Jun-2013 21:19:22] NOTICE: child 18224 stopped for tracing
[04-Jun-2013 21:19:22] NOTICE: about to trace 18224
[04-Jun-2013 21:19:22] NOTICE: finished trace of 18224
[04-Jun-2013 21:19:26] WARNING: [pool www] child 18197,script '/home/site/public_html/index.PHP' (request: "GET /index.PHP") execution timed out (15.475021 sec),terminating
[04-Jun-2013 21:19:26] WARNING: [pool www] child 18055,script '/home/site/public_html/index.PHP' (request: "GET /index.PHP") executing too slow (12.927407 sec),logging
[04-Jun-2013 21:19:26] NOTICE: child 18055 stopped for tracing
[04-Jun-2013 21:19:26] NOTICE: about to trace 18055
[04-Jun-2013 21:19:26] NOTICE: finished trace of 18055
[04-Jun-2013 21:19:26] WARNING: [pool www] child 18197 exited on signal 15 (SIGTERM) after 4094.193190 seconds from start
[04-Jun-2013 21:19:26] NOTICE: [pool www] child 5137 started
[04-Jun-2013 21:24:49] WARNING: [pool www] child 17918,script '/home/site/public_html/index.PHP' (request: "GET /index.PHP") executing too slow (11.367854 sec),logging
[04-Jun-2013 21:24:49] NOTICE: child 17918 stopped for tracing
[04-Jun-2013 21:24:49] NOTICE: about to trace 17918
[04-Jun-2013 21:24:49] NOTICE: finished trace of 17918
[04-Jun-2013 21:24:53] WARNING: [pool www] child 18226,script '/home/site/public_html/index.PHP' (request: "GET /index.PHP") executing too slow (10.763667 sec),logging
[04-Jun-2013 21:24:53] WARNING: [pool www] child 18206,script '/home/site/public_html/index.PHP' (request: "GET /index.PHP") executing too slow (12.060464 sec),logging
[04-Jun-2013 21:24:53] WARNING: [pool www] child 18073,script '/home/site/public_html/index.PHP' (request: "GET /index.PHP") executing too slow (11.846097 sec),logging
[04-Jun-2013 21:24:53] NOTICE: child 18073 stopped for tracing
[04-Jun-2013 21:24:53] NOTICE: about to trace 18073
[04-Jun-2013 21:24:53] NOTICE: finished trace of 18073
[04-Jun-2013 21:24:53] NOTICE: child 18206 stopped for tracing
[04-Jun-2013 21:24:53] NOTICE: about to trace 18206
[04-Jun-2013 21:24:53] NOTICE: finished trace of 18206
[04-Jun-2013 21:24:53] NOTICE: child 18226 stopped for tracing
[04-Jun-2013 21:24:53] NOTICE: about to trace 18226
[04-Jun-2013 21:24:53] NOTICE: finished trace of 18226
[04-Jun-2013 21:24:56] WARNING: [pool www] child 5137,script '/home/site/public_html/index.PHP' (request: "GET /index.PHP") executing too slow (12.055624 sec),logging
[04-Jun-2013 21:24:56] WARNING: [pool www] child 18206,script '/home/site/public_html/index.PHP' (request: "GET /index.PHP") execution timed out (15.395149 sec),terminating
[04-Jun-2013 21:24:56] WARNING: [pool www] child 17996,script '/home/site/public_html/index.PHP' (request: "GET /index.PHP") executing too slow (12.145728 sec),logging
[04-Jun-2013 21:24:56] WARNING: [pool www] child 17918,script '/home/site/public_html/index.PHP' (request: "GET /index.PHP") execution timed out (18.036700 sec),terminating
[04-Jun-2013 21:24:56] NOTICE: child 17996 stopped for tracing
[04-Jun-2013 21:24:56] NOTICE: about to trace 17996
[04-Jun-2013 21:24:56] NOTICE: finished trace of 17996
[04-Jun-2013 21:24:56] NOTICE: child 5137 stopped for tracing
[04-Jun-2013 21:24:56] NOTICE: about to trace 5137
[04-Jun-2013 21:24:56] NOTICE: finished trace of 5137
[04-Jun-2013 21:24:56] WARNING: [pool www] child 17918 exited on signal 15 (SIGTERM) after 4424.343036 seconds from start
[04-Jun-2013 21:24:56] NOTICE: [pool www] child 6706 started
[04-Jun-2013 21:24:56] WARNING: [pool www] child 18206 exited on signal 15 (SIGTERM) after 4424.264130 seconds from start
[04-Jun-2013 21:24:56] NOTICE: [pool www] child 6707 started
[04-Jun-2013 21:24:59] WARNING: [pool www] child 17996,script '/home/site/public_html/index.PHP' (request: "GET /index.PHP") execution timed out (15.479201 sec),terminating
[04-Jun-2013 21:24:59] WARNING: [pool www] child 17996 exited on signal 15 (SIGTERM) after 4427.655572 seconds from start
[04-Jun-2013 21:24:59] NOTICE: [pool www] child 6708 started

这是我的Nginx配置

user www-data;
worker_processes 4;
pid /var/run/Nginx.pid;
worker_rlimit_nofile 20000;

events {
    #worker_connections 768;
    #worker_connections 19000;

    #multi_accept on;
    use epoll;
    #worker_connections 10240;  
    worker_connections 4096;
}


http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    #keepalive_timeout 65;
    #keepalive_timeout 5;

#added
    client_body_timeout   15;
    client_header_timeout 15;
    keepalive_timeout     15;
    send_timeout          15;

site.conf

proxy_buffer_size   128k;
    proxy_buffers   4 256k;
    proxy_busy_buffers_size   256k;

    fastcgi_connect_timeout 60;
    fastcgi_send_timeout 180;
    fastcgi_read_timeout 180;
    fastcgi_buffer_size 128k;
    fastcgi_buffers 4 256k;
    #fastcgi_buffers 256 16k; #4096k total
    fastcgi_busy_buffers_size 256k;
    fastcgi_temp_file_write_size 256k;
    fastcgi_intercept_errors on;

PHP5-fpm通过TCP端口连接

谢谢

我认为你可能运行了太多并发的PHP进程,但是如果没有更多关于资源瓶颈的信息,很难知道.我想你可能受到磁盘IO和/或cpu的限制,并且所有并行的PHP进程都在竞争这些进程并相互减慢速度.在某些时候,进程切换的开销成为一个重要因素,并且通过运行大量进程可以获得更少的吞吐量而不是更多.您可能也会遇到或担心RAM耗尽并开始交换的情况,这非常糟糕.信任Nginx能够将请求排队并保持更高的吞吐量更快的请求,同时减少它们.

我通常会从5到50个PHP进程中进行任何操作,该范围的两端都有点特殊.通常10-15.对于性能非常高的磁盘系统,以及超过通常的16个核心,拥有更多进程可能是有意义的,但与拥有更多更便宜的服务器相比,这通常是错误的经济.根据我的经验,除非你有很多编写得非常糟糕的代码,否则在一台服务器上并行处理超过15个PHP进程通常没什么好处,如果有一个好处,它可能是稳定性而不是吞吐量,面对病态长期运行的请求堆积并且不留下备用流程.

如果您有多个具有单独进程池的代码库,则可能需要大量进程,但每个池可能不需要超过3到5个进程.

你确实需要很多Nginx工作者连接来处理静态文件.除了4096之外,不太可能有任何改进,只有在不寻常的情况下你会看到1000和4000之间的差异.(除非你主要服务于静态文件 – 这是一个完全不同的场景,但是因为你正在讨论这个问题上的PHP进程我不认为这是这种情况).

我怀疑你的超时时间太长了.如果没有任何结果,请断开连接并继续下一个连接.

原文链接:https://www.f2er.com/php/139103.html

猜你在找的PHP相关文章