进程last-request-cpu的PHP-FPM池状态 [英] PHP-FPM pool status of process last-request-cpu

查看:91
本文介绍了进程last-request-cpu的PHP-FPM池状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了PHP并启用了FPM功能,但是我对FPM状态数据(例如流程last-request-cpu)不确定,下面是我的php-fpm.conf详细信息.

I have installed a PHP and enable the FPM function, but i feel uncertain about the FPM status data(like the process last-request-cpu), below is my php-fpm.conf detail.

[www]
; Unix user/group of processes
user = www-data
group = www-data

; Chdir to this directory at the start.
chdir = /

; The address on which to accept FastCGI requests.
listen = /var/run/phpfpm/$pool_php5-fpm.sock

; Set listen(2) backlog. A value of '-1' means unlimited.
listen.backlog = -1

; Set permissions for unix socket.
listen.mode = 0666

; Pool configuration.
pm = dynamic
pm.max_children = 10
pm.start_servers = 4
pm.min_spare_servers = 2
pm.max_spare_servers = 6
pm.max_requests = 500

; The URI to view the FPM status page.
pm.status_path = /status

; The ping URI to call the monitoring page of FPM.
ping.path = /ping

; The access log file.
access.log = /var/log/phpfpm/$pool_php-fpm.access.log

; The access log format.
access.format = %R - %u %t "%m %r%Q%q" %s %f %{mili}d %{kilo}M %C%%

; The log file for slow requests.
slowlog = /var/log/phpfpm/$pool_php-fpm.log.slow

; The timeout for serving a single request after which a PHP backtrace will be
; dumped to the 'slowlog' file. A value of '0s' means 'off'.
request_slowlog_timeout = 5

; Limits the extensions of the main script FPM will allow to parse.
security.limit_extensions = .php

我已启用pm.status_path =/status来查看FPM状态结果,如下所示:

I have enable the pm.status_path = /status to view the FPM status result as below:

<?xml version="1.0" ?>
<status>
<pool>www</pool>
<process-manager>dynamic</process-manager>
<start-time>1418352728</start-time>
<start-since>21936</start-since>
<accepted-conn>20</accepted-conn>
<listen-queue>0</listen-queue>
<max-listen-queue>0</max-listen-queue>
<listen-queue-len>0</listen-queue-len>
<idle-processes>3</idle-processes>
<active-processes>1</active-processes>
<total-processes>4</total-processes>
<max-active-processes>1</max-active-processes>
<max-children-reached>0</max-children-reached>
<slow-requests>0</slow-requests>
<processes>
<process>
    <pid>11</pid>
    <state>Idle</state>
    <start-time>1418352728</start-time>
    <start-since>21936</start-since>
    <requests>5</requests>
    <request-duration>5391</request-duration>
    <request-method>GET</request-method>
    <request-uri>/status?xml&amp;full</request-uri>
    <content-length>0</content-length>
    <user>-</user><script>-</script>
    <last-request-cpu>0.00</last-request-cpu>
    <last-request-memory>262144</last-request-memory>
</process>
<process>
    <pid>12</pid>
    <state>Idle</state>
    <start-time>1418352728</start-time>
    <start-since>21936</start-since>
    <requests>5</requests>
    <request-duration>3365</request-duration>
    <request-method>GET</request-method>
    <request-uri>/status?xml&amp;full</request-uri>
    <content-length>0</content-length>
    <user>-</user><script>-</script>
    <last-request-cpu>297.18</last-request-cpu>
    <last-request-memory>262144</last-request-memory>
</process>
</processes>
</status>

我不知道为什么元素last-request-cpu值297.18大于100,我想知道如何将其用作监视信息. 谢谢

I dont know why the element last-request-cpu value 297.18 is more than 100, i would like to know how to use it as monitored info.. Thanks

推荐答案

该度量标准将表明在

CPU时间(或处理时间)是中央处理器(CPU)用于处理计算机程序或操作系统的指令的时间,而不是例如等待输入/输出( I/O)操作或进入低功耗(空闲)模式. CPU时间以时钟滴答或秒为单位.

CPU time (or process time) is the amount of time for which a central processing unit (CPU) was used for processing instructions of a computer program or operating system, as opposed to, for example, waiting for input/output (I/O) operations or entering low-power (idle) mode. The CPU time is measured in clock ticks or seconds.

因此,它不是以本页其他地方建议的毫秒为单位测量的.

So it is not measured in milliseconds as suggested elsewhere on this page.

您可以在

相关部分如下(为便于阅读而重新格式化):

The relevant parts are this (reformatted for readability):

431    if (proc.cpu_duration.tv_sec == 0 && proc.cpu_duration.tv_usec == 0) {
432        cpu = 0.;
433    } else {
434        cpu = (proc.last_request_cpu.tms_utime 
                + proc.last_request_cpu.tms_stime 
                + proc.last_request_cpu.tms_cutime 
                + proc.last_request_cpu.tms_cstime) 
                / fpm_scoreboard_get_tick() 
                / (proc.cpu_duration.tv_sec 
                + proc.cpu_duration.tv_usec / 1000000.) 
                * 100.;
435    }

tms proc.last_request_cpu结构成员定义为:

The struct members for tms proc.last_request_cpu are defined as:

  • tms_utime结构成员是执行调用过程的用户指令所收取的CPU时间.
  • tms_stime结构成员是由系统代表调用进程执行的CPU时间.
  • tms_cutime结构成员是子进程的tms_utimetms_cutime时间的总和.
  • tms_cstime结构成员是子进程的tms_stimetms_cstime时间的总和.
  • The tms_utime structure member is the CPU time charged for the execution of user instructions of the calling process.
  • The tms_stime structure member is the CPU time charged for execution by the system on behalf of the calling process.
  • The tms_cutime structure member is the sum of the tms_utime and tms_cutime times of the child processes.
  • The tms_cstime structure member is the sum of the tms_stime and tms_cstime times of the child processes.

因此,这意味着我们将累加上次请求中所有可能的cpu时间.所有时间都是根据使用的时钟滴答次数来衡量的.

So this means we are adding up all possible cpu times charged in the last request. All times are measured in terms of the number of clock ticks used.

fpm_scoreboard_get_tick 函数只会返回可能的滴答声每秒,例如您的计算机每核最大每秒可以执行多少条指令.

timeval proc.cpu_duration结构成员定义为:

  • time_t tv_sec:这表示经过时间的整秒数.
  • long int tv_usec:这是剩余的经过时间(几分之一秒),以微秒数表示.它总是少于一百万.
  • time_t tv_sec: This represents the number of whole seconds of elapsed time.
  • long int tv_usec: This is the rest of the elapsed time (a fraction of a second), represented as the number of microseconds. It is always less than one million.

这是经过的时间,以秒为单位,包括任何分数,例如类似于2.456435663.

This is the elapsed time in seconds, including any fractions, e.g. something like 2.456435663.

然后将值乘以100,以获得百分比值.

The value is then multiplied by 100 to get the percentage value.

示例:

假设我们的上一个请求在5秒钟内总共烧了350次滴答声.我们还假设每秒最大滴答声是100.如果将这些数字放到上面的等式中,我们将得到

Assume our last request burned a total of 350 ticks in 5 seconds. We also assume that our maximum ticks per second is 100. If we put these numbers into the equation above, we get

 (350 / 100 / 5) * 100 = 70

这意味着最后一个请求已用完您可用CPU时间的70%.

This means the last request used up 70% of your available CPU time.

获得高于100%的值的原因是因为每秒的滴答声值不受您拥有的内核数的影响,而proc.last_request_cpu值将返回所有进程的滴答声计数,例如对数据库或某些其他数据源的访问可能在另一个过程中发生,但直接受到PHP执行的代码的影响.因此,这里考虑了这一点.

The reason you get values above 100% is because the value for ticks per second is unaffected by the number of cores you have, whereas proc.last_request_cpu values will return the tick count of all processes, e.g. access to a database or some other data source may happen in another process, but is directly affected by the code PHP executes. So this is taken into account here.

这篇关于进程last-request-cpu的PHP-FPM池状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