`
dongbao100
  • 浏览: 34487 次
  • 性别: Icon_minigender_1
  • 来自: 沈阳
社区版块
存档分类
最新评论

PHP的pm、pm.max_requests、memory_limit参数

    博客分类:
  • php
 
阅读更多

1、php-fpm.conf中的pm
pm是来控制php-fpm的工作进程数到底是一次性产生固定不变(static)还是在运行过程中随着需要动态变化(dynamic)。众所周知,工作进程数与服务器性能息息相关,太少则不能及时处理请求,太多则会占用内存过大而拖慢系统。因为php-fpm处理请求时会随着处理的请求数的增加而占用越来越多的内存,所以static模式下往往不好判断启动的能使内存利用最大化的固定进程数,所以想到了dynamic模式。可是为什么我们不用dynamic模式呢,试想某个时刻请求数比较低,20个进程足够应付,突然压力增大了,出现了40个并发PHP请求,按照最小5个空闲进程的设置就需要45个进程,也就是说需要在短时间内创建出25个进程,我们知道创建进程的操作是比较消耗系统资源的,再加上40个并发PHP请求肯定也会给MySQL带来一定的压力,此时再创建25个进程无疑是雪上加霜,所以我在这里还是选择了static模式。
2、php-fpm.conf中的pm.max_requests
根据说明我们知道这个参数的含义是php-fpm工作进程处理完多少请求后自动重启,主要目的就是为了控制请求处理过程中的内存溢出,使得内存占用在一个可接受的范围内。从这里我们感觉这个数字似乎设置的小一点更加有利于性能提升,但是当这个数字非常小的时候会发生一种情况,由于PHP请求是平均地分配给各个工作进程的,如果这个值太小就会导致所有的工作进程几乎同时达到这个值并且进入需要重启的状态,当所有的工作进程都在同一时刻重启就会发生在数秒内甚至更长的时间PHP将停止响应直到所有的进程均重启完为止。这是不能接受的,所以我一般会把这个值设置为PHP启动后第一批工作进程达到此值需要重启时,第一个进程重启与最后一个进程重启之间的时间相差1分钟以上,一般在压力比较大的晚上这个差值将会扩大到5分钟左右,此时对进程重启对服务器的负面影响就可以忽略了。
3、php.ini中的memory_limit
顾名思义,这个值是用来限制PHP所占用的内存的,具体一点说就是一个PHP工作进程即php-fpm所能够使用的最大内存,默认是128MB,一开始在虚拟机中我设置为PHP 5.1.6的默认值16MB,发现大于16MB的附件将无法下载,也就是说PHP 5.3中附件是从硬盘完整读取到PHP内存中再传给nginx的,这跟PHP 5.1.6+Apache 2.2.3不同,后者读取附件是PHP并不加载这个附件而是直接交给Apache来加载,这就使得php-fpm占用内存大了不少。当php-fpm占用内存达到了memory_limit所限制的值时,当前进程会被fpm主进程使用TERM信号终止掉,此时被处理的PHP请求将返回客户端502错误,nginx的error log中将记录出错原因是“Connection reset by peer”。可是更加令人难以理解的事情发生了,在使用了eAccelerator的PHP 5.3上,居然发生了当php-fpm内存达到memory_limit所限制的值时,所有进程都开始疯狂重启而不再接受任何请求,此时除非使用kill命令杀死主进程,否则php-fpm永远都不会恢复响应,可想而知nginx必然出现无止境的502错误了。。。

分享到:
评论

相关推荐

    openstack安装包(一)

    python-requests-1.1.0-4.el6.noarch.rpm python-routes1.12-1.12.3-4.el6.noarch.rpm python-saslwrapper-0.18-1.el6_3.x86_64.rpm python-setuptools-0.6.10-3.el6.noarch.rpm python-simplejson-2.0.9-3.1.el6....

    libaec-1.0.2-3.el8.x86_64.rpm

    在安装gmt时,出现错误: Error: Problem: package gmt-6.0.0-1.el8.... - conflicting requests - nothing provides libsz.so.2()(64bit) needed by netcdf-4.7.0-2.el8.x86_64 把这个文件安装后,就正常了。

    sql最全的常用命令语句

    select a.*,login_time,program_name,client_interface_name,login_name,cpu_time,memory_usage*8 as 'memory_usage(KB)', total_scheduled_time,reads,writes,logical_reads from tb a inner join master.sys.dm_...

    reddingsmonitor:KML追踪器

    需要包 sudo apt-get install php7.0-fpm php7.0-dom PHP-FPM池设置 ...listen = 127.0.0.1:9000;...pm.max_requests = 0 作曲家安装 sudo php /home/reddingsmonitor/composer.phar install --no-plugins

    EO.WebBrowser_for_.NET_2018.2.53.0

    EO.WebBrowser offers ability to intercept and modify all requests that originate from the browser engine. For example, you can automatically deny all request sent to a specific host. It also offers ...

    .DS_Store

    .DS_Store

    php.ini-development

    max_input_time ; Default Value: -1 (Unlimited) ; Development Value: 60 (60 seconds) ; Production Value: 60 (60 seconds) ; output_buffering ; Default Value: Off ; Development Value: 4096 ; Production...

    aha154x.zip_Download aha154x.sys_The Power_adaptec aha-154x_mini

    This driver exports several functions which are used by SCSIPORT.SYS to issue SCSI requests to the devices attached to the controller, process adapter interrupts, and various other SCSI activities. ...

    PIL1_4.zip_PIL1_4_PIL1_4.zip_Plug-in dll_hltr_plug-in

    In the past I have written a plug-in architecture for one of my MFC projects. This architecture, ... I have also had requests to post an article on the subject. That s how this library came about.

    openstack安装包(二)

    python-requests-1.1.0-4.el6.noarch.rpm python-routes1.12-1.12.3-4.el6.noarch.rpm python-saslwrapper-0.18-1.el6_3.x86_64.rpm python-setuptools-0.6.10-3.el6.noarch.rpm python-simplejson-2.0.9-3.1.el6....

    ZendFramework中文文档

    6.3. 读取(Fetching)选项和参数 6.3.1. 操作 Getopt 异常 6.3.2. 通过名字读取 (Fetching)选项 6.3.3. 报告选项 6.3.4. 读取非选项参数 6.4. 配置 Zend_Console_Getopt 6.4.1. 添加选项规则 6.4.2. 添加...

    SqlServer应用之sys.dm_os_waiting_tasks 引发的疑问(中)

    通过上篇文章给大家介绍了SqlServer应用之sys.dm_os_waiting_tasks 引发的疑问(上) ,说了一下sys.dm_exec_requests 和 sys.dm_os_waiting_tasks 在获取并行等待的时候得不同结果,这一篇我们谈论下我的第二个疑问:...

    Python数据分析实践:pandas读写html表格数据new.pdf

    构造请求主要用到requests库,定位提取数据 用的比较多的有xpath和正则匹配。一个完整的爬虫,代码量少则几十行,多则百来行,对于新手来说学习成本还是比较高的。 针对网页结构类似的表格类型数据,pd.read_html()...

    udp.rar_The Number

    Keeps track of the number of DNS requests. Used to implement the firewall option that restricts the number of DNS requests (-max_dns_conns).

    air_b.zip_BLUETOOTH Inquiry_building

    * eir_b makes the device visible and responds to Bluetooth 2.1 Extended Inquiry Response (EIR) requests. This ReadMe is not intended to describe procedures that are covered in the xIDE user guide ...

    SQL Monitor for Oracle,MySQL和DB2 v2.4.3.6 中文绿色版

    select * from sys.dm_exec_requests select * from sys.dm_exec_sessions 然后dbcc INPUTBUFFER(spid)来获取指定进程执行的SQL,最后用kill spid来中止SQL进程。 实际调试起来,会用到其它复杂的SQL,譬如是什么...

    python-requests-2.6.0-1.el7_1.noarch.rpm

    离线安装包,亲测可用

    虾米工具包xiami-tools.zip

    songid 的歌曲Xiami.get_session(self) 获得当前 Xiami 实例的requests.Session对象Xiami.get_random_songs(self, uid=None, full=False) 不知道干什么用的Xiami.get_artist_topsongs(self, artist_id, full=False) ...

    python3-requests-2.20.0-2.1.el8_1.noarch(1).rpm

    官方离线安装包,亲测可用

    grpc_requests:python grpc reflaction客户端

    grpc要求人类的GRPC from grpc_requests import Clientclient = Client . get_by_endpoint ( "localhost:50051" )assert client . service_names == [ "helloworld.Greeter" ]request_data = { "name" : 'sinsky' } ...

Global site tag (gtag.js) - Google Analytics