Desempenho lento do servidor - mod_fcgid causando (104), (09) e (32) erros: mod_fcgid: ap_pass_brigade falhou na função handle_request_ipc

0

Estou com problemas para acompanhar a origem do desempenho lento do servidor da Web para páginas do Wordpress e de páginas não armazenadas em cache.

Server OS : Debian 8 "Jesssie)" - Versão Linux 4.9.58-xxxx-std-ipv6-64 ([email protected]) (versão gcc 6.3.0 20170516 Debian 6.3.0-18)) # 1 SMP seg 23 de outubro 11:35:59 CEST 2017 ( Ispconfig )

Servidor Web : Versão do servidor: Apache / 2.4.10 (Debian)

PHP (padrão): PHP 7.0.26

PHP (selecionado): Versão do PHP 7.1.8

Procesor : Intel Xeon E5-2630v3 2x - 16 / 32t - 2.4GHz / 3.2GHz

RAM : 128 GB DDR4 ECC 1866 MHz

Discos : SoftRaid 2x450GB SSD NVMe

apache2.conf :

Timeout 300
KeepAlive On
MaxKeepAliveRequests 300
KeepAliveTimeout 5

Status do servidor (pelos últimos 40 minutos):

Server Version: Apache/2.4.10 (Debian) mod_fastcgi/mod_fastcgi-SNAP-0910052141 mod_fcgid/2.3.9 mod_python/3.3.1 Python/2.7.9 OpenSSL/1.0.1t
Server MPM: worker
Server Built: Sep 20 2017 04:37:43

Current Time: Monday, 22-Jan-2018 05:24:45 EST
Restart Time: Monday, 22-Jan-2018 04:43:55 EST
Parent Server Config. Generation: 1
Parent Server MPM Generation: 0
Server uptime: 40 minutes 50 seconds
Server load: 0.06 0.09 0.33
Total accesses: 8359 - Total Traffic: 147.2 MB
CPU Usage: u20.73 s2.61 cu0 cs0 - .953% CPU load
3.41 requests/sec - 61.5 kB/second - 18.0 kB/request
13 requests currently being processed, 237 idle workers

apache2ctl -M :

Loaded Modules:
 core_module (static)
 so_module (static)
 watchdog_module (static)
 http_module (static)
 log_config_module (static)
 logio_module (static)
 version_module (static)
 unixd_module (static)
 access_compat_module (shared)
 actions_module (shared)
 alias_module (shared)
 auth_basic_module (shared)
 auth_digest_module (shared)
 authn_core_module (shared)
 authn_file_module (shared)
 authz_core_module (shared)
 authz_host_module (shared)
 authz_user_module (shared)
 autoindex_module (shared)
 dav_module (shared)
 dav_fs_module (shared)
 deflate_module (shared)
 dir_module (shared)
 env_module (shared)
 expires_module (shared)
 fastcgi_module (shared)
 fcgid_module (shared)
 filter_module (shared)
 include_module (shared)
 mime_module (shared)
 mpm_worker_module (shared)
 negotiation_module (shared)
 proxy_module (shared)
 proxy_fcgi_module (shared)
 python_module (shared)
 reqtimeout_module (shared)
 rewrite_module (shared)
 setenvif_module (shared)
 socache_shmcb_module (shared)
 ssl_module (shared)
 status_module (shared)
 suexec_module (shared)

Servidor MPM: worker :

<IfModule mpm_worker_module>
        StartServers             10
        MinSpareThreads          25
        MaxSpareThreads          400
        ThreadLimit              64
        ThreadsPerChild          25
        MaxRequestWorkers        500
        MaxConnectionsPerChild   0
</IfModule>

my.cnf (MySQL):

innodb_buffer_pool_size = 61440M
innodb_file_per_table=1
innodb_log_file_size = 1024M
innodb_buffer_pool_instances=60
key_buffer              = 2048M
max_allowed_packet      = 16M
thread_stack            = 192K
thread_cache_size       = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover         = BACKUP
#max_connections        = 100
#table_cache            = 64
#thread_concurrency     = 10
#
# * Query Cache Configuration
#
query_cache_limit       = 1M
query_cache_size        = 0
query_cache_type        = 0
#query_cache_size        = 8192M

