(转帖)php
- wxforex2010-11-12高级会员12377
转的不知道谁是原创了.......
php-fpm目前主要又两个分支,分别对应于php-5.2.x的版本和php-5.3.x的版本。在5.2.x的版本中,php-fpm.conf使用的是xml格式,而在新的5.3.x版本中,则是和php.ini一样的配置风格。
在5.2.x版本中,php-fpm.conf中对于进程管理号称是有两种风格,一种是静态(static)的,一种是类似于apache风格(apache-like)的。- 68 Process manager settings
- 69
- 70
- 71 Sets style of controling worker process count.
- 72 Valid values are ’static’ and ‘apache-like’
- 73 static复制代码按照文档的说明,如果pm的style采用apache-like,启动的进程数应该是和StartServers指定的一样。不过经过数次的尝试,我们会发现,实际上在这里将pn的style配置成apache-like没有起任何作用。也就是说,这里的apache-like并没有被实现。
不过,在最新的5.3.x的配套php-fpm中,apache风格的进程管理已经被实现了。- 98 ; Choose the process manager which control how processes are managed
- - 99 ; Two choices:
- - 100 ; – static : a fixed number (pm.max_children) of child processes
- - 101 ; – dynamic : The number of child processes are set up dynamically depending on the following directives
- - 102 ; – pm.max_children : the maximum number of children that can be alive at the same time
- - 103 ; – pm.start_servers : the number of children created on startup
- - 104 ; – pm.min_spare_servers : the minimum number of children in ‘idle’ state (waiting to precess).
- - 105 ; If the number of ‘idle’ processes is less than this number,
- - 106 ; some children will be created.
- - 107 ; – pm.max_spare_servers : the maximum number of children in ‘idle’ state (waiting to precess).
- - 108 ; If the number of ‘idle’ processes is greater than this number,
- - 109 ; some children will be killed;
- - 110 ; It’s mandatory
- - 111 pm = dynamic复制代码由上面一段文字可知,对于进程的管理存在两种风格——static和dynamic。
和之前的版本的进程管理其实还是一样的,只是将apache-like改成了dynamic,这样更容易理解。
如果设置成static,进程数自始至终都是pm.max_children指定的数量。
如果设置成dynamic,则进程数是动态的,最开始是pm.start_servers指定的数量,如果请求较多,则会自动增加,保证空闲的进程数不小于pm.min_spare_servers,如果进程数较多,也会进行相应清理,保证多余的进程数不多于pm.max_spare_servers。当php-fpm启动后,一个php-cgi进程约战3M内存,但是当它们处理过一些请求后,有些内存是释放不掉的,占用的内存能达到20M-30M不等。对于内存大的服务器(比如说4G)来说,指定静态的max_children实际上更为妥当,因为这样不需要进行额外的进程数目控制。
比如我们指定为100个,那么php-fpm耗费的内存就能控制在 2G的样子,用2G来处理别的事情也应该足够了。如果内存稍微小点,比如1G,那么指定静态的进程数量应该更加有利于服务器的稳定。这样可以保证php-fpm只获取够用的内存,将不多的内存分配给其他应用去使用,会使系统的运行更加畅通。对于更小的内存来说,比如128M的内存,即使按照20M的内存量来算,10个php-cgi进程就将耗掉200M内存,那系统的崩溃就应该很正常了。因此应该尽量地控制php-fpm进程的数量,大体明确其他应用占用的内存后,给它指定一个静态的小数量,会让系统更加平稳一些。[ 本帖最后由 wxforex 于 2010-11-12 16:04 编辑 ]