Home  >  Article  >  Backend Development  >  PHP-FPM的pm.max_children 配置值怎么计算?

PHP-FPM的pm.max_children 配置值怎么计算?

WBOY
WBOYOriginal
2016-07-06 13:53:032660browse

<code>pm = static
pm.max_children = 500
</code>

https://segmentfault.com/a/1190000002488698 这篇文章中说:pm.max_children 数量的多少根据机器内存确定,基本上一个进程需要30M的内存,假设起100个进程,那么就是3000M,3G内存

这里一个进程需要30M内存,是怎么算出来的?
pm.max_children 配置值根据什么来计算比较的合理?

回复内容:

<code>pm = static
pm.max_children = 500
</code>

https://segmentfault.com/a/1190000002488698 这篇文章中说:pm.max_children 数量的多少根据机器内存确定,基本上一个进程需要30M的内存,假设起100个进程,那么就是3000M,3G内存

这里一个进程需要30M内存,是怎么算出来的?
pm.max_children 配置值根据什么来计算比较的合理?

30M内存是跑出来的。拿着生产的机器跑一下,一般都在10-30M左右。看看top的res、shr
除了内存,也要看机器CPU,要看访问量等等。

比如,每秒100个请求,那开100多一点最好,不空闲也不等待。

一个php进程,大概占用多少内存呢,大概是20MB(具体的要看你的php加载了多少模块)。可以通过pmap指令查看哪些地方占用了内存。所以,尽量不要加载不必要的php扩展模块,可以减少不必要的内存浪费。

<code>pmap $(pgrep php-fpm | head -1)</code>

不同的php单个进程的消耗是不同的,你可以在测试你的php程序时通过memory_get_peak_usage(true)这个函数获得内存峰值,以此作为单个请求的程序内存消耗消耗量,并考虑进php-fpm本身的基础内存消耗,可以得到一个近似的单进程内存消耗量。

http://blog.tanteng.me/2016/03/php-fpm-conf/
请参考这篇文章

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn