php5-fpm은 모든 코어를 최대화합니다(nginx+php5fpm+wordpress).

php5-fpm은 모든 코어를 최대화합니다(nginx+php5fpm+wordpress).

우리는 8개의 CPU 코어로 실행되는 16GB Linode를 가지고 있으며 부하 테스트를 시도할 때 서버가 매우 기본적인 WordPress 사이트에서 초당 약 250개의 요청을 중단하기 시작하는 문제를 디버깅하려고 합니다. 나는 참고로 사이트의 첫 페이지만 치고 있습니다.

서버에 로그인하고 Htop에서 서버 통계를 보면 모든 코어가 고정되어 있고 php5-fpm 프로세스가 엄청나게 로드되어 있는 것을 볼 수 있습니다. 테스트가 완료된 후에도 이러한 프로세스는 여전히 존재하며 서버를 다시 활성화하려면 결국 php-fpm을 다시 시작해야 합니다.

오늘 부하 테스트를 하다가 로그에서 이런 내용을 봤습니다.

[23-Dec-2013 12:19:03] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 0 idle, and 27 total children
[23-Dec-2013 12:19:04] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 16 children, there are 0 idle, and 35 total children
[23-Dec-2013 12:19:05] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 45 total children
[23-Dec-2013 12:19:06] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 55 total children
[23-Dec-2013 12:19:07] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 65 total children
[23-Dec-2013 12:19:08] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 75 total children
[23-Dec-2013 12:19:19] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 5 idle, and 93 total children

따라서 분명히 뭔가 문제가 있습니다. 저는 현재 시스템에 맞게 이러한 설정을 조정하는 데 전문가가 아닙니다.

여기 www.conf가 있습니다.

; Start a new pool named 'www'.
; the variable $pool can we used in any directive and will be replaced by the
; pool name ('www' here)
[www]

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
user = www-data
group = www-data

; The address on which to accept FastCGI requests.
; Valid syntaxes are:
;   'ip.add.re.ss:port'    - to listen on a TCP socket to a specific address on
;                            a specific port;
;   'port'                 - to listen on a TCP socket to all addresses on a
;                            specific port;
;   '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = /var/run/php5-fpm.sock

; Set listen(2) backlog. A value of '-1' means unlimited.
; Default Value: 128 (-1 on FreeBSD and OpenBSD)
listen.backlog = 65536

pm = dynamic

; The number of child processes to be created when pm is set to 'static' and the
; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'.
; This value sets the limit on the number of simultaneous requests that will be
; served. Equivalent to the ApacheMaxClients directive with mpm_prefork.
; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP
; CGI. The below defaults are based on a server without much resources. Don't
; forget to tweak pm.* to fit your needs.
; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand'
; Note: This value is mandatory.
pm.max_children = 150
; The number of child processes created on startup.
; Note: Used only when pm is set to 'dynamic'
; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2
pm.start_servers = 20
; The desired minimum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.min_spare_servers = 10
; The desired maximum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.max_spare_servers = 35
; The number of seconds after which an idle process will be killed.
; Note: Used only when pm is set to 'ondemand'
; Default Value: 10s
;pm.process_idle_timeout = 10s;

; The number of requests each child process should execute before respawning.
; This can be useful to work around memory leaks in 3rd party libraries. For
; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS.
; Default Value: 0
pm.max_requests = 500

pm.status_path = /status-www

; The log file for slow requests
; Default Value: not set
; Note: slowlog is mandatory if request_slowlog_timeout is set
;slowlog = log/$pool.log.slow
slowlog = /var/log/php-fpm-slow.log

; 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'.
; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
; Default Value: 0
request_slowlog_timeout = 115s

; The timeout for serving a single request after which the worker process will
; be killed. This option should be used when the 'max_execution_time' ini option
; does not stop script execution for some reason. A value of '0' means 'off'.
; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
; Default Value: 0
request_terminate_timeout = 120s

; Set open file descriptor rlimit.
; Default Value: system defined value
rlimit_files = 65536

; Set max core size rlimit.
; Possible Values: 'unlimited' or an integer greater or equal to 0
; Default Value: system defined value
rlimit_core = 0

www.conf에 대해 조언이나 지적할 사항이 있습니까?

답변1

먼저, 스스로에게 질문을 던져야 합니다. 250 req/초가 귀하의 사이트에서 실제로 처리할 수 있어야 하는 것입니까? 페이지에 대한 요청이 너무 많습니다. 솔직히 말해서, 가상화된 시스템이라는 점을 고려하면 CPU를 최대로 사용하는 250req/s는 정상이라고 생각합니다.

pm.max_children = 150

아마도 자녀 수를 최대로 초과했다는 오류가 계속 발생하기 때문에 이 문제를 계속 제기했을 것입니다. 그러나 시스템이 처리할 수 있는 것 이상으로 이것을 높이면 실제로 발에 총을 쏘는 것입니다. 처리할 수 없는 다음 요청은 수락하는 것보다 수락하지 않는 것이 좋습니다. 이 값을 늘리면 시스템이 얇아질 뿐만 아니라 더 많은 리소스 요구 사항과 더 많은 오버헤드가 발생합니다. 그리고 시스템이 더 이상 처리할 수 없는 크기로 폭발하면 얼어붙는 것과 같은 징후가 나타납니다. 귀하의 VPS가 귀하에게 무엇을 제공하는지 정확히 알지 못하지만(노드의 다른 사용자에 따라 달라지므로 정적이지 않기 때문에 결코 알 수 없습니다), 개인적으로 귀하가 지정한 시스템에 대해 20을 초과하는 것은 그렇지 않다고 말하고 싶습니다. 현실적인 설정.

또한 최대 자식보다 큰 자식을 갖는 것은 의미가 없으므로 그에 따라 시작/최소/최대 예비를 조정해야 합니다. 아니면 그냥 걱정하지 말고 로 설정해도 됩니다 pm = static.

답변2

프로세스 관리를 주문형으로 변경

pm = ondemand

관련 정보