php-fpm:帮助了解start_servers,min_spare_servers,max_spare_servers


10

我想调我的PHP-FPM安装我的服务器,我有麻烦搞清楚什么与做pm.start_serverspm.min_spare_serverspm.max_spare_servers变量。我在用pm = dynamic

pm.max_children非常清楚。每个子进程一次服务1个Web客户端。好。那么,什么是“服务器”?显然,根据我的默认配置,一台服务器可以为1个以上的孩子提供服务。上限是多少?对于#个孩子/服务器,我应该如何使用经验法则?还是完全相关?在某个论坛上,有人声称服务器数量应为2 x CPU核心数量,但是我看到了推荐的配置,数量要高得多,为40-50。

PHP文档和许多“调整php-fpm”文章都没有帮助。

Answers:


14

基本上,当您设置为dynamic喜欢时,php-fpm随时将运行的进程数是非常可配置的。当设置为static将有始终是运行的子进程。通常,您将其设置为动态以节省资源。每个子进程可以处理一个请求。上限取决于您的php应用程序有多沉重以及您获得了多少流量。您还应该计算每个子进程的平均内存消耗,并确保您绝不允许子进程的数量超过服务器上安装的内存数量,否则您将开始交换甚至让内核开始杀死进程。

; Choose how the process manager will control the number of child processes.
; Possible Values:
;   static  - a fixed number (pm.max_children) of child processes;
;   dynamic - the number of child processes are set dynamically based on the
;             following directives:
;             pm.max_children      - the maximum number of children that can
;                                    be alive at the same time.
;             pm.start_servers     - the number of children created on startup.
;             pm.min_spare_servers - the minimum number of children in 'idle'
;                                    state (waiting to process). If the number
;                                    of 'idle' processes is less than this
;                                    number then some children will be created.
;             pm.max_spare_servers - the maximum number of children in 'idle'
;                                    state (waiting to process). If the number
;                                    of 'idle' processes is greater than this
;                                    number then some children will be killed.
; Note: This value is mandatory.

设置这些选项时,请注意以下事项:

  • 您的平均要求多长时间?
  • 网站获得的同时访问者的最大数量是多少?
  • 每个子进程平均消耗多少内存?

3
非常有帮助,感谢您的见解。对于计算也很有用,可使用它ps --no-headers -o "rss,cmd" -C php-fpm | awk '{ sum+=$1 } END { printf ("%d%s\n", sum/NR/1024,"M") }'查看每个工作程序有多少内存。摘自community.webcore.cloud/tutorials/...
马特忍者
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.