ããµã¤ãã¦ãºã»ã¢ããã³ãã«ã¬ã³ãã¼2012ãããæ®ãã¯ä»æ¥ã¨ææ¥ã®ã¿ã§ãï¼ããã¾ã§ã®è¨äºä¸è¦§ï¼ã
ããã«ã¡ã¯ã社å
ã¤ã³ãã©æ
å½ã®ç¨²çã§ããä»åã¯WordPressãµã¼ãã®ç°¡åãªæ¹åæ¹æ³ã¨è² è·ãã¹ãã«ããæ¯è¼ã®ã話ã§ãã
ä¸è¬ã®åç¨ãµã¤ãã§ãå©ç¨å¯è½ãªãWordPressãããµã¤ãã¦ãºã®Webãµã¤ãã§ã CMS ã§ä½¿ã£ãããææ Blog ãµã¼ãã¹ãã移è¡ãããã¨ããã®æ©æµã«ä¸ã£ã¦ãã¾ãããã㪠WordPress ç°å¢ã§ãããæè¿ãµã¼ãã¸ã®è² è·ãé«ãï¼ ã¨ããé£çµ¡ãåãã調æ»ãã¦ãè² è·ãã¹ãã¨ç°å¢æ¹åã«åãçµãã æã®ãã¨ãç´¹ä»ãã¾ãã
â» å ã¿ã«ãµã¼ãé«è² è·ã®åå 㯠WordPress ã¨å ¨ç¶é¢ä¿ããã¾ããã§ããã詳細ã¯æ¬ç¨¿ã®ä¸»æ¨ã¨ç°ãªãããçãã¾ãããæªæã®ååã¨ãããã¨ã§ãWordPress ã¯è¯ãåã§ããã
ãã¹ãç°å¢ãç¨æãã
ãã¹ãç¨ã«ä»¥ä¸ã®ä»®æ³ç°å¢ãç¨æãã¾ããã
CPU | Xeon E5640 x4 |
---|---|
MEM | 4 GB |
HDD | 40 GB |
OS | CentOS 6.3 x64 |
Apache | 2.2.15 |
PHP | 5.3.3 |
MySQL | 5.1.66 |
ããã§ã¯ PHP ã«ã¯ remi ããã±ã¼ã¸ ãå©ç¨ãã¦ãã¾ããå¾è¿°ãã¾ããã php-fpm ã®ããã±ã¼ã¸ãæ¨æºãªãã¸ããªã«ç¡ãããã§ãã WordPress ã®ã¤ã³ã¹ãã¼ã«æ¹æ³ã¯ WordPress Codex æ¥æ¬èªç ã«è¨è¼ã®éãã®æé ã§ãããã®ãã¡ MySQL ã«ã¤ãã¦ã¯ç°å¢ã«åã£ã my.ini è¨å®ãæµç¨ããåæåå¾ InnoDB ã«å¤æ´ãã¾ãã my.ini ã®è¨å®ãµã³ãã«ã¯ /usr/share/doc/mysql-server-5.5.28/
以ä¸ã«å¹¾ã¤ãããã¾ãããããã§ã¯ my-huge.cnf ã /etc/my.ini ã¨ãã¦ã³ãã¼ããInnoDB é¢é£ã®è¨å®ãæå¹ã«ãã¦ç¨ãã¾ããåæåå¾ã® InnoDB å¤æã¯ã以ä¸ã®è¦é ã§å
¨ã¦ã® table ã«å¯¾ãå®æ½ãã¾ãã
mysql -u root -p wordpress Password: mysql> SHOW TABLES; +-----------------------+ | Tables_in_tech | +-----------------------+ | wp_commentmeta | | wp_comments | | wp_links | ... mysql> ALTER TABLE wp_commentmeta ENGINE = InnoDB;
å¤æå¾ã®ç¢ºèªã¯ä»¥ä¸ã®ã³ãã³ãã§ç¢ºèªã§ãã¾ãã
mysql> SHOW TABLE STATUS;
è² è·ãã¹ããã¼ã«ãå©ç¨ãã¦ã¿ã
è² è·ãã¹ããã¼ã«ã¯ãWebè² è·ãã¹ãã§æ¤ç´¢ ããã°è²ã
ã¨è¦ä»ããã¾ããã©ããå©ç¨ãããã«ã¤ãã¦ã¯ãå½ç¶ãªãããã¹ãã±ã¼ã¹ã«å¿ãã¦é¸æãã¹ãã§ãããæ¬ç¨¿ã§ã¯ Apache Bench ã使ã£ã¦ç´ æ©ããæ軽ãªãã¹ããå®æ½ãã¦ã¿ã¾ãããã®ã³ãã³ãã¯ãCentOSã§ã¯ httpd-tools ããã±ã¼ã¸ã«å«ã¾ãã¦ãã¾ãã
使ãæ¹ã®ç°¡åãªèª¬æã¯ä»¥ä¸ã®éãã
ab [ -n requests ] [ -c concurrency ] [http[s]://]hostname[:port]/path
-n: ç·ãªã¯ã¨ã¹ãæ° -c: åæãªã¯ã¨ã¹ãæ°
ab ã¯ãæå®ãããªã¯ã¨ã¹ãæ°ã«éããã¾ã§ã®å¦çæéã®è¨æ¸¬ããè¡ãªããã¹ããã¼ã«ã§ããç¹å®ã® URL ã«å¯¾ãã¦ã²ãããåæã¢ã¯ã»ã¹ãå®æ½ããåç´ãªãã®ã§ãããWeb ãµã¤ãã¸è² è·ããããç®çãªãååã§ããä½ãããµã¼ãã®è² è·ç¶æ³ã確èªããã«ã¯ããã ãã§ã¯å½¹è
ä¸è¶³ããµã¼ãã®è² è·ãè¦ããªããLoadAverage ã Swap ã®æ
å ±ãããã¯è¦ã¦ããããã¨ããã
ã¨ããããã§ãç·ãªã¯ã¨ã¹ãæ°ãå¢ãããªãããµã¼ãã®æ
å ±ãåéãã bash ã¹ã¯ãªãããç°¡åã«æ¸ãã¾ããã
#!/bin/bash C_REQ=50 ## concurrency SVR="wpserver" URL="http://wordpress.cybozu.co.jp/" for req in `seq 50 50 1000`; do flg=1 cnt=0 while [ ${flg} -eq 1 ]; do if [ ${cnt} -ge 5 ]; then echo "Over 5 continued." 2>&1 exit 1 fi logfile="`printf %04d ${req}`_${C_REQ}.log" ssh ${SVR} w > ${logfile} ssh ${SVR} free >> ${logfile} ab -n ${req} -c ${C_REQ} ${URL} >> ${logfile} ssh ${SVR} w >> ${logfile} ssh ${SVR} free >> ${logfile} grep "Failed requests: 0" ${logfile} if [ $? -eq 0 ]; then flg=0 fi sleep 90 ## Interval cnt=$(($cnt+1)) done done exit 0
æ¬æ ¼çãªæ¤æ»ã§ã¯ãªãã®ã§ãab ã«è¨å®ãããªãã·ã§ã³å¤ã¯ãããã¦ã§ãããã¦ããäºã¯ç°¡åã§ãç·ãªã¯ã¨ã¹ãæ°ã50ã1000ã§50ãã¤å¢ãããªãã ab ãå®è¡ããã®åå¾ã§ ssh è¶ãã« w ã³ãã³ã㨠free ã³ãã³ãã§ãªã½ã¼ã¹æ å ±ãåéãã¦ãã¾ããåéãããã°ãã¡ã¤ã«åã¯ãä¾ãã° "0050_50.log" ã®ãããªæããè² è·ã®æãæ¹ã«ãã£ã¦ã¯éä¸ã§ãªã¯ã¨ã¹ãå¦çã«å¤±æããäºãããã¾ããã¹ã¯ãªããã§ã¯é次失æã確èªããæ大5åã¾ã§å試è¡ããããã§ãé§ç®ãªãçµäºãã¾ãã
ãã¹ãçµæãã欲ããæ å ±ãæ½åºãã
ä¸è¨ã¹ã¯ãªããã§åéããçµæã®ãµã³ãã«ã§ããåç´ã«ãwããfreeããabããwããfreeãã®é ã§å®è¡ããçµæã®ç¾ åã«ãªãã¾ãã
09:49:15 up 13:45, 1 user, load average: 0.79, 9.06, 13.03
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
hoge pts/0 10.X.XXX.XX Wed20 13.00s 0.06s 0.02s sshd: hoge [pri
total used free shared buffers cached
Mem: 3924804 755980 3168824 0 132176 104112
-/+ buffers/cache: 519692 3405112
Swap: 2047992 0 2047992
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking wordpress.cybozu.co.jp (be patient).....done
Server Software: Apache
Server Hostname: wordpress.cybozu.co.jp
Server Port: 80
Document Path: /
Document Length: 55719 bytes
Concurrency Level: 50
Time taken for tests: 7.349 seconds
Complete requests: 50
Failed requests: 0
Write errors: 0
Total transferred: 2796600 bytes
HTML transferred: 2785950 bytes
Requests per second: 6.80 [#/sec] (mean)
Time per request: 7348.846 [ms] (mean)
Time per request: 146.977 [ms] (mean, across all concurrent requests)
Transfer rate: 371.63 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 4 6 0.9 6 7
Processing: 1344 5434 2042.5 6396 7342
Waiting: 967 4710 2050.5 5628 7153
Total: 1348 5440 2043.3 6402 7348
Percentage of the requests served within a certain time (ms)
50% 6402
66% 7097
75% 7117
80% 7165
90% 7314
95% 7338
98% 7348
99% 7348
100% 7348 (longest request)
09:49:22 up 13:45, 1 user, load average: 3.32, 9.33, 13.07
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
hoge pts/0 10.X.XXX.XX Wed20 20.00s 0.06s 0.02s sshd: hoge [pri
total used free shared buffers cached
Mem: 3924804 1690408 2234396 0 132260 104132
-/+ buffers/cache: 1454016 2470788
Swap: 2047992 0 2047992
åºåçµæã®è©³ç´°ãªèª¬æã¯å種解説ãµã¤ãããåç §é ãäºã¨ãã¦ãããããè² è·ç¶æ³ãè¦ãããã«ã以ä¸ã®æ å ±ãæ½åºãã¾ãã
- ãªã¯ã¨ã¹ãæ°
- è¨æ¸¬æé(s)
- ç§éå¦çæ°(req/s)
- å¹³åå¦çæé(ms/req)
- Load Average(1m)
- Swap (Byte)
ããã¦ãã¡ããç°¡åã«æ¸ãã¦ã¿ãæ å ±æ½åº&CSVåã¹ã¯ãªããã
# !/bin/bash C_REQ=50 ## åæãªã¯ã¨ã¹ãæ° URL="http://wordpress.cybozu.co.jp/" IFS=" " dir="`dirname ${1}`/`basename ${1}`" if [ ! -d ${dir} ]; then echo "No such directory." 2&>1 exit 1 fi for req in `seq 50 50 1000`; do logfile="`printf %04d ${req}`\_${C\_REQ}.log" grep "Failed requests: 0" ${dir}/${logfile} 2>&1 >/dev/null if [ $? -ne 0 ]; then break fi ## Get time(s) dat=(`grep '[0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}' ${dir}/${logfile} | awk '{print $1;}'`) pre=(`echo ${dat[0]} | awk -F : '{printf("%d\n%d\n%d", $1, $2, $3);}'`) post=(`echo ${dat[1]} | awk -F : '{printf("%d\n%d\n%d", $1, $2, $3);}'`) time=`echo "(${post[0]}*60*60)+(${post[1]}*60)+(${post[2]})-(${pre[0]}*60*60)-(${pre[1]}*60)-(${pre[2]})" | bc` ## Get LoadAverage(1m) dat=(`grep 'load average:' ${dir}/${logfile} | sed -e 's/.*\(load average:.*\)/\1/'`) pre="`echo ${dat[0]} | awk '{print substr($3,0,length($3));}'`" post="`echo ${dat[1]} | awk '{print substr($3,0,length($3));}'`" load_average=`echo "${post} - ${pre}" | bc` ## Get Req/s req_per_s=`grep 'Requests per second:' ${dir}/${logfile} | awk '{print $4;}'` ## Get Req time ms_per_req=`grep 'Time per request:.*(mean)' ${dir}/${logfile} | awk '{print $4;}'` ## Get Swap mem=(`grep '\-/+ buffers/cache' ${dir}/${logfile} | awk '{print $3;}'`) swp=(`grep 'Swap:' ${dir}/${logfile} | awk '{print $3;}'`) swapping=`echo "(${mem[1]}-${mem[0]})+(${swp[1]}-${swp[0]})" | bc` echo "${req}","${time}","${req_per_s}","${ms_per_req}","${load_average}","${swapping}" done exit 0
ãè¨æ¸¬æé(s)ã㯠ab å®è¡åå¾ã® w ã³ãã³ãã®æå»ãç§æ°ã«æç®ããå·®åã§ãããLoad Average(1m)ããSwap(Byte)ãããab å®è¡åå¾ã®å¤ã®å·®åã§åºãã¦ãã¾ããå¾ãããçµæã¯ãExcel ã§ã°ã©ãåããã¨å¤ãæããªãã¾ãã以ä¸ã¯ç´ ã®è¨å®ã§ã®è¨æ¸¬çµæã§ãã
è¨æ¸¬æéã®å¢å ãLoad Averageã®å¢å å ·åãè¦ãéããããã£ã½ãæ å ±ãå¾ããã¦ãã¾ããåææ¥ç¶æ°ã¯50åºå®ãªã®ã§ãSwapããããªãã®ã§ãããã
ç°å¢ãå¤ãã¦ãã¹ããã¦ã¿ã
è² è·ãã¹ãã®æ¹éã決ã¾ã£ãããä»åº¦ã¯ç°å¢æ¹åãå³ãã¾ããæ¬ç¨¿ã§ã¯ç°å¢æ¹åã«å¹æã®ãããã¼ã«ã®å°å
¥æç¡ã§ãã¹ãçµæã®æ¯è¼ããã¾ããã
å°å
¥ãããã¼ã«ã¯ä»¥ä¸ã®éãã§ãã
- APC
- FastCGI
- NGiNX+php-fpm
APC
PHPã®é«éåã«ã¯ãAlternative PHP Cacheãã¨ããã®ãããã¾ãããã¡ãã¯PHPã®ä¸éã³ã¼ãã®ãã£ãã·ã¥ãæé©åããã¦ããããã®ã§ããµã¼ãã«ä»è¾¼ãã ãã§ã¹ã¯ãªããã®å¤æ´ãå¿
è¦ãªãé«éåãããã¹ã°ã¬ã¢ãã§ãã
CentOSã§ã®è¨å®æé ã¯ä»¥ä¸ã®éãã
# yum install pcre-devel
# pear install pecl/APC
...
# vi /etc/php.d/apc.ini
----------
[apc]
extension=apc.so
----------
# service httpd restart
å°å ¥ç¢ºèªã¯ä»¥ä¸ã®éãã
# php -i | grep apc
...
apc.enabled => On => On
...
ä¸æçã«APCãå¤ãããå ´åã¯ã/etc/php.d/apc.ini ãä½å¦ãã«éé¿ã㦠Apache åèµ·åã§OKã
FastCGI
CGI ã¯ãªã¯ã¨ã¹ãæ¯ã«ããã»ã¹ã®çæã¨ç ´æ£ãè¡ãªããã¾ããããããããã¡ã¢ãªä¸ã§å¾
ã¡åãã¦ããã®ãªã¼ãã¼ãããã軽æ¸ããä»çµã¿ã FastCGI ã§ãã
CentOSã§ã®è¨å®æé ã¯ä»¥ä¸ã®éããEPELããã±ã¼ã¸ ãå©ç¨ã§ãããããyumãªãã¸ããªã追å ãã¦ããã¦ãã ããã
# yum install --enablerepo=epel fcgi mod_fcgid
# vi /etc/httpd/conf.d/fcgid.conf
----------
AddType text/html .php
DirectoryIndex index.php
FcgidMaxRequestLen 134217728
----------
# mv /etc/httpd/conf.d/php.conf /etc/httpd/conf.d/php.conf.disable
# vi /etc/httpd/conf/httpd.conf
----------
...
<VirtualHost *:80>
...
<Directory "/var/www/html/wordpress.cybozu.co.jp">
<IfModule mod_fcgid.c>
Options FollowSymLinks Includes ExecCGI
AddHandler fcgid-script .php
FCGIWrapper /usr/bin/php-cgi .php
</IfModule>
...
</Directory>
</VirtualHost>
----------
# service httpd restart
å°å ¥ç¢ºèªã¯ä»¥ä¸ã®éãã
# ps -ef | grep php
apache 19643 19339 3 19:03 ? 00:01:30 /usr/bin/php-cgi
...
ä¸æçã« FastCGI ãå¤ãããå ´å㯠fcgid.conf ã fcgid.conf.disable ãªã©ã«æ¹åã㦠Apache åèµ·åã§OKã
NGiNX + php-fpm
å°ãæ¯è²ãå¤ãã¾ãã¦ãWeb ãµã¼ãã Apache ãã NGiNX ã«å¤æ´ãã¦ã¿ã¾ããããã¡ã㯠Apache ããã軽éãã¤å¿
è¦ååãªæ©è½ãæãã Web ãµã¼ãã§ãWordPress ã®åä½äºä¾ãè±å¯ã§ãã
CentOSã§ã®è¨å®æé ã¯ä»¥ä¸ã®éãã
#vi /etc/yum.repos.d/
----------
[nginx]
name=nginx
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=0
----------
# vi install --enablerepo=nginx
ããã ãã§ã¯PHPãåä½ããªãã®ã§ãããã¯ã¨ã³ãCGIã¨ãã¦remiããã±ã¼ã¸ãã php-fpm ãã¤ã³ã¹ãã¼ã«ãã¾ãã
# yum install --enablerepo=remi php-fpm
php-fpm ã¯è¯ãã¨ãã¦ãNGiNX 㯠WordPress åãã«è¨å®ãè¡ãªãå¿
è¦ãããã¾ãããã¡ãã¯é·ããªãã¾ãã®ã§ã詳ãã㯠WordPress Codex æ¥æ¬èªç ããåç
§ãã ããã/etc/nginx/conf.d/
以ä¸ã« restrictions.conf ããã³ wordpress.conf ãä¿åãã¦ã/etc/nginx/sites-enabled/
以ä¸ã«ãµã¤ããã¡ã¤ã³æ¯ã® conf ãã¡ã¤ã«ãç¨æããã® server ãã£ã¬ã¯ãã£ãå
㧠/etc/nginx/conf.d/
以ä¸ã® conf ãã¡ã¤ã«ãèªã¿è¾¼ãããã«ãã¾ãã
æå¾ã«ãµã¼ãã¹ãèµ·åãã¾ãããã Apache ãåãã¦ããå ´åã¯ãå¿ ãåæ¢ãã¦ãã ããã
# service php-fpm start
# service nginx start
ã¾ãããã¡ãã®ç°å¢ã§ã APC ãå©ç¨å¯è½ã§ããåè¿°åæ§ /etc/php.d/apc.ini ã®æç¡ã§è¨å®ããåæ å¾ã¯ php-fpm ãµã¼ãã¹ã®åèµ·åãè¡ãªãã¾ãã
ãã¹ãçµæ
Apache ç°å¢ã« APC ãå°å ¥ããå ´åã¨ãFastCGI ãå°å ¥ããå ´åã§ã®æ¯è¼ããã¦ã¿ã¾ããã
APCå°å ¥ã«ãããLoad Averageã¨å¦çæéãä¸ãã£ã¦ãã¾ãããªã¯ã¨ã¹ãã®å¹³åå¦çæéãªã©ã1000ãªã¯ã¨ã¹ãã§ã®çµæãè¦ãã¨2ç§è¿ãå·®ãåºã¾ãããPHPã®ä¸éã³ã¼ããã£ãã·ã¥ã¯é«éåã¨è² è·è»½æ¸ã®ä¸¡æ¹ã«æå¹ã ã¨è§£ãã¾ãã FastCGI å°å ¥ã§ããå¦çé度ã®æ¹åã«è¥å¹²ã®å¹æãããããã§ããSwapãä¸ãã£ã¦ããã®ãå°ãä¸æè°ã§ããããã¹ãå 容ãåä¸ãªã¯ã¨ã¹ãã®ç¹°ãè¿ãã§ããäºã¨ãã¡ã¢ãªå ±æãå¹ãã¦ããã®ããç¥ãã¾ããã
次㫠Apache ç°å¢ã¨ NGiNX ç°å¢ã¨ã®æ¯è¼ããã¦ã¿ã¾ããã
NGiNX ç°å¢ã¯ +php-fpm ãªã®ã§ãä¼¼ãç°å¢ã¨ã㦠Apache + FastCGI ç°å¢ã¨æ¯è¼ãã¦ãã¾ã(å³å¯ã«ã¯ç°ãªãã¾ã)ãã¤ãã§ã« APC ã®æç¡ã§ãæ¯è¼ãã¦ã¿ã¾ãããSwap ãå¥ã«ããã¨ãçµæã¨ãã¦ã¯ãã¾ãå·®ãç¡ããããªâ¦â¦ãããããå ã¯è¨å®ã®ãã¥ã¼ãã³ã°ãå¿ è¦ã«ãªãããã§ãã
æå¾ã«
æ¬ç¨¿ã§ã¯ãWordPress ã®ç°å¢æ¹åã«ãããããã®æ§è½å·®ãç°¡åãªè² è·ãã¹ãã«ã¦æ¯è¼ãã¾ãããããã«æãã以å¤ã«ãè¨å®å ¨ä½ã®ãã¥ã¼ãã³ã°ãETag ãããã¹ãå§ç¸®ãªã©ã®éä¿¡éåæ¸ãWordPress ãã©ã°ã¤ã³ã§ã®ãã£ãã·ã¥è¨å®ãªã©æ¹åãé«éåã¯ã¾ã ã¾ã 沢山ããã¾ãããé·ããªãã¾ãã®ã§å²æã
æ¬ç¨¿ã®ãã¹ãæ¹æ³ã§ã¯å®éã®ã¢ã¯ã»ã¹ãæ³å®ãã試é¨ããåæã¢ã¯ã»ã¹ã®éçå¤ãå³ãäºã¯åºæ¥ã¾ãããã§ããããããã¼ã«ãè¨å®ã«å¯¾ããå¹æããããã©ãããæ¤è¨¼ããç¨åº¦ã«ã¯æç¨ã§ãåæ¨é¸æã®æéã¨ããã«ã¯ååã§ãã
ç
©éãªè¨å®ã¯åãæ¢ãããå°å
¥ããã ãã§ãå¹æã®ãããã¼ã«ã¯å¤ã
ããã¾ããç°¡åã§å¹æã®é«ããã®ããæ軽ãªæ¹æ³ã§æ¤è¨¼ãåæ¨é¸æããã®ãããµã¼ãç°å¢æ¹åã®å¹ççãªæ¹æ³ã ã¨æãã¾ãã
ææ¥ã¯ããµã¤ãã¦ãº Office on cybozu.com ã§ã·ã³ã¿ãã¯ã¹ãã¤ã©ã¤ããå®ç¾ããæ¹æ³ãããéããã¾ããã楽ãã¿ã«ã