domain.com.vhost-le-ssl.conf (...)

<Directory /var/www/domain.com/web>
                                # Clear PHP settings of this website
                                <FilesMatch ".+\.ph(p[345]?|t|tml)$">
                                                SetHandler None
                                </FilesMatch>
                                Options +FollowSymLinks
                                AllowOverride All
                                                                Require all granted
                                                </Directory>
                <Directory /var/www/clients/client1/web1/web>
                                # Clear PHP settings of this website
                                <FilesMatch ".+\.ph(p[345]?|t|tml)$">
                                                SetHandler None
                                </FilesMatch>
                                Options +FollowSymLinks
                                AllowOverride All
                                                                Require all granted
                                                </Directory>




                # suexec enabled
                <IfModule mod_suexec.c>
                        SuexecUserGroup web1 client1
                </IfModule>
                # php as fast-cgi enabled
        # For config options see: http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html
                <IfModule mod_fcgid.c>
                                FcgidIdleTimeout 300
                                FcgidProcessLifeTime 3600
                                FcgidInitialEnv PHP_FCGI_MAX_REQUESTS 10000
                                #FcgidMaxProcesses 1000
                                FcgidMaxRequestsPerProcess 10000
                                FcgidMinProcessesPerClass 0
                                FcgidMaxProcessesPerClass 10
                                FcgidConnectTimeout 20
                                FcgidIOTimeout 600
                                FcgidBusyTimeout 3600
                                FcgidOutputBufferSize   0
                                # FcgidBusyScanInterval 120
                                FcgidMaxRequestLen 1073741824
                </IfModule>
                <Directory /var/www/domain.com/web>
                                <FilesMatch "\.php[345]?$">
                                        SetHandler fcgid-script
                                </FilesMatch>
                                FCGIWrapper /var/www/php-fcgi-scripts/web1/.php-fcgi-starter .php
                                FCGIWrapper /var/www/php-fcgi-scripts/web1/.php-fcgi-starter .php3
                                FCGIWrapper /var/www/php-fcgi-scripts/web1/.php-fcgi-starter .php4
                                FCGIWrapper /var/www/php-fcgi-scripts/web1/.php-fcgi-starter .php5
                                Options +ExecCGI
                                AllowOverride All
                                                                Require all granted
                                                </Directory>
                <Directory /var/www/clients/client1/web1/web>
                                <FilesMatch "\.php[345]?$">
                                        SetHandler fcgid-script
                                </FilesMatch>
                                FCGIWrapper /var/www/php-fcgi-scripts/web1/.php-fcgi-starter .php
                                FCGIWrapper /var/www/php-fcgi-scripts/web1/.php-fcgi-starter .php3
                                FCGIWrapper /var/www/php-fcgi-scripts/web1/.php-fcgi-starter .php4
                                FCGIWrapper /var/www/php-fcgi-scripts/web1/.php-fcgi-starter .php5
Options +ExecCGI
                                AllowOverride All
                                                                Require all granted
                                                </Directory>



                # add support for apache mpm_itk
                <IfModule mpm_itk_module>
                        AssignUserId web1 client1
                </IfModule>

                <IfModule mod_dav_fs.c>
                # Do not execute PHP files in webdav directory
                        <Directory /var/www/clients/client1/web1/webdav>
                                <ifModule mod_security2.c>
                                        SecRuleRemoveById 960015
                                        SecRuleRemoveById 960032
                                </ifModule>
                                <FilesMatch "\.ph(p3?|tml)$">
                                        SetHandler None
                                </FilesMatch>
                        </Directory>
                        DavLockDB /var/www/clients/client1/web1/tmp/DavLock
                        # DO NOT REMOVE THE COMMENTS!
                        # IF YOU REMOVE THEM, WEBDAV WILL NOT WORK ANYMORE!
      # WEBDAV BEGIN
                        # WEBDAV END
                </IfModule>
