php5-fpm maximiza todos los núcleos (nginx+php5fpm+wordpress)

php5-fpm maximiza todos los núcleos (nginx+php5fpm+wordpress)

Tenemos un Linode de 16 gigas ejecutándose con 8 núcleos de CPU y estoy tratando de solucionar un problema que cuando intento una prueba de carga, el servidor comienza a asustarse con alrededor de 250 solicitudes por segundo en un sitio de WordPress bastante básico. Solo estoy accediendo a la página principal del sitio para su información.

Cuando inicio sesión en el servidor y veo las estadísticas del servidor en Htop, veo todos los núcleos vinculados y una carga de procesos php5-fpm. Una vez realizada la prueba, estos procesos aún existen y eventualmente tengo que reiniciar php-fpm para que el servidor vuelva a funcionar.

Vi esto en el registro hoy al realizar la prueba de carga.

[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

Obviamente algo está mal, simplemente no soy un experto en modificar estas configuraciones para el sistema actual que tenemos.

Aquí está nuestro 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

¿Algún consejo o algo que señalar con www.conf?

Respuesta1

En primer lugar, debería hacerse la pregunta: ¿250 solicitudes por segundo es algo que su sitio realmente debería poder manejar? Son MUCHAS solicitudes para una página. Francamente, creo que 250req/s como máximo en tu CPU es normal dado lo que tienes: un sistema virtualizado.

pm.max_children = 150

Probablemente seguiste planteando esto porque sigues recibiendo errores que dicen que estás al máximo de niños. Pero en realidad te estás disparando en el pie cuando elevas esto más allá de lo que tu sistema puede manejar. Es mejor NO aceptar una próxima solicitud que no pueda manejar que aceptar. Aumentar esto no sólo adelgaza su sistema, sino que crea más requisitos de recursos y más gastos generales. Y cuando eso explota a un tamaño que su sistema ya no puede soportar, crea signos como congelamiento. No sé exactamente qué te ofrece tu VPS (y nunca lo sabrás ya que no es estático ya que depende de otros usuarios en el nodo), pero personalmente diría que cualquier valor superior a 20 para tu sistema especificado no es escenario realista.

También debe ajustar el repuesto inicial/mínimo/máximo en consecuencia, ya que tener hijos mayores que el máximo no tiene sentido. O simplemente puedes no preocuparte por eso y configurarlo pm = static.

Respuesta2

Cambiar la gestión de procesos a bajo demanda

pm = ondemand

información relacionada