co`i blog

just another trash

Entries tagged “gentoo”

Kết quả benchmark memcacheq

written by root, on 4/16/10 5:17 PM.

Xem thông tin về memcacheq tại http://memcachedb.org/memcacheq/


Base để build hệ thống là Gentoo 64bits (Xeon 3.2Ghz, 4GB RAM) với các thông số:
CFLAGS="-O2 -pipe -march=athlon64 -fforce-addr"
CXXFLAGS="${CFLAGS}"
CHOST="x86_64-pc-linux-gnu"

Các bạn có thể đọc theo cách INSTALL tại trang chủ của memcacheq. Đối với Gentoo, kiểm tra các gói sau:
Server10 ~ # emerge -pv libevent db

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild   R   ] dev-libs/libevent-1.4.13  0 kB
[ebuild     U ] sys-libs/db-4.8.26 [4.8.24] USE="-doc -java -nocxx -tcl -test" 22,362 kB

Total: 2 packages (1 upgrade, 1 reinstall), Size of downloads: 22,362 kB

Sau đó compile theo như hướng dẫn:
Server10 ~ # cd /usr/src
Server10 src # wget http://memcacheq.googlecode.com/files/memcacheq-0.2.0.tar.gz
Server10 src # tar xfz memcacheq-0.2.0.tar.gz
Server10 src # cd memcacheq-0.2.0
Server10 memcacheq-0.2.0 # ./configure --prefix=/usr/local/memcacheq --enable-threads
Server10 memcacheq-0.2.0 # make
Server10 memcacheq-0.2.0 # make install

Ở đây, tôi sử dụng thư mục data nằm tại: /data
Tôi có tweak một số thông số BerkeleyDB cho phù hợp bằng cách tạo file DB_CONFIG nằm trong /data với nội dung sau:
set_cachesize 1 500 0
set_lg_regionmax 64000000
set_lg_bsize 7680000
* Đọc thêm về các thông số:
set_cachesize
set_lg_regionmax
set_lg_bsize


Chạy memcacheq với thông số:
/usr/local/memcache/bin/memcacheq -r -H /data -N -R -v -L 1024 -B 1280 -u root -p 29000 -c 30000 -m 128MB -U 29000 -t 4 -C 1m -T 15 -S 15 -d

Thông tin về các tham số, các bạn tự tìm hiểu nhé.

Benchmark với PHP (môi trường thực tế)
Cài đặt module memcache cho PHP.
Server11 ~ # emerge -pv dev-php5/pecl-memcache

Ở đây, tôi dùng 2 script
Script đầu tiên là consumer.php có nhiệm vụ đọc và marked data được đưa vào (tuy vậy tôi không xóa)
<?php
set_time_limit (0);
$memcache_obj = memcache_connect('Server10', 29000);
$i = 0;
while (1) {
        memcache_get($memcache_obj, 'demoqueuea')."\n";
        //usleep(1000);
}
memcache_close($memcache_obj);
?>

Script thứ 2 là give.php, có nhiệm vụ ghi data vào. Mỗi lần chạy sẽ ghi 1 triệu record.
<?php
$bgtime = time();
$memcache_obj = memcache_connect('Server10', 29000);
$i = 0;
while ($i < 1000000) {
        memcache_set($memcache_obj, 'demoqueuea', 'message body here-'.$data.'-'.$i, 0, 0);
        $i = $i + 1;
}
memcache_close($memcache_obj);
echo "Execute time: ".(time()-$bgtime);
?>

Đầu tiên ta khởi tạo consumer.php chạy nền.
Server11 ~ # nohup php consumer.php > consumer.log 2>&1 &

Thử với 1 process.
Server11 ~ #  cat mass.sh
#!/bin/bash
        for i in `seq 1 10`;
        do
                php give.php >> test.log
        done
Server11 ~ # /bin/bash ./mass.sh

Kiểm tra test.log để có kết quả.
Tương tự vậy với 2, 4 process.
Server11 ~ #  cat mass4.sh
#!/bin/bash
        for i in `seq 1 10`;
        do
                php give.php >> test4.log&
                php give.php >> test4.log&
                php give.php >> test4.log&
                php give.php >> test4.log
        done
Server11 ~ # /bin/bash ./mass.sh



Kết quả nhận được:

Hình: Bảng so sánh.


Hình: Kết quả với 1 và 2 thread.


Hình: Kết quả với 4 thread.

HipHop PHP trên Gentoo

written by root, on 3/23/10 2:19 PM.

Bạn nào compile thử hphp (HipHop PHP) chắc cũng sẽ biết nỗi khổ compile một đống các thứ lỉnh kỉnh để có thể compile được. Tuy nhiên, trên gentoo mọi việc... thật đơn giản :-) Trong khi chờ đợi tôi release các file rpm đã patch theo yêu cầu của hphp trên CentOS 5.x, tôi sẽ chỉ các bạn compile trên gentoo.
Thực ra theo tôi thấy, do hphp phụ thuộc vào các lib cũng như việc compile hphp nhiều nên các bạn chọn những distro compile from source là tốt nhất. Hoặc như pdah build toàn bộ lib theo PREFIX khác với system.

Lưu ý
Hiện nay hphp chỉ chạy trên nền 64bits.
Trong hướng dẫn tôi sử dụng emerge với option -pv để các bạn biết các option tôi đã compile.

Trước hết và dĩ nhiên: sync data mới của gentoo.
emerge --sync

Cài git
Server10 ~ # emerge -v dev-vcs/git
[ebuild     U ] dev-vcs/git-1.7.0.2 [1.7.0] USE="cgi curl iconv perl subversion threads -bash-completion -blksha1 -cvs -doc -emacs -gtk (-ppcsha1) -tk -webdav -xinetd" 2,644 kB

Cài các gói kiểm tra các gói thông dụng cần cài đặt bởi hphp
Server10 ~ # emerge -pv cmake gcc flex bison re2c mysql libxml2 icu openssl binutils libcap zlib dev-libs/oniguruma expat libmcrypt gd

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild   R   ] dev-libs/expat-2.0.1-r3  0 kB
[ebuild   R   ] dev-util/re2c-0.13.5  0 kB
[ebuild   R   ] dev-libs/icu-4.2.1  USE="-debug -doc -examples" 0 kB
[ebuild   R   ] dev-libs/oniguruma-5.9.2  0 kB
[ebuild   R   ] dev-libs/libmcrypt-2.5.8-r1  0 kB
[ebuild   R   ] sys-devel/flex-2.5.35  USE="nls -static" 1,228 kB
[ebuild   R   ] sys-devel/bison-2.4.1  USE="nls -static" 0 kB
[ebuild   R   ] sys-libs/libcap-2.19  USE="-pam" 0 kB
[ebuild     U ] sys-devel/binutils-2.20.1 [2.20-r1] USE="multislot* nls -multitarget -test -vanilla" 17,106 kB
[ebuild     U ] sys-libs/zlib-1.2.4 [1.2.3-r1] 473 kB
[ebuild   R   ] sys-devel/gcc-4.3.4  USE="hardened mudflap (multilib) multislot nls nptl openmp (-altivec) -bootstrap -build -doc (-fixed-point) -fortran -gcj -gtk (-libffi) (-n32) (-n64) -nocxx -nopie -objc -objc++ -objc-gc -test -vanilla" 74 kB
[ebuild     U ] dev-util/cmake-2.8.1 [2.8.0-r2] USE="ncurses -emacs -qt4 -vim-syntax" 3,522 kB
[ebuild     U ] dev-libs/openssl-0.9.8m-r1 [0.9.8l-r2] USE="kerberos* (sse2) zlib -bindist -gmp -test" 3,680 kB
[ebuild     U ] dev-libs/libxml2-2.7.7 [2.7.6] USE="python readline -debug -doc -examples -ipv6 -test" 4,755 kB
[blocks b     ] <dev-libs/libxml2-2.7.7 ("<dev-libs/libxml2-2.7.7" is blocking sys-libs/zlib-1.2.4)
[ebuild   R   ] media-libs/gd-2.0.35-r1  USE="fontconfig jpeg png truetype xpm" 0 kB
[ebuild   R   ] dev-db/mysql-5.1.44-r1  USE="big-tables cluster extraengine perl ssl -community -debug -embedded -latin1 -max-idx-128 -minimal -pbxt -profiling (-selinux) -static -test" 0 kB

Total: 16 packages (5 upgrades, 11 reinstalls), Size of downloads: 30,834 kB

Cài libmbfl: đi kèm với hphp không cần phải cài. Khi load hphp về sẽ có sẵn.
libpcre3 có sẵn trong gentoo.

Cài tbb: yêu cầu của hphp là 2.2 trở lên, bản có trên gentoo của tôi là tbb-2.1.015 không phù hợp nên phải tự tạo file ebuild mới sau đó mới emerge.
Server10 ~ # cd /usr/portage/dev-cpp/tbb
Server10 tbb # wget http://up.conlua.net/hphp/tbb-2.2.013.ebuild
Server10 tbb # ebuild tbb-2.2.013.ebuild digest
Server10 tbb # emerge -pv tbb

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild   R   ] dev-cpp/tbb-2.2.013  USE="-debug -doc -examples" 0 kB

Cài Boost: có thể compile hphp với Boost 1.42, nhưng khuyến cáo dân dev-hphp, không nên chạy với Boost 1.42 do 1 số bug của Boost. Nên tôi phải downgrade xuống bản 1.41.
Server10 ~ # echo ">=dev-libs/boost-1.42.0" >> /etc/portage/package.mask
Server10 ~ # emerge -pv boost

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild   R   ] dev-libs/boost-1.41.0-r3  USE="eselect expat icu mpi python tools -debug -doc -test" 0 kB

Lấy source hphp: sử dụng git để lấy source từ repo.
Server10 ~ # mkdir /usr/src/hh
Server10 ~ # cd /usr/src/hh
Server10 hh # git clone git://github.com/facebook/hiphop-php.git
Server10 hh # cd hiphop-php
Server10 hiphop-php # git submodule init
Server10 hiphop-php # git submodule update

Cài đặt libevent: hphp cần apply 1 patch riêng cho lib này, nên ta tiến hành build với patch.
Server10 ~ # mkdir /usr/portage/dev-libs/libevent/files
Server10 ~ # cd /usr/src/hh/hiphop-php/
Server10 hiphop-php # cp src/third_party/libevent.fb-changes.diff /usr/portage/dev-libs/libevent/files
Server10 hiphop-php # cd /usr/portage/dev-libs/libevent/
Server10 libevent # rm -rf libevent-1.4.13.ebuild
Server10 libevent # wget http://up.conlua.net/hphp/libevent-1.4.13.ebuild
Server10 libevent # ebuild libevent-1.4.13.ebuild digest
Server10 libevent # emerge -pv libevent

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild   R   ] dev-libs/libevent-1.4.13  0 kB

Total: 1 package (1 reinstall), Size of downloads: 0 kB
Trong trường hợp emerge ra version mới hơn, có thể tự đọc file download về, để ý dòng dưới đây và ghi vào vị trí tương ứng file mới. Nếu không, có thể làm tương tự việc mask packages giống như đã làm với Boost.
epatch "${FILESDIR}"/libevent.fb-changes.diff

Cài đặt curl: hphp cần apply 1 patch riêng cho lib này, nên ta tiến hành build với patch.
Server10 ~ # cd /usr/src/hh/hiphop-php/
Server10 hiphop-php # cp src/third_party/libcurl.fb-changes.diff /usr/portage/net-misc/curl/files
Server10 hiphop-php # cd /usr/portage/net-misc/curl/
Server10 curl # rm -rf curl-7.20.0-r1.ebuild
Server10 curl # wget http://up.conlua.net/hphp/curl-7.20.0-r1.ebuild
Server10 curl # ebuild curl-7.20.0-r1.ebuild digest
Server10 curl # emerge -pv curl

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild   R   ] net-misc/curl-7.20.0-r1  USE="gnutls idn kerberos ldap libssh2 ssl -ares -ipv6 -nss -test" 0 kB

Total: 1 package (1 reinstall), Size of downloads: 0 kB

Bắt đầu biên dịch hphp
Server10 ~ # cd /usr/src/hh/hiphop-php/
Server10 hiphop-php # export HPHP_HOME=`pwd`
Server10 hiphop-php # export HPHP_LIB=`pwd`/bin
Server10 hiphop-php # cmake .
Server10 hiphop-php # make


Ở đây tôi thử hphp với RivetTracker. Tôi làm như sau:
Server10 ~ # cd /home/rt/pub
Server10 pub # find . -name "*.php" > files.list
Server10 pub # $HPHP_HOME/src/hphp/hphp --input-list=files.list -k 1 --log=9 --force=1 --cluster-count=8
Kết quả tôi có khi compile nằm ở thư mục /tmp/hphp_HoMEOR. Tôi thử chạy và kiểm tra ứng dụng.
Server10 ~ # cd /home/rt/pub
Server10 pub # /tmp/hphp_HoMEOR/program -m server -v "Server.SourceRoot=`pwd`" -v "Server.DefaultDocument=index.php" -c $HPHP_HOME/bin/mime.hdf

Và khi dùng trình duyệt mở web theo máy chủ tôi đã cài. Kết quả ra đúng như ý muốn.

Một số thử nghiệm và kết quả
  • phpMyAdmin : không biên dịch được source C++. Báo lỗi undefined var, nếu có thời gian sửa lại source php có thể chạy được.
  • VBulletin : không biên dịch được source C++. Báo lỗi không thấy file, lỗi này do structure của các class kém của VBB.
  • wTorrent : không parse được hphp. Do sử dụng require_one nhiều chỗ. Sử dụng path tương đối.
  • WordPress : Compile được nhưng chạy không chính xác. Tôi thử không có xài patch của hphp.

Các bạn thử nhé :-)


Tham khảo:
Building and installing - hiphop-php - GitHub
Boost 1.42 - HipHop for PHP Dev - Google Groups