(...)

Problema :

Eu hospedo um único site wordpress nesta máquina. (32) erro aparecia de tempos em tempos, mesmo quando o site estava em desenvolvimento e o único usuário era eu. Atualmente tenho cerca de 5k visitantes únicos por dia ( link ) e meu error.log exibe vários (104), (9 ) e (32) erros, incluindo:

    (...)
        (104)Connection reset by peer: [client: XXX.XX.XX.XX:XXXX] mod_fcgid: error reading data from FastCGI server
        (104)Connection reset by peer: [client: XXX.XX.XX.XX:XXXX] mod_fcgid: ap_pass_brigade failed in handle_request_ipc function
        (9)Bad file descriptor: [client: XXX.XX.XX.XX:XXXX] mod_fcgid: ap_pass_brigade failed in handle_request_ipc function
        (32)Broken pipe: [client: XXX.XX.XX.XX:XXXX] mod_fcgid: ap_pass_brigade failed in handle_request_ipc function
(104)Connection reset by peer: [client: XXX.XX.XX.XX:XXXX] mod_fcgid: error reading data from FastCGI server, referer: https://domain.com/wp-admin/post.php?post=XXXXXXX&action=edit
    (...)

O erro mais comum é:

(32)Broken pipe: [client: XXX.XX.XX.XX:XXXX] mod_fcgid: ap_pass_brigade failed in handle_request_ipc function

Eu diria que esses erros ocorrem em 5% a 10% de todas as visitas e o número é atualmente baixo apenas devido ao fato de que a maioria das minhas páginas está em cache. Isso começa a me preocupar, pois meu site está recebendo mais acessos dia a dia e mais visitantes estão registrando e usando a opção "pesquisa" ou apenas clicam em links "tag" que não são armazenados em cache devido ao seu conteúdo dinâmico.

Pelo que notei, esses erros ocorrem principalmente quando o PHP está em execução. Para teste eu abri em torno de 20 post em abas e clicou no botão "editar". Isso causou erros (104), (9) e (32). (32) aparece também quando o visitante está fazendo a pesquisa. No total, tenho cerca de 500k post no meu wordpress.

O que fiz para tentar corrigi-lo (SEM SUCESSO): 1 . Eu mudei de PHP-FPM para Fast-CGI e abri 20 posts em abas e cliquei no botão "editar". Erros ainda aparecem em error.log e e post não são carregados com o navegador exibindo " Aguardando o soquete disponível " ( as páginas armazenadas em cache funcionam super-rápidas ).

ps aux | grep "php"

