WordPress 사이트와 캐시되지 않은 페이지의 웹 서버 성능 저하 원인을 추적하는 데 문제가 있습니다.
서버 운영 체제: Debian 8 "Jesssie"-Linux 버전 4.9.58-xxxx-std-ipv6-64([이메일 보호됨]) (gcc 버전 6.3.0 20170516 (Debian 6.3.0-18) ) #1 SMP Mon Oct 23, 2017 11:35:59 CEST (ISP 구성)
네트워크 서버:서버 버전: Apache/2.4.10(Debian)
PHP(기본값): PHP 7.0.26
PHP(선택): PHP 버전 7.1.8
프로세서: Intel 2x Xeon E5-2630v3 - 16/32t - 2.4GHz /3.2GHz
메모리: 128GB DDR4 ECC 1866MHz
디스크:SoftRaid 2x450GB SSD NVMe
Apache2.conf:
Timeout 300
KeepAlive On
MaxKeepAliveRequests 300
KeepAliveTimeout 5
서버 상태(지난 40분):
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)
서버 MPM: 직원:
<IfModule mpm_worker_module>
StartServers 10
MinSpareThreads 25
MaxSpareThreads 400
ThreadLimit 64
ThreadsPerChild 25
MaxRequestWorkers 500
MaxConnectionsPerChild 0
</IfModule>
내 cnf(마이SQL):
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>
(...)
질문:
주문을 접수합니다워드프레스 웹사이트이 기계에. (32) 사이트가 개발 중이고 사용자가 저뿐임에도 가끔 오류가 나타날 수 있습니다. 현재 하루에 약 5000명의 순 방문자가 있습니다(https://domain.com) 그리고 내오류 기록다음을 포함하여 여러 (104), (9) 및 (32) 오류가 표시됩니다.
(...)
(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
(...)
가장 일반적인 오류는 다음과 같습니다.
(32)Broken pipe: [client: XXX.XX.XX.XX:XXXX] mod_fcgid: ap_pass_brigade failed in handle_request_ipc function
이 오류는 모든 방문의 5%-10%에서 발생한다고 말하고 싶습니다. 이는 내 페이지의 대부분이 캐시되어 있기 때문에 현재로서는 낮은 수치입니다. 내 웹사이트가 날마다 더 많은 조회수를 얻고 있고 점점 더 많은 방문자가 가입하여 "검색" 옵션을 사용하거나 동적 콘텐츠로 인해 캐시되지 않는 "태그" 링크를 클릭하고 있기 때문에 이것이 걱정되기 시작했습니다. .
제가 관찰한 바에 따르면 이러한 오류의 대부분은 PHP가 실행 중일 때 발생합니다. 테스트를 위해 약 20개의 게시물을 탭으로 열고 '수정' 버튼을 클릭했습니다. 이로 인해 오류 (104), (9) 및 (32)가 발생합니다. (32)는 방문자가 검색할 때도 나타납니다. 전체적으로 WordPress에는 약 500,000개의 게시물이 있습니다.
내가 그걸 고치려고 뭘 했는지(성공하지 못했습니다): 1. 나는 출신PHP-FPM도착하다빠른 CGI탭에서 게시물 20개를 열고 "편집" 버튼을 클릭하세요. error.log에 오류가 계속 나타나고 게시물이 로드되지 않고 브라우저에 "사용 가능한 소켓을 기다립니다."(캐시된 페이지는 매우 빠르게 실행됩니다.).
보조 | 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 - 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
(...)
편집하다:
이러한 MySQL 쿼리로 인해 mysqld는 128.9%의 CPU 사용량을 생성했습니다.
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. 다음 옵션을 업데이트하고 조정했습니다.
FcgidBusyTimeout 3600
FcgidProcessLifeTime 3600
FcgidOutputBufferSize 0
아파치 mod_fcgid 문서또 다른 가능성 나열"mod_fcgid: ap_pass_brigade가 handler_request_ipc 함수에서 실패했습니다." 제한사항으로 인해 오류가 발생할 수 있습니다.PHP_FCGI_MAX_REQUESTS그리고/또는프로세스당 FcgidMaxRequests. PHP FastCGI는 500개의 요청을 처리한 후 종료를 처리하며, 모듈이 애플리케이션에 연결되고 다음 요청을 보낸 후에 종료될 수 있으며, 이로 인해 "mod_fcgid: ap_pass_brigade가 handler_request_ipc 함수에서 실패했습니다." 오류가 발생합니다.
Apache mod_fcgid 문서와 이 문서에 따르면질문, 다음 옵션도 업데이트했습니다.
FcgidMaxRequestsPerProcess 10000
FcgidInitialEnv PHP_FCGI_MAX_REQUESTS 10000
불행하게도 둘 다1) 그리고2) 내 문제를 해결하지 못했습니다 :-/ 이 시스템(Intel 2x Xeon E5-2630v3 - 16/32t - 2.4GHz/3.2GHz + 128GB DDR4 ECC 1866 MHz RAM)을 최대한 활용하고 문제를 해결하는 방법에 대한 제안mod_fcgid실수? 건배!
답변1
Meta_key의 인덱스가 잘못되었습니다. 가능한 문자 255개 중 191개만 포함되어 있으므로 mysql은 이를 사용하지 않습니다. 이것이 바로 쿼리가 느린 이유입니다.
https://stackoverflow.com/questions/37675274/wordpress-query-slow-with-many-posts-and-custom-fields
이 사람(Killer Loop)은 wp_postmeta의 Meta_key를 191자로 변경하고 2/10초 안에 결과를 얻었습니다.