【AmazonLinux】HHVMでWordPressを超高速化

インストール

参考 HHVMGitHub

Gitやウェブに乗っているやり方では無理だったので少し変えました。

また、署名がないのでオプションで–nogpgcheckを付けました。

以下を実行するとhhvmと依存関係がすべてダウンロードされます。

HHVMインストール
## Add opsrock-hhvm-depends
cat <<'EOL' > /etc/yum.repos.d/opsrock-hhvm-depends.repo
[opsrock-hhvm-depens]
name=Opsrock hhvm depends for Amazon Linux Repository
baseurl=https://packagecloud.io/opsrock-hhvm/hhvm-depends/el/6/$basearch
enabled=1
gpgcheck=1
gpgkey=https://packagecloud.io/gpg.key
includepkgs=glog,tbb
sslverify=true
EOL

## Add OpsRock
cat <<'EOL' > /etc/yum.repos.d/opsrock-hhvm.repo
[opsrock-hhvm]
name=Opsrock hhvm for Amazon Linux Repository
baseurl=https://packagecloud.io/opsrock-hhvm/hhvm-stable2/el/6/$basearch
enabled=1
gpgcheck=1
gpgkey=https://packagecloud.io/gpg.key
includepkgs=hhvm
sslverify=true
EOL

yum -y --disablerepo=amzn-main --nogpgcheck install tbb
yum -y --nogpgcheck install hhvm

インストールパッケージはtbbと以下の通りです。

依存関係パッケージ
Installing:
hhvm x86_64 3.12.12-1.amzn1 opsrock-hhvm 19 M
Installing for dependencies:
boost x86_64 1.53.2-14.23.amzn1 amzn-updates 33 k
boost-atomic x86_64 1.53.2-14.23.amzn1 amzn-updates 34 k
boost-chrono x86_64 1.53.2-14.23.amzn1 amzn-updates 43 k
boost-context x86_64 1.53.2-14.23.amzn1 amzn-updates 35 k
boost-date-time x86_64 1.53.2-14.23.amzn1 amzn-updates 68 k
boost-filesystem x86_64 1.53.2-14.23.amzn1 amzn-updates 104 k
boost-graph x86_64 1.53.2-14.23.amzn1 amzn-updates 253 k
boost-iostreams x86_64 1.53.2-14.23.amzn1 amzn-updates 90 k
boost-locale x86_64 1.53.2-14.23.amzn1 amzn-updates 300 k
boost-math x86_64 1.53.2-14.23.amzn1 amzn-updates 859 k
boost-program-options x86_64 1.53.2-14.23.amzn1 amzn-updates 309 k
boost-python x86_64 1.53.2-14.23.amzn1 amzn-updates 251 k
boost-random x86_64 1.53.2-14.23.amzn1 amzn-updates 38 k
boost-regex x86_64 1.53.2-14.23.amzn1 amzn-updates 823 k
boost-serialization x86_64 1.53.2-14.23.amzn1 amzn-updates 369 k
boost-signals x86_64 1.53.2-14.23.amzn1 amzn-updates 90 k
boost-system x86_64 1.53.2-14.23.amzn1 amzn-updates 39 k
boost-test x86_64 1.53.2-14.23.amzn1 amzn-updates 486 k
boost-thread x86_64 1.53.2-14.23.amzn1 amzn-updates 60 k
boost-timer x86_64 1.53.2-14.23.amzn1 amzn-updates 42 k
boost-wave x86_64 1.53.2-14.23.amzn1 amzn-updates 458 k
gcc48-c++ x86_64 4.8.5-11.135.amzn1 amzn-main 9.8 M
gd x86_64 2.0.35-11.10.amzn1 amzn-main 155 k
glog x86_64 0.3.3-2.amzn1 opsrock-hhvm-depens 288 k
libc-client x86_64 2007e-11.6.amzn1 amzn-main 632 k
libdwarf x86_64 20130207-3.3.amzn1 amzn-main 117 k
libmemcached x86_64 1.0.16-5.8.amzn1 amzn-main 271 k
libstdc++48 x86_64 4.8.5-11.135.amzn1 amzn-main 403 k
oniguruma x86_64 5.9.1-3.1.2.amzn1 amzn-main 149 k
unixODBC x86_64 2.2.14-14.7.amzn1 amzn-main 483 k

 

設定

/etc/hhvm/server.ini
;; See: https://github.com/facebook/hhvm/wiki/INI-Settings

;; JIT Settings
hhvm.jit = true

;; common options
hhvm.pid_file = /var/tmp/hhvm.pid
hhvm.server.user = nobody
hhvm.log.use_log_file = true
hhvm.log.file = /var/log/hhvm/error.log
hhvm.log.header = true
hhvm.repo.central.path = /tmp/.hhvm.hhbc

;; listner options
;;; port and socket have exclusive relationship.
;hhvm.server.port = 9001
hhvm.server.file_socket = /var/tmp/hiphop-php.sock

;;; please update 2 * number of CPUs
hhvm.server.thread_count = 2

; server mode options
hhvm.server.type = fastcgi
hhvm.server.default_document = index.php

;; php options
;;; hhvm specific
hhvm.log.level = Warning
hhvm.log.always_log_unhandled_exceptions = true
hhvm.log.runtime_error_reporting_level = 8191
hhvm.mysql.typed_results = false

hhvm.server.source_root = (ここにドキュメントルートを入れてください ex. /var/www/html/wordpress/など)
hhvm.server.user = nginx
hhvm.log.header = true

 

ソケットの変更(/etc/nginx/nginx.conf)
#server unix:/var/run/php-fpm.sock;
server unix:/var/tmp/hiphop-php.sock;

再起動

service php-fpm stop
service hhvm start
service nginx restart

戻す方法

ソケットを戻して以下を実行

service hhvm stop
service php-fpm start
service nginx restart

ベンチマーク

Apache Benchでの計測です。

php-fpmのベンチマーク
Concurrency Level: 100
Time taken for tests: 61.489 seconds
Complete requests: 500
Failed requests: 0
Total transferred: 12188500 bytes
HTML transferred: 12080000 bytes
Requests per second: 8.13 [#/sec] (mean)
Time per request: 12297.845 [ms] (mean)
Time per request: 122.978 [ms] (mean, across all concurrent requests)
Transfer rate: 193.58 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 51 234 232.1 138 1443
Processing: 598 10914 2838.4 12062 12926
Waiting: 553 10907 2839.4 12059 12829
Total: 791 11148 2734.5 12220 13623

 

HHVMのベンチマーク
Concurrency Level: 100
Time taken for tests: 31.546 seconds
Complete requests: 500
Failed requests: 0
Total transferred: 12214000 bytes
HTML transferred: 12080000 bytes
Requests per second: 15.85 [#/sec] (mean)
Time per request: 6309.202 [ms] (mean)
Time per request: 63.092 [ms] (mean, across all concurrent requests)
Transfer rate: 378.11 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 89 248 222.3 153 1216
Processing: 540 5637 2510.8 4334 13788
Waiting: 352 5630 2510.1 4321 13788
Total: 738 5885 2626.8 4484 14001

 

2倍の性能向上が見られましたので、良いと思います。

最近だとPHP7.2がめちゃ早いのでなんとも言えませんが、変わり種が欲しい方は試してみていいんじゃないんですかね。

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です