root      7554  0.0  0.0 210764 24084 ?        Ss    2017   0:47 php-fpm: master process (/etc/php/7.0/fpm/php-fpm.conf)
root     21443  0.0  0.0 280056  8700 ?        Ss   05:49   0:00 php-fpm: master process (/opt/php-7.1/etc/php-fpm.conf)
www-data 21444  0.0  0.0 280056  6904 ?        S    05:49   0:00 php-fpm: pool www
www-data 21445  0.0  0.0 280056  6904 ?        S    05:49   0:00 php-fpm: pool www
web1     21801  1.4  0.0 367796 83900 ?        S    05:49   0:05 /opt/php-7.1/bin/php-cgi -d open_basedir=/var/www/clients/client1/web1/web:/var/www/clients/client1/web1/private:/var/www/clients/client1/web1/tmp:/var/www/domain.com/web:/srv/www/domain.com/web:/usr/share/php5:/usr/share/php:/tmp:/usr/share/phpmyadmin:/etc/phpmyadmin:/var/lib/phpmyadmin:/dev/random:/dev/urandom -d upload_tmp_dir=/var/www/clients/client1/web1/tmp -d session.save_path=/var/www/clients/client1/web1/tmp -d sendmail_path=/usr/sbin/sendmail -t -i -f [email protected]
web1     21802  0.9  0.0 367716 81768 ?        S    05:49   0:03 /opt/php-7.1/bin/php-cgi -d open_basedir=/var/www/clients/client1/web1/web:/var/www/clients/client1/web1/private:/var/www/clients/client1/web1/tmp:/var/www/domain.com/web:/srv/www/domain.com/web:/usr/share/php5:/usr/share/php:/tmp:/usr/share/phpmyadmin:/etc/phpmyadmin:/var/lib/phpmyadmin:/dev/random:/dev/urandom -d upload_tmp_dir=/var/www/clients/client1/web1/tmp -d session.save_path=/var/www/clients/client1/web1/tmp -d sendmail_path=/usr/sbin/sendmail -t -i -f [email protected]
web1     21803  0.7  0.0 291716 80684 ?        S    05:49   0:02 /opt/php-7.1/bin/php-cgi -d open_basedir=/var/www/clients/client1/web1/web:/var/www/clients/client1/web1/private:/var/www/clients/client1/web1/tmp:/var/www/domain.com/web:/srv/www/domain.com/web:/usr/share/php5:/usr/share/php:/tmp:/usr/share/phpmyadmin:/etc/phpmyadmin:/var/lib/phpmyadmin:/dev/random:/dev/urandom -d upload_tmp_dir=/var/www/clients/client1/web1/tmp -d session.save_path=/var/www/clients/client1/web1/tmp -d sendmail_path=/usr/sbin/sendmail -t -i -f [email protected]
web1     21804  0.6  0.0 367656 81500 ?        S    05:49   0:02 /opt/php-7.1/bin/php-cgi -d open_basedir=/var/www/clients/client1/web1/web:/var/www/clients/client1/web1/private:/var/www/clients/client1/web1/tmp:/var/www/domain.com/web:/srv/www/domain.com/web:/usr/share/php5:/usr/share/php:/tmp:/usr/share/phpmyadmin:/etc/phpmyadmin:/var/lib/phpmyadmin:/dev/random:/dev/urandom -d upload_tmp_dir=/var/www/clients/client1/web1/tmp -d session.save_path=/var/www/clients/client1/web1/tmp -d sendmail_path=/usr/sbin/sendmail -t -i -f [email protected]
web1     21805  0.4  0.0 291716 80304 ?        S    05:49   0:01 /opt/php-7.1/bin/php-cgi -d open_basedir=/var/www/clients/client1/web1/web:/var/www/clients/client1/web1/private:/var/www/clients/client1/web1/tmp:/var/www/domain.com/web:/srv/www/domain.com/web:/usr/share/php5:/usr/share/php:/tmp:/usr/share/phpmyadmin:/etc/phpmyadmin:/var/lib/phpmyadmin:/dev/random:/dev/urandom -d upload_tmp_dir=/var/www/clients/client1/web1/tmp -d session.save_path=/var/www/clients/client1/web1/tmp -d sendmail_path=/usr/sbin/sendmail -t -i -f [email protected]
web1     21817  0.3  0.0 366944 80224 ?        S    05:49   0:01 /opt/php-7.1/bin/php-cgi -d open_basedir=/var/www/clients/client1/web1/web:/var/www/clients/client1/web1/private:/var/www/clients/client1/web1/tmp:/var/www/domain.com/web:/srv/www/domain.com/web:/usr/share/php5:/usr/share/php:/tmp:/usr/share/phpmyadmin:/etc/phpmyadmin:/var/lib/phpmyadmin:/dev/random:/dev/urandom -d upload_tmp_dir=/var/www/clients/client1/web1/tmp -d session.save_path=/var/www/clients/client1/web1/tmp -d sendmail_path=/usr/sbin/sendmail -t -i -f [email protected]
web1     21818  0.7  0.0 361524 76512 ?        S    05:49   0:02 /opt/php-7.1/bin/php-cgi -d open_basedir=/var/www/clients/client1/web1/web:/var/www/clients/client1/web1/private:/var/www/clients/client1/web1/tmp:/var/www/domain.com/web:/srv/www/domain.com/web:/usr/share/php5:/usr/share/php:/tmp:/usr/share/phpmyadmin:/etc/phpmyadmin:/var/lib/phpmyadmin:/dev/random:/dev/urandom -d upload_tmp_dir=/var/www/clients/client1/web1/tmp -d session.save_path=/var/www/clients/client1/web1/tmp -d sendmail_path=/usr/sbin/sendmail -t -i -f [email protected]
web1     21998  0.8  0.0 369600 85560 ?        S    05:50   0:02 /opt/php-7.1/bin/php-cgi -d open_basedir=/var/www/clients/client1/web1/web:/var/www/clients/client1/web1/private:/var/www/clients/client1/web1/tmp:/var/www/domain.com/web:/srv/www/domain.com/web:/usr/share/php5:/usr/share/php:/tmp:/usr/share/phpmyadmin:/etc/phpmyadmin:/var/lib/phpmyadmin:/dev/random:/dev/urandom -d upload_tmp_dir=/var/www/clients/client1/web1/tmp -d session.save_path=/var/www/clients/client1/web1/tmp -d sendmail_path=/usr/sbin/sendmail -t -i -f [email protected]
web1     22192  3.9  0.0 289668 79848 ?        S    05:53   0:06 /opt/php-7.1/bin/php-cgi -d open_basedir=/var/www/clients/client1/web1/web:/var/www/clients/client1/web1/private:/var/www/clients/client1/web1/tmp:/var/www/domain.com/web:/srv/www/domain.com/web:/usr/share/php5:/usr/share/php:/tmp:/usr/share/phpmyadmin:/etc/phpmyadmin:/var/lib/phpmyadmin:/dev/random:/dev/urandom -d upload_tmp_dir=/var/www/clients/client1/web1/tmp -d session.save_path=/var/www/clients/client1/web1/tmp -d sendmail_path=/usr/sbin/sendmail -t -i -f [email protected]
web1     22193  0.8  0.0 285392 75288 ?        S    05:53   0:01 /opt/php-7.1/bin/php-cgi -d open_basedir=/var/www/clients/client1/web1/web:/var/www/clients/client1/web1/private:/var/www/clients/client1/web1/tmp:/var/www/domain.com/web:/srv/www/domain.com/web:/usr/share/php5:/usr/share/php:/tmp:/usr/share/phpmyadmin:/etc/phpmyadmin:/var/lib/phpmyadmin:/dev/random:/dev/urandom -d upload_tmp_dir=/var/www/clients/client1/web1/tmp -d session.save_path=/var/www/clients/client1/web1/tmp -d sendmail_path=/usr/sbin/sendmail -t -i -f [email protected]
ispconf+ 22268  0.0  0.0 285232 22940 ?        Ss   05:54   0:00 /usr/bin/php-cgi -d disable_classes= -d disable_functions= -d magic_quotes_gpc=off -d open_basedir= -d session.save_path=/usr/local/ispconfig/interface/temp
ispconf+ 22270  0.1  0.0 285528 16064 ?        S    05:54   0:00 /usr/bin/php-cgi -d disable_classes= -d disable_functions= -d magic_quotes_gpc=off -d open_basedir= -d session.save_path=/usr/local/ispconfig/interface/temp
root     22433  0.0  0.0  13216  2172 pts/0    S+   05:55   0:00 grep php
root     24127  0.0  0.0 306300  8952 ?        Ss    2017   0:37 php-fpm: master process (/usr/local/php-7.1.8/etc/php-fpm.conf)
www-data 24128  0.0  0.0 306640  9228 ?        S     2017   0:00 php-fpm: pool www
www-data 24129  0.0  0.0 306300  6980 ?        S     2017   0:00 php-fpm: pool www
www-data 29862  0.0  0.0 213180 19708 ?        S    Jan19   0:04 php-fpm: pool www
www-data 29891  0.0  0.0 213176 21532 ?        S    Jan19   0:04 php-fpm: pool www
www-data 29948  0.0  0.0 211136 17540 ?        S    Jan19   0:03 php-fpm: pool www

