$value ) if( $value['eid'] == $eid ) return $value; return null; } function RecommendedEntry_updateIndexFile( $eid_updated, $eid, $direction ) { $filename = '/var/www/VirtualDomain/kenji00.com/blog/recommend_data'; is_dir( $filename ) || mkdir( $filename ); $filename .= '/'. substr( $eid_updated, -1 ); is_dir( $filename ) || mkdir( $filename ); $filename .= sprintf( '/%d.txt', $eid_updated); file_exists( $filename ) || touch( $filename ); $fp = @fopen( $filename, 'r+' ); if( $fp ) { if( flock( $fp, LOCK_EX | LOCK_NB )) { $ret = ''; $not_found = 1; while( !feof( $fp ) && ( $buf = fgets( $fp ))) { list( $_eid, $_n0, $_n1 ) = split( "[\t\r\n]", $buf ); if( $eid == $_eid ) { $not_found = 0; $direction ? $_n1++ : $_n0++; } $ret .= sprintf( "%d\t%d\t%d\n", $_eid, $_n0, $_n1 ); } if( $not_found ) $ret .= sprintf( "%d\t%d\t%d\n", $eid, 1 - $direction, $direction); rewind( $fp ); fwrite( $fp, $ret, strlen( $ret )); } fclose( $fp ); } } function RecommendedEntry_incoming() { $eid_prev = $_COOKIE['mtrcmnd_eid']; if( isset( $eid_prev )) { if( $eid_prev != 131 && RecommendedEntry_getEntryData( $eid_prev )) { RecommendedEntry_updateIndexFile( 131, $eid_prev, 0 /*incoming_from*/ ); RecommendedEntry_updateIndexFile( $eid_prev, 131, 1 /*outgoing_to*/ ); } } else { RecommendedEntry_updateIndexFile( 131, 131, 0 /*incoming_from*/ ); } } RecommendedEntry_incoming(); function RecommendedEntry_outgoing() { setcookie( 'mtrcmnd_eid', 131, time() + 2592000, '/' ); } RecommendedEntry_outgoing(); function RecommendedEntry_initialize( $mode = 0 ) { global $RecommendedEntry_table; $RecommendedEntry_table = array(); $filename = '/var/www/VirtualDomain/kenji00.com/blog/recommend_data/'. substr( '131', -1 ). '/131.txt'; $fp = @fopen( $filename, 'r' ); if( $fp ) { if( flock( $fp, LOCK_SH | LOCK_NB )) { while( !feof( $fp ) && ( $buf = fgets( $fp ))) { list( $_eid, $_n0, $_n1 ) = split( "[\t\r\n]", $buf ); if( 131 == $_eid ) continue; else if( $mode == 1 ) $RecommendedEntry_table{$_eid} = $_n0; else if( $mode == 2 ) $RecommendedEntry_table{$_eid} = $_n1; else $RecommendedEntry_table{$_eid} = $_n0 + $_n1; } arsort( $RecommendedEntry_table, SORT_NUMERIC ); } fclose( $fp ); } } function RecommendedEntry_GetEntry( $_index ) { global $RecommendedEntry_table; foreach( $RecommendedEntry_table as $eid => $count ) { if( --$_index ) continue; $entry = RecommendedEntry_getEntryData( $eid ); if( $entry ) $entry['count'] = $count; return $entry; } } ?> CentOS3にPHP5+eAccelerator - 寝不足にて候(仮)
Jan
20
2008

CentOS3にPHP5+eAccelerator

現在入ってるのは、PHP5.1.6
5.2系へのUpdateは、適当なSRPMを探すのが面倒なので、とりあえず見送り。

結論から言うと、eAcceleratorの導入で、応答速度は1/3近くまで短縮される模様。

本当は、Apacheも2.0から2,2にしようと思いましたが、SRPMからのrebuildだとApache Portable Runtimeのインストール時に、稼動中ソフト/ライブラリとの兼ね合いで弄りが必要となり、心が折れました。
ソースからmakeすればいいじゃん。という説もありますが、一介の金融系サラリーマンでnerdでもgeekでも無いワタクシは、PKG管理派に宗旨替えをしていますので。

前回のeAcceleratorインストール時は、未だPHP4.4.4でした。その時の手順を思い出しながら、こちらはソースからbuild。

