たんたんめん日記

ソシャゲ関連のなんでもやさん備忘録

【PHP】Hip-Hop vm を試してみた

https://www.facebook.com/notes/facebook-engineering/the-hiphop-virtual-machine/10150415177928920 の記事を発見。

「そういや、そんなんあったなー。」 と、思いながら、リンクを辿って行くと

https://github.com/facebook/hiphop-php/wiki/HHVM-Pre-built-packages-for-Centos-6.4
CentOSへのインストール方法の解説が。

なんか、案外簡単に試すことが出来そうです。
ということで、vagrantに環境作って動かしてみました。

ひとまず、wordpressを動かしてみようじゃないかということで、 こちらを参考にさせて頂き、作業してみました。


HipHopのインストール

上のCentOSへのインストール方法そのままにインストール。

# yum install http://ftp.riken.jp/Linux/fedora/epel/6/i386/epel-release-6-8.noarch.rpm

# cd /etc/yum.repos.d

# wget http://www.hop5.in/yum/el6/hop5.repo

mysqlが5.1とか入っちゃうので、remiから5.5をインストール。気分的な問題かも。

# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
# yum install -y perl-DBD-MySQL libaio libaio-devel openssl-devel
# yum --enablerepo=remi --disablerepo=updates,base install mysql mysql-server mysql-devel

WordPress設置

ずぼらにrootで放り込みます。

# mkdir /var/www
# cd /var/www
# wget http://ja.wordpress.org/wordpress-3.6.1-ja.tar.gz
# tar xvzf wordpress-3.6.1-ja.tar.gz 

# cd wordpress
# cp wp-config-sample.php wp-config.php 

データベース設定

設定前にmysqlの初期化、DBの作成と、ユーザーの追加を行っておきます。

vim /var/www/wordpress/wp-config.php

define('DB_NAME', 'wpdata');

define('DB_USER', 'dbmanager');

define('DB_PASSWORD', 'dbmanagerpass');


hhvmの設定

設定ファイルを新規作成。こちらの参考記事を元に作成しました。

vim /etc/hhvm.hdf

Server {
  Port = 80
  SourceRoot = /var/www/wordpress
}


VirtualHost {
  * {
    Pattern = .*
    RewriteRules {
      dirindex {
        pattern = ^/(.*)/*$
        to = $1/index.php
        qsa = true
      }
    }
  }
}

StaticFile {
  Extensions {
    css = text/css
    gif = image/gif
    html = text/html
    jpe = image/jpeg
    jpeg = image/jpeg
    jpg = image/jpeg
    png = image/png
    tif = image/tiff
    tiff = image/tiff
    txt = text/plain
  }
}

パスの正規表現がイケてないな…


サーバー起動

# hhvm --mode  daemon --config /etc/hhvm.hdf

これでWebサーバーも立ち上がっているので、/wp-admin/install.phpにアクセスしてwordpressの初期設定を行っておきます。


比較用のapache/phpをインストール

ベンチマーク取ってみたいので、比較用にapache環境もインストール

# yum install -y  pcre-devel
# yum install httpd php php-devel php-pear php-mysql 

インストールされたものは↓な感じです

# yum list httpd php php-devel php-pear php-mysql 
httpd.x86_64                                    2.2.15-29.el6.centos                                 @updates
php.x86_64                                      5.3.3-23.el6_4                                       @updates
php-devel.x86_64                                5.3.3-23.el6_4                                       @updates
php-mysql.x86_64                                5.3.3-23.el6_4                                       @updates
php-pear.noarch                                 1:1.9.4-4.el6                                        @base   

apcもインストール

# pecl install APC

httpd.confを編集

vim /etc/httpd/conf/httpd.conf

DocumentRoot "/var/www/html"
↓
DocumentRoot "/var/www/wordpress"

php.iniを編集

vim /etc/php.ini

;date.timezone = 
↓
date.timezone = Asia/Tokyo

追加
↓
extension=apc.so

負荷テスト

手元のMBAからabで。

apapche編

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 192.168.xx.xx (be patient).....done


Server Software:        Apache/2.2.15
Server Hostname:        192.168.xx.xx
Server Port:            80

Document Path:          /?p=5
Document Length:        11297 bytes

Concurrency Level:      10
Time taken for tests:   6.220 seconds
Complete requests:      100
Failed requests:        0
Write errors:           0
Total transferred:      1151400 bytes
HTML transferred:       1129700 bytes
Requests per second:    16.08 [#/sec] (mean)
Time per request:       622.008 [ms] (mean)
Time per request:       62.201 [ms] (mean, across all concurrent requests)
Transfer rate:          180.77 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       0
Processing:   365  615  56.7    612     791
Waiting:      353  487  42.5    481     652
Total:        365  615  56.7    613     791

Percentage of the requests served within a certain time (ms)
  50%    613
  66%    633
  75%    644
  80%    652
  90%    677
  95%    711
  98%    760
  99%    791
 100%    791 (longest request)


hiphop編

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 192.168.xx.xx (be patient).....done


Server Software:        
Server Hostname:        192.168.xx.xx
Server Port:            80

Document Path:          /?p=5
Document Length:        11297 bytes

Concurrency Level:      10
Time taken for tests:   2.237 seconds
Complete requests:      100
Failed requests:        0
Write errors:           0
Total transferred:      1144400 bytes
HTML transferred:       1129700 bytes
Requests per second:    44.69 [#/sec] (mean)
Time per request:       223.748 [ms] (mean)
Time per request:       22.375 [ms] (mean, across all concurrent requests)
Transfer rate:          499.48 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       1
Processing:   104  221  32.1    225     288
Waiting:      102  210  32.2    211     280
Total:        104  221  32.1    226     288

Percentage of the requests served within a certain time (ms)
  50%    226
  66%    236
  75%    240
  80%    242
  90%    260
  95%    269
  98%    280
  99%    288
 100%    288 (longest request)

3倍近く? apacheのチューニングを全くしていないからかもですが、結構差が出ました。

参考サイトでは、メディアのアップロードが出来ないとのことでしたが、 試してみたところ問題なくアップロード出来ました。
修正されたんでしょうかね、、、


業務で使うには、まだまだ怖いですが、このパフォーマンスはなかなかに魅力的です!