TOP :

top - 06:02:08 up 27 days, 17:45,  1 user,  load average: 2.45, 3.20, 2.26
Tasks: 487 total,   1 running, 486 sleeping,   0 stopped,   0 zombie
%Cpu(s): 12.5 us,  3.6 sy,  0.0 ni, 83.4 id,  0.0 wa,  0.0 hi,  0.5 si,  0.0 st
KiB Mem:  13198007+total, 12718466+used,  4795408 free,  2421808 buffers
KiB Swap:  1046520 total,        0 used,  1046520 free. 10000835+cached Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
27655 mysql     20   0 68.220g 0.012t  11640 S 519.8 10.1   3798:47 mysqld
21602 www-data  20   0 2058172  17132   7092 S   0.3  0.0   0:00.77 apache2
(...)

Editar :

Essas consultas do MySQL geram 128,9% de uso da CPU pelo mysqld:

    mysql> show full processlist;
+--------+---------------+-----------+---------------+---------+------+----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Id     | User          | Host      | db            | Command | Time | State                | Info                                                                                                                                                                                 |
+--------+---------------+-----------+---------------+---------+------+----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 284863 | root          | localhost | c1DATABASE | Query   |    0 | NULL                 | show full processlist                                                                                                                                                                |
| 287063 | c1DATABASE | localhost | c1DATABASE | Sleep   |    0 |                      | NULL                                                                                                                                                                                 |
| 287064 | c1DATABASE | localhost | c1DATABASE | Query   |    0 | Sorting result       | SELECT  t.*, tt.* FROM wp_terms AS t  INNER JOIN wp_term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ('post_tag') AND tt.count > 0 ORDER BY tt.count DESC LIMIT 45 |
| 287065 | c1DATABASE | localhost | c1DATABASE | Query   |    1 | Copying to tmp table | SELECT SQL_CALC_FOUND_ROWS  wp_posts.ID FROM wp_posts  WHERE 1=1  AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish')  ORDER BY RAND() LIMIT 0, 10                |
| 287066 | c1DATABASE | localhost | c1DATABASE | Sleep   |    0 |                      | NULL                                                                                                                                                                                 |
+--------+---------------+-----------+---------------+---------+------+----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
5 rows in set (0.00 sec)