[eAcceleratorのインストール]

$ wget http://jaist.dl.sourceforge.net/sourceforge/eaccelerator/eaccelerator-0.9.5.2.tar.bz2
$ bunzip2 -dc eaccelerator-0.9.5.2.tar.bz2 | tar xvf -
$ cd eaccelerator-0.9.5.2
$ /usr/bin/phpize
$ ./configure --enable-eaccelerator=shared --with-php-config=/usr/bin/php-config --with-eaccelerator-info
$ make
$ su
# make install
Installing shared extensions: /usr/lib/php/modules/

[設定]

$ cp control.php /var/www/VirtualHosts/kenji00/***.kenji00.com/htdocs/
$ vi /var/www/VirtualHosts/kenji00/***.kenji00.com/htdocs/control.php

$user = "*******";
$pw = "********";

$ mkdir /tmp/eaccelerator
# chown apache:apache /tmp/eaccelerator/
# cp eaccelerator.ini /etc/php.d/eaccelerator.ini
# vi /etc/php.d/eaccelerator.ini

zend_extension = "/usr/lib/php/modules/eaccelerator.so"
eaccelerator.allowed_admin_path = "/var/www/VirtualHosts/kenji00/***.kenji00.com/htdocs/control.php"

[TEST]

# /etc/init.d/httpd restart

47-test_php.png

では、テストしてみましょう。

先ずは1回目。インストール済みのcontrol.phpで、Cachingを無効にしています。

$ ab -n 100 -c 10 http://***.kenji00.com/index.php

This is ApacheBench, Version 2.0.40-dev <$Revision: 1.121.2.1 $> apache-2.0
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/

Benchmarking cat.kenji00.com (be patient).....done


Server Software: Apache
Server Hostname: ***.kenji00.com
Server Port: 80

Document Path: /index.php
Document Length: 14311 bytes

Concurrency Level: 10
Time taken for tests: 87.545530 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 1472400 bytes
HTML transferred: 1431100 bytes
Requests per second: 1.14 [#/sec] (mean)
Time per request: 8754.553 [ms] (mean)
Time per request: 875.455 [ms] (mean, across all concurrent requests)
Transfer rate: 16.41 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.7 0 7
Processing: 3032 8546 7254.4 6660 43925
Waiting: 2864 7979 6574.6 6347 43761
Total: 3032 8546 7254.3 6660 43925

Percentage of the requests served within a certain time (ms)
50% 6660
66% 8256
75% 9568
80% 10456
90% 15477
95% 19389
98% 43640
99% 43925
100% 43925 (longest request)

次は、Caching有効時。テストしているURLのcacheがあることをcontrol.phpで確認して.....

$ ab -n 100 -c 10 http://***.kenji00.com/index.php

This is ApacheBench, Version 2.0.40-dev <$Revision: 1.121.2.1 $> apache-2.0
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/

Benchmarking cat.kenji00.com (be patient).....done


Server Software: Apache
Server Hostname: ***.kenji00.com
Server Port: 80

Document Path: /index.php
Document Length: 14311 bytes

Concurrency Level: 10
Time taken for tests: 38.965838 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 1472400 bytes
HTML transferred: 1431100 bytes
Requests per second: 2.57 [#/sec] (mean)
Time per request: 3896.584 [ms] (mean)
Time per request: 389.658 [ms] (mean, across all concurrent requests)
Transfer rate: 36.88 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.7 0 5
Processing: 1436 3836 2701.9 3168 15025
Waiting: 1369 3589 2436.0 3039 14516
Total: 1441 3836 2701.9 3168 15025

Percentage of the requests served within a certain time (ms)
50% 3168
66% 4204
75% 5329
80% 5745
90% 7480
95% 9817
98% 13015
99% 15025
100% 15025 (longest request)

このエントリを読んだ人はこんなんも読んでいます

トラックバック(1)

トラックバックURL: http://blog.kenji00.com/MT/mt-tb.cgi/130

ベンチマークに使っていたXOOPSアプリのcache機能を使っていなかったので、... 続きを読む

コメントする

過去のエントリ(一覧)

Powered by Movable Type 4.261
Creative Commons License
このブログはクリエイティブ・コモンズでライセンスされています。