HipHop for PHPをインストールしてみた
Facebookが開発したPHPからC++に変換するツール「HipHop for PHP」をインストールしてみた。
インストール
極力yumで入れる。
# install php 5.2 yum -y install apr apr-util gmp yum -y install --enablerepo=c5-testing --disablerepo=base,updates php php-cli php-common php-mbstring php-pear python-devel # install dependency yum -y install --enablerepo=rpmforge cmake gcc-c++ gcc44 gcc44-c++ flex bison re2c mysql mysql-devel libxml2 libxml2-devel libmcrypt libmcrypt-devel php-mcrypt openssl binutils binutils-devel libcap libcap-devel gd zlib bzip2 bzip2-libs bzip2-devel pcre pcre-devel expat expat-devel gd gd-devel openldap openldap-devel readline readline-devel libc-client libc-client-devel ncurses ncurses-devel pam pam-devel # install tbb cd /usr/local/src/ wget http://www.threadingbuildingblocks.org/uploads/78/146/2.2%20update%202/tbb22_012oss_lin.tgz tar -xvf tbb22_012oss_lin.tgz mv tbb22_012oss /usr/local/ export TBB_INSTALL_DIR="/usr/local/tbb22_012oss" export TBB_ARCH_PLATFORM="intel64/cc4.1.0_libc2.4_kernel2.6.16.21" # install libmbfl yum -y install libtool git clone git://github.com/scottmac/libmbfl.git cd libmbfl/ ./buildconf ./configure make make install # install oniguruma cd /usr/local/src/ wget http://www.geocities.jp/kosako3/oniguruma/archive/onig-5.9.2.tar.gz tar -xvf onig-5.9.2.tar.gz cd onig-5.9.2 ./configure make make install # download hiphop cd /usr/local/src/ git clone git://github.com/facebook/hiphop-php.git # install libcurl cd /usr/local/src/ wget http://curl.haxx.se/download/curl-7.20.0.tar.bz2 tar -xvf curl-7.20.0.tar.bz2 cp hiphop-php/src/third_party/libcurl.fb-changes.diff curl-7.20.0/ cd curl-7.20.0 sed -i 's/curl-old\///g' libcurl.fb-changes.diff sed -i 's/curl-new\///g' libcurl.fb-changes.diff patch -p0 < libcurl.fb-changes.diff ./configure --with-ssl --with-zlib --with-libidn --enable-sspi --enable-ldap --enable-ldaps make make install # install libevent cd /usr/local/src/ wget http://monkey.org/~provos/libevent-1.4.13-stable.tar.gz tar -xvf libevent-1.4.13-stable.tar.gz cp hiphop-php/src/third_party/libevent-1.4.13.fb-changes.diff libevent-1.4.13-stable/ cd libevent-1.4.13-stable sed -i 's/libevent-1.4.13-stable\///g' libevent-1.4.13.fb-changes.diff sed -i 's/libevent-1.4.13-stable-fb\///g' libevent-1.4.13.fb-changes.diff patch -p0 < libevent-1.4.13.fb-changes.diff ./configure make make install # install memcached cd /usr/local/src/ wget http://packages.sw.be/perl-Net-SSLeay/perl-Net-SSLeay-1.36-1.el5.rfx.i386.rpm yum -y install perl-Net-SSLeay-1.36-1.el5.rfx.i386.rpm yum -y install --enablerepo=rpmforge memcached # install libmemcache cd /usr/local/src/ wget http://download.tangent.org/libmemcached-0.43.tar.gz tar -xvf libmemcached-0.43.tar.gz cd libmemcached-0.43 ./configure make make install # install libicu cd /usr/local/src/ wget http://download.icu-project.org/files/icu4c/4.2.1/icu4c-4_2_1-src.tgz tar xvf icu4c-4_2_1-src.tgz cd icu/source chmod +x runConfigureICU configure install-sh ./runConfigureICU Linux gmake gmake install # install boost cd /usr/local/src/ wget 'http://downloads.sourceforge.net/project/boost/boost/1.45.0/boost_1_45_0.tar.bz2?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fboost%2Ffiles%2Fboost%2F1.45.0%2F&ts=1293050553&use_mirror=jaist' tar -xvf boost_1_45_0.tar.bz2 cd boost_1_45_0 export CC=gcc44 export CXX=g++44 ./bootstrap.sh --prefix=/usr/local ./bjam ./bjam --prefix=/usr/local install # install hiphop cd /usr/local/src/ cd hiphop-php/ export HPHP_HOME=`pwd` export HPHP_LIB=`pwd`/bin export CC=gcc44 export CXX=g++44 cmake . make make install
コンパイル
ただechoするだけじゃつまらないし、前に作ったHTTP_OAuthProviderのサンプルを動かしてみた。
/usr/local/srcに置きっぱなしなのは、とりあえず気にしない。
# /usr/local/src/hiphop-php/src/hphp/hphp `find . -name '*.php'` --keep-tempdir=1 --log=3 --include-path=. --include-path=/usr/share/pear running hphp... creating temporary directory /tmp/hphp_DGs7aM ... parsing inputs... parsing inputs took 0'00" (83 ms) wall time pre-optimizing... pre-optimizing took 0'00" (100 ms) wall time inferring types... inferring types took 0'00" (40 ms) wall time post-optimizing... post-optimizing took 0'00" (17 ms) wall time creating CPP files... creating CPP files took 0'00" (339 ms) wall time saving code errors... compiling and linking CPP files... compiling and linking CPP files took 4'21" (261282 ms) wall time all files saved in /tmp/hphp_DGs7aM ... running hphp took 4'22" (262053 ms) wall time
サーバ起動
動いた。
# /tmp/hphp_DGs7aM/program -m server mapping self... mapping self took 0'04" (4334 ms) wall time loading static content... loading static content took 0'00" (0 ms) wall time page server started admin server started all servers started
気をつける点
カレントディレクトリ以外から読み込むライブラリ(Pearとか)で、FactoryMethodパターンとか使って、includeしようとしてるPHPファイルをis_file()してると必ずfalseが返ってしまう。(拡張子がcppだから)
実際にアクセスしてみると、コンソールにログが出てる。
HipHop Notice: Tried to invoke /usr/share/pear/HTTP/OAuthProvider/Store/CacheLite.php but file not found.
使えない関数
get_magic_quotes_runtime
set_magic_quotes_runtime
eval
(set|get)_magic_quotes_runtimeは、Pearでよく使われてるから、Pearのライブラリの中身をいじる必要がありそう。
最初思ってたよりは面倒臭くなさそうだけど、手直しは必要なレベル。
ベンチマーク
ABでhttp://127.0.0.1/consumer_http_oauthconsumer.phpへリクエストを行う。
consumer_http_oauthconsumer.phpは、3legged_request.phpに対してHTTPリクエストを行う。
3legged_request.phpは、認証チェックしてリクエストトークンを発行する。
Apacheの方が遥かに速い…!
OAuth認証の場合、Cで実装された関数を大量に使ってるからなのかも。
SmartyとかViewを含んだ普通のWebアプリケーションなら速いのかも。
あとはポートを待ち受けてるプログラムの差なのかも。
それにしても4倍とは、これいかに。
HipHop for PHP
# ab -n 1000 -c 100 http://127.0.0.1/consumer_http_oauthconsumer.php This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0 Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Copyright 2006 The Apache Software Foundation, http://www.apache.org/ Benchmarking 127.0.0.1 (be patient) Completed 100 requests Completed 200 requests Completed 300 requests Completed 400 requests Completed 500 requests Completed 600 requests Completed 700 requests Completed 800 requests Completed 900 requests Finished 1000 requests Server Software: Server Hostname: 127.0.0.1 Server Port: 80 Document Path: /consumer_http_oauthconsumer.php Document Length: 519 bytes Concurrency Level: 100 Time taken for tests: 95.260325 seconds Complete requests: 1000 Failed requests: 980 (Connect: 0, Length: 980, Exceptions: 0) Write errors: 0 Total transferred: 664794 bytes HTML transferred: 351794 bytes Requests per second: 10.50 [#/sec] (mean) Time per request: 9526.032 [ms] (mean) Time per request: 95.260 [ms] (mean, across all concurrent requests) Transfer rate: 6.81 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 2 8.7 0 38 Processing: 18 9382 2001.9 10003 10073 Waiting: 16 9380 2001.6 10001 10073 Total: 32 9385 1997.4 10003 10098 Percentage of the requests served within a certain time (ms) 50% 10003 66% 10011 75% 10017 80% 10020 90% 10036 95% 10052 98% 10064 99% 10073 100% 10098 (longest request)
Apache
# ab -n 1000 -c 100 http://127.0.0.1/consumer_http_oauthconsumer.php This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0 Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Copyright 2006 The Apache Software Foundation, http://www.apache.org/ Benchmarking 127.0.0.1 (be patient) Completed 100 requests Completed 200 requests Completed 300 requests Completed 400 requests Completed 500 requests Completed 600 requests Completed 700 requests Completed 800 requests Completed 900 requests Finished 1000 requests Server Software: Apache/2.2.8 Server Hostname: 127.0.0.1 Server Port: 80 Document Path: /consumer_http_oauthconsumer.php Document Length: 507 bytes Concurrency Level: 100 Time taken for tests: 23.967652 seconds Complete requests: 1000 Failed requests: 894 (Connect: 0, Length: 894, Exceptions: 0) Write errors: 0 Total transferred: 896892 bytes HTML transferred: 508892 bytes Requests per second: 41.72 [#/sec] (mean) Time per request: 2396.765 [ms] (mean) Time per request: 23.968 [ms] (mean, across all concurrent requests) Transfer rate: 36.51 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 1 5.9 0 23 Processing: 79 2376 3796.3 1126 23926 Waiting: 79 1989 2820.5 1111 14996 Total: 79 2378 3801.2 1126 23948 Percentage of the requests served within a certain time (ms) 50% 1126 66% 1218 75% 1309 80% 1387 90% 7765 95% 8484 98% 20845 99% 21469 100% 23948 (longest request)
環境
OS : CentOS 5.5 64bit on XenServer
VCPU : 1
MEM : 1GB
参考URL
HipHopのビルドとインストール方法(和訳) : candycane development blog
http://blog.candycane.jp/archives/295
ついに公開,Facebook-HipHop-PHP - なぜか数学者にはワイン好きが多い
http://d.hatena.ne.jp/tullio/20100221/1266760473
HipHop for PHP インストールログ - modules/mod_girl.so
http://d.hatena.ne.jp/mod_girl/20101020/1287558769