2 . Eu atualizei e ajustei as seguintes opções:

FcgidBusyTimeout 3600
FcgidProcessLifeTime 3600
FcgidOutputBufferSize   0

Fontes : link

Documentação do Apache mod_fcgid lista outra possibilidade que o " mod_fcgid: ap_pass_brigade falhou na função handle_request_ipc "pode ocorrer erro, que é devido ao limite de PHP_FCGI_MAX_REQUESTS e / ou FcgidMaxRequestsPerProcess . Os processos do PHP FastCGI saem após o processamento de 500 solicitações, e eles podem sair depois que este módulo já estiver conectado ao aplicativo e enviar a próxima solicitação, resultando no erro "mod_fcgid: ap_pass_brigade failed in handle_request_ipc function".

De acordo com a documentação do mod_fcgid do Apache e esta pergunta , também atualizei as seguintes opções:

FcgidMaxRequestsPerProcess 10000
FcgidInitialEnv PHP_FCGI_MAX_REQUESTS 10000

Fontes : link

Infelizmente, ambos 1 ) e 2 ) não resolveram o meu problema: - / Qualquer conselho de como maximizar o máximo desta máquina (Intel 2x Xeon E5-2630v3 - 16 / 32t - 2.4GHz / 3.2GHz + 128GB DDR4 ECC 1866 MHz RAM) e corrigir o problema com mod_fcgid erros? Felicidades!

    
por Martin Smith 22.01.2018 / 12:37

1 resposta

2

O índice em meta_key está errado, contém apenas 191 dos 255 caracteres possíveis, então o mysql não o usará. Essa é a causa da sua consulta lenta.

link

Essa pessoa (Killer Loop) mudou meta_key em wp_postmeta para 191 caracteres e obteve resultados de 2/10 segundos.

    
por 22.01.2018 / 14:52