MongoDB,CouchDB,MySQL,memcacheデータをPHPから読み込み&書き込み速度を検証してみました!(その2)
前回、MongoDB,CouchDB,MySQL,memcacheの読み込み&書き込み速度を検証してみました。
MongoDB,CouchDB,MySQL,memcacheデータをPHPから読み込み&書き込み速度を検証してみました! - @camelmasaの開発日記
下記の原因で予想していたような結果を出す事が出来ませんでした。
・MongoDBでコネクションプーリングをしていなかった。
・CouchDBのHTTPリクエスト方法が遅かった。
id:yssk22さんのコメントにより上記の部分を修正する事が出来ましたので再度検証してみました。
gt
CouchDB:0.10.1
MySQL:5.1.43
memcache:1.2.8
CPU:AMD(の何か)
メモリ:4GB
(ざっくり検証です。)
読み込み時のソース
前回と一緒で"test"データベースの"test"テーブル(コレクション)の"test"データをphpから読み込みするプログラムです。
<?php $ch = curl_init("http://192.168.0.30:5984/"); $fp = fopen("test/1ab25e328d1f36b2895671666491e48f", "w"); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch);
前回、PEARパッケージであるHTTP_Requestを用いて検証して物凄く遅かったのですが、cURL関数を使って通信する事で速度が飛躍的に向上する事が期待できます。
mongodb.php
<?php $mongo = new Mongo(); $db = $mongo->selectDB("test"); $col = $db->selectCollection("test"); $cursor = $col->findOne();
前回コネクションプーリングしていなかったので今回はコネクションプーリングして検証します。
コンストラクタの第3引数にtrueをする事でプーリングを確保出来ます。
<?php <?php $link = mysql_pconnect('localhost', 'user', 'pass'); mysql_select_db('mytest', $link); $result = mysql_query('SELECT `test` FROM `test` LIMIT 0,1;');
memcache.php
<?php $memcache = new Memcache; $memcache->connect('localhost', 11211) or die ("Could not connect"); $memcache->get('test');
読み込み結果
ab -c 100 -n 1000 'http://192.168.0.30/couchdb.php' Server Software: Apache/2.2.3 Server Hostname: 192.168.0.30 Server Port: 80 Document Path: /couchdb.php Document Length: 41 bytes Concurrency Level: 100 Time taken for tests: 3.152094 seconds Complete requests: 1000 Failed requests: 0 Write errors: 0 Total transferred: 232000 bytes HTML transferred: 41000 bytes Requests per second: 317.25 [#/sec] (mean) Time per request: 315.209 [ms] (mean) Time per request: 3.152 [ms] (mean, across all concurrent requests) Transfer rate: 71.70 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 2 7.9 0 31 Processing: 26 302 112.4 248 813 Waiting: 26 302 112.5 248 813 Total: 26 305 112.7 248 813 Percentage of the requests served within a certain time (ms) 50% 248 66% 262 75% 349 80% 443 90% 515 95% 525 98% 534 99% 538 100% 813 (longest request)
mongodb.php
ab -c 100 -n 1000 'http://192.168.0.30/mongodb.php' Benchmarking 192.168.0.30 (be patient) Server Software: Apache/2.2.3 Server Hostname: 192.168.0.30 Server Port: 80 Document Path: /mongodb.php Document Length: 0 bytes Concurrency Level: 100 Time taken for tests: 1.404074 seconds Complete requests: 1000 Failed requests: 0 Write errors: 0 Total transferred: 190570 bytes HTML transferred: 0 bytes Requests per second: 712.21 [#/sec] (mean) Time per request: 140.407 [ms] (mean) Time per request: 1.404 [ms] (mean, across all concurrent requests) Transfer rate: 132.47 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 2 7.2 0 30 Processing: 10 129 88.5 124 844 Waiting: 9 128 88.4 124 843 Total: 29 131 88.9 124 865 Percentage of the requests served within a certain time (ms) 50% 124 66% 125 75% 130 80% 130 90% 145 95% 152 98% 191 99% 750 100% 865 (longest request)
ab -c 100 -n 1000 'http://192.168.0.30/mysql.php' Benchmarking 192.168.0.30 (be patient) Server Software: Apache/2.2.3 Server Hostname: 192.168.0.30 Server Port: 80 Document Path: /mysql.php Document Length: 0 bytes Concurrency Level: 100 Time taken for tests: 1.533586 seconds Complete requests: 1000 Failed requests: 0 Write errors: 0 Total transferred: 190000 bytes HTML transferred: 0 bytes Requests per second: 652.07 [#/sec] (mean) Time per request: 153.359 [ms] (mean) Time per request: 1.534 [ms] (mean, across all concurrent requests) Transfer rate: 120.63 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 3 6.2 0 25 Processing: 13 142 125.8 135 1512 Waiting: 9 141 126.1 134 1510 Total: 20 146 126.1 138 1528 Percentage of the requests served within a certain time (ms) 50% 138 66% 147 75% 149 80% 151 90% 155 95% 159 98% 165 99% 182 100% 1528 (longest request)
memcache.php
Benchmarking 192.168.0.30 (be patient) Server Software: Apache/2.2.3 Server Hostname: 192.168.0.30 Server Port: 80 Document Path: /memcache.php Document Length: 0 bytes Concurrency Level: 100 Time taken for tests: 1.305582 seconds Complete requests: 1000 Failed requests: 0 Write errors: 0 Total transferred: 190950 bytes HTML transferred: 0 bytes Requests per second: 765.94 [#/sec] (mean) Time per request: 130.558 [ms] (mean) Time per request: 1.306 [ms] (mean, across all concurrent requests) Transfer rate: 142.47 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 4 6.7 1 28 Processing: 26 121 30.1 129 188 Waiting: 25 116 29.5 124 187 Total: 26 126 33.2 132 193 Percentage of the requests served within a certain time (ms) 50% 132 66% 141 75% 148 80% 153 90% 164 95% 171 98% 179 99% 183 100% 193 (longest request)
読み込み結果検証
Time taken for testsが
memcache>MOngoDB>MySQL>CouchDB
の順番になりましたね。
これは納得がいく順番ですね。
前回同じ条件でのcouchdb.phpが9.587989 secondsでしたが、今回は3.152094 secondsと飛躍的に増加しました!
又MongoDBをコネクションプーリングする事でも処理が早くなりました。
下記が接続時のログですが、1000回のアクセスにも係わらず21回しか新規の接続をしていない事が確認できます。
Fri Feb 26 12:25:52 db version v1.2.2, pdfile version 4.5 Fri Feb 26 12:25:52 git version: 8a4fb8b1c7cb78648c55368d806ba35054f6be54 Fri Feb 26 12:25:52 sys info: Linux domU-12-31-39-01-70-B4 2.6.21.7-2.fc8xen #1 SMP Fri Feb 15 12:39:36 EST 2008 i686 BOOST_LIB_VERSION=1_37 Fri Feb 26 12:25:52 waiting for connections on port 27017 Fri Feb 26 12:27:02 connection accepted from 192.168.0.30:51154 #1 Fri Feb 26 12:27:02 connection accepted from 192.168.0.30:51155 #2 Fri Feb 26 12:27:03 connection accepted from 192.168.0.30:51156 #3 Fri Feb 26 12:27:03 connection accepted from 192.168.0.30:51157 #4 Fri Feb 26 12:27:03 connection accepted from 192.168.0.30:51158 #5 Fri Feb 26 12:27:03 connection accepted from 192.168.0.30:51159 #6 Fri Feb 26 12:27:03 connection accepted from 192.168.0.30:51160 #7 Fri Feb 26 12:27:03 connection accepted from 192.168.0.30:51161 #8 Fri Feb 26 12:27:03 connection accepted from 192.168.0.30:51162 #9 Fri Feb 26 12:27:03 connection accepted from 192.168.0.30:51163 #10 Fri Feb 26 12:27:03 connection accepted from 192.168.0.30:51164 #11 Fri Feb 26 12:27:03 connection accepted from 192.168.0.30:51165 #12 Fri Feb 26 12:27:03 connection accepted from 192.168.0.30:51166 #13 Fri Feb 26 12:27:03 connection accepted from 192.168.0.30:51167 #14 Fri Feb 26 12:27:03 connection accepted from 192.168.0.30:51168 #15 Fri Feb 26 12:27:03 connection accepted from 192.168.0.30:51169 #16 Fri Feb 26 12:27:03 connection accepted from 192.168.0.30:51170 #17 Fri Feb 26 12:27:03 connection accepted from 192.168.0.30:51171 #18 Fri Feb 26 12:27:03 connection accepted from 192.168.0.30:51172 #19 Fri Feb 26 12:27:03 connection accepted from 192.168.0.30:51173 #20 Fri Feb 26 12:27:03 connection accepted from 192.168.0.30:51442 #21 Fri Feb 26 12:27:04 end connection 192.168.0.30:51161
次は書き込み時の検証してみます。
書き込み時のソース
<?php $ch = curl_init("http://192.168.0.30:5984/"); $fp = fopen("test", "w"); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, '{"test":"test"}'); curl_exec($ch);
mongodb_write.php
<?php $mongo = new Mongo('192.168.0.30:27017',true,true); $db = $mongo->selectDB("test"); $col = $db->selectCollection("test"); $col->insert(array("test" => "test"));
<?php $link = mysql_pconnect('localhost', 'user', 'pass'); mysql_select_db('mytest', $link); $result = mysql_query("INSERT INTO `test` VALUES ('test');");
memcache_write.php
<?php $memcache = new Memcache; $memcache->connect('localhost', 11211) or die ("Could not connect"); $memcache->set("test", "test");
書き込み結果
ab -c 100 -n 1000 'http://192.168.0.30/couchdb_write.php' Benchmarking 192.168.0.30 (be patient) Server Software: Apache/2.2.3 Server Hostname: 192.168.0.30 Server Port: 80 Document Path: /couchdb_write.php Document Length: 64 bytes Concurrency Level: 100 Time taken for tests: 3.193331 seconds Complete requests: 1000 Failed requests: 0 Write errors: 0 Total transferred: 255255 bytes HTML transferred: 64064 bytes Requests per second: 313.15 [#/sec] (mean) Time per request: 319.333 [ms] (mean) Time per request: 3.193 [ms] (mean, across all concurrent requests) Transfer rate: 77.98 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 38 31.2 33 117 Processing: 110 268 92.0 239 561 Waiting: 3 237 90.8 217 537 Total: 112 306 106.7 275 642 Percentage of the requests served within a certain time (ms) 50% 275 66% 300 75% 315 80% 353 90% 507 95% 556 98% 595 99% 616 100% 642 (longest request)
mongodb_write.php
ab -c 100 -n 1000 'http://192.168.0.30/mongodb_write.php' Benchmarking 192.168.0.30 (be patient) Server Software: Apache/2.2.3 Server Hostname: 192.168.0.30 Server Port: 80 Document Path: /mongodb_write.php Document Length: 0 bytes Concurrency Level: 100 Time taken for tests: 1.227498 seconds Complete requests: 1000 Failed requests: 0 Write errors: 0 Total transferred: 190000 bytes HTML transferred: 0 bytes Requests per second: 814.67 [#/sec] (mean) Time per request: 122.750 [ms] (mean) Time per request: 1.227 [ms] (mean, across all concurrent requests) Transfer rate: 150.71 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 11 7.7 11 30 Processing: 25 105 18.4 109 131 Waiting: 3 94 19.8 92 121 Total: 25 116 19.9 119 160 Percentage of the requests served within a certain time (ms) 50% 119 66% 126 75% 131 80% 133 90% 138 95% 141 98% 145 99% 150 100% 160 (longest request)
ab -c 100 -n 1000 'http://192.168.0.30/mysql_write.php' Benchmarking 192.168.0.30 (be patient) Server Software: Apache/2.2.3 Server Hostname: 192.168.0.30 Server Port: 80 Document Path: /mysql_write.php Document Length: 0 bytes Concurrency Level: 100 Time taken for tests: 1.480484 seconds Complete requests: 1000 Failed requests: 0 Write errors: 0 Total transferred: 190000 bytes HTML transferred: 0 bytes Requests per second: 675.45 [#/sec] (mean) Time per request: 148.048 [ms] (mean) Time per request: 1.480 [ms] (mean, across all concurrent requests) Transfer rate: 124.96 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 1.6 0 9 Processing: 5 139 57.9 151 619 Waiting: 5 139 58.0 151 619 Total: 5 140 57.8 151 625 Percentage of the requests served within a certain time (ms) 50% 151 66% 154 75% 155 80% 157 90% 186 95% 213 98% 224 99% 332 100% 625 (longest request)
memcache_write.php
ab -c 100 -n 1000 'http://192.168.0.30/memcache_write.php' Benchmarking 192.168.0.30 (be patient) Server Software: Apache/2.2.3 Server Hostname: 192.168.0.30 Server Port: 80 Document Path: /memcache_write.php Document Length: 0 bytes Concurrency Level: 100 Time taken for tests: 1.244228 seconds Complete requests: 1000 Failed requests: 0 Write errors: 0 Total transferred: 190190 bytes HTML transferred: 0 bytes Requests per second: 803.71 [#/sec] (mean) Time per request: 124.423 [ms] (mean) Time per request: 1.244 [ms] (mean, across all concurrent requests) Transfer rate: 148.69 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 8 10.6 1 37 Processing: 15 112 35.4 124 192 Waiting: 7 106 33.5 118 191 Total: 32 120 39.1 129 199 Percentage of the requests served within a certain time (ms) 50% 129 66% 143 75% 150 80% 156 90% 165 95% 175 98% 185 99% 190 100% 199 (longest request)
全体を通したまとめ
書き込み時のTime taken for testsが
MongoDB>memcache>MySQL>CouchDB
の順番になりましたね。
こちらも納得がいく順番ですね!
MongoDB早いですね!!!流石です。
CouchDBはこれぐらいの速さなのですかね?
色々なドキュメントを見ると、MongoDBより遅いという記事を見ますが…。
あとがき
今度はこうしたらCouchDBが早くなるよ!的なアドバイス欲しいな〜。(あるかな?)
上記のテストサーバーは家でそのままにしてあるので、こんなテストして!っていう場合コメント下さい。
最後にid:yssk22さん有難う御座います!
[PR]Spreeの情報を集めています。
ECを持ちたい方、仕事でECを使いたい方向けのコミュニティサイトです。
このサイトでは世界で最も使用されているECの1つであるSpreeについての情報を提供しています。
http://spreecommerce.jp/
MongoDB,CouchDB,MySQL,memcacheデータをPHPから読み込み&書き込み速度を検証してみました!
前回、前前回とMongoDB,CouchDBのインストール方法やphpからの使用方法を記事にしました。
CentOS5.4にCouchDBをインストールする方法! - @camelmasaの開発日記
CouchDBをphpから操作する方法。 - @camelmasaの開発日記
CentOS5.4にMongoDBをインストールする方法! - @camelmasaの開発日記
MongoDBをphpから操作する方法。 - @camelmasaの開発日記
MongoDBとCouchDBにMySQL(MyISAM)とmemcacheを加えて読み込み(SELECT)と書き込み(INSERT)の速度を検証してみたいと思います。
環境
OS:CentOS5.4
PHP:5.3.1
MongoDB:1.2.2
CouchDB:0.10.1
MySQL:5.1.43
memcache:1.2.8
CPU:AMD(の何か)
メモリ:4GB
(ざっくりと検証です。)
読み取り時のソース
簡単に、"test"データベースの"test"テーブル(コレクション)の"test"データをphpから読み込みするプログラムです。
こんなソースで良いのか。
<?php require_once "HTTP/Request.php"; $http = new HTTP_Request('http://192.168.80.139:5984/test/93e4b62c166489b5ff94600e3003db88'); $response = $http->sendRequest();
mongodb.php
<?php $mongo = new Mongo(); $db = $mongo->selectDB("test"); $col = $db->selectCollection("test"); $cursor = $col->findOne();
<?php $link = mysql_pconnect('localhost', 'user', 'pass'); mysql_select_db('mytest', $link); $result = mysql_query('SELECT `test` FROM `test`;');
memcache.php
<?php $memcache = new Memcache; $memcache->connect('localhost', 11211) or die ("Could not connect"); $memcache->get('test');
読み込み結果
ab -c 100 -n 1000 'http://192.168.0.30/couchdb.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 192.168.0.30 (be patient) Server Software: Apache/2.2.3 Server Hostname: 192.168.0.30 Server Port: 80 Document Path: /couchdb.php Document Length: 0 bytes Concurrency Level: 100 Time taken for tests: 9.587989 seconds Complete requests: 1000 Failed requests: 0 Write errors: 0 Total transferred: 190000 bytes HTML transferred: 0 bytes Requests per second: 104.30 [#/sec] (mean) Time per request: 958.799 [ms] (mean) Time per request: 9.588 [ms] (mean, across all concurrent requests) Transfer rate: 19.29 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 1.5 0 9 Processing: 22 926 923.1 650 9554 Waiting: 21 860 568.4 650 5877 Total: 22 927 923.5 650 9555 Percentage of the requests served within a certain time (ms) 50% 650 66% 662 75% 783 80% 1099 90% 1565 95% 1735 98% 3220 99% 5656 100% 9555 (longest request)
mongodb.php
ab -c 100 -n 1000 'http://192.168.0.30/mongodb.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 192.168.0.30 (be patient) Server Software: Apache/2.2.3 Server Hostname: 192.168.0.30 Server Port: 80 Document Path: /mongodb.php Document Length: 0 bytes Concurrency Level: 100 Time taken for tests: 1.939626 seconds Complete requests: 1000 Failed requests: 0 Write errors: 0 Total transferred: 190000 bytes HTML transferred: 0 bytes Requests per second: 515.56 [#/sec] (mean) Time per request: 193.963 [ms] (mean) Time per request: 1.940 [ms] (mean, across all concurrent requests) Transfer rate: 95.38 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 1.5 0 8 Processing: 35 187 35.4 201 236 Waiting: 35 187 35.4 201 235 Total: 35 187 35.2 201 244 Percentage of the requests served within a certain time (ms) 50% 201 66% 202 75% 204 80% 204 90% 207 95% 208 98% 209 99% 226 100% 244 (longest request)
ab -c 100 -n 1000 'http://192.168.0.30/mysql.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 192.168.0.30 (be patient) Server Software: Apache/2.2.3 Server Hostname: 192.168.0.30 Server Port: 80 Document Path: /mysql.php Document Length: 0 bytes Concurrency Level: 100 Time taken for tests: 1.421236 seconds Complete requests: 1000 Failed requests: 0 Write errors: 0 Total transferred: 190000 bytes HTML transferred: 0 bytes Requests per second: 703.61 [#/sec] (mean) Time per request: 142.124 [ms] (mean) Time per request: 1.421 [ms] (mean, across all concurrent requests) Transfer rate: 130.17 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 1 5.1 0 22 Processing: 7 131 142.4 129 1404 Waiting: 7 131 142.3 129 1403 Total: 19 133 142.6 129 1416 Percentage of the requests served within a certain time (ms) 50% 129 66% 130 75% 136 80% 138 90% 141 95% 144 98% 173 99% 1339 100% 1416 (longest request)
memcache.php
ab -c 100 -n 1000 'http://192.168.0.30/memcache.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 192.168.0.30 (be patient)
Server Software: Apache/2.2.3
Server Hostname: 192.168.0.30
Server Port: 80
Document Path: /memcache.php
Document Length: 0 bytes
Concurrency Level: 100
Time taken for tests: 1.453866 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 191900 bytes
HTML transferred: 0 bytes
Requests per second: 687.82 [#/sec] (mean)
Time per request: 145.387 [ms] (mean)
Time per request: 1.454 [ms] (mean, across all concurrent requests)
Transfer rate: 128.62 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 15 10.2 14 45
Processing: 20 124 36.9 138 479
Waiting: 16 109 35.7 119 462
Total: 27 139 41.8 147 496
Percentage of the requests served within a certain time (ms)
50% 147
66% 163
75% 172
80% 176
90% 186
95% 191
98% 198
99% 203
100% 496 (longest request)
読み込み結果検証
Requests per secondの順位下記。
MySQL(MyISAM)>memcache>MongoDB>>>CouchDB
MySQLが一番早い結果になるとは思わなかったです。(なって欲しくなかった)
でもFacebookでのMySQL運用術はKVSの様にシンプルなのかな。
(http://hyuki.com/yukiwiki/wiki.cgi?HowFriendFeedUsesMySqlToStoreSchemaLessData)
CouchDBはRESTでのデータ取得をPEARでやってしまってるので遅いのかな?
毎度毎度その処理部分のPHPをコンパイルする分遅くなっているのでしょう。
MongoDBもmemcache並に早いですね。
MySQLがmemcacheより早いのは意外です。解せぬ〜。
次は書き込み時の速さを見てみます。
書き込み時のソース
couchdbはinsertの方法が調べれず…><
誰か教えて!ヘルプ!
mongodb_write.php
<?php $mongo = new Mongo(); $db = $mongo->selectDB("test"); $col = $db->selectCollection("test"); $col->insert(array("test" => "test"));
<?php $link = mysql_pconnect('localhost', 'root', ''); mysql_select_db('mytest', $link); $result = mysql_query("INSERT INTO `test` VALUES ('test');");
memcache_write.php
<?php $memcache = new Memcache; $memcache->connect('localhost', 11211) or die ("Could not connect"); $memcache->set("test", "test");
書き込み結果
mongodb_write.php
ab -c 100 -n 1000 'http://192.168.0.30/mongodb_write.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 192.168.0.30 (be patient) Server Software: Apache/2.2.3 Server Hostname: 192.168.0.30 Server Port: 80 Document Path: /mongodb_write.php Document Length: 0 bytes Concurrency Level: 100 Time taken for tests: 9.325888 seconds Complete requests: 1000 Failed requests: 0 Write errors: 0 Total transferred: 190190 bytes HTML transferred: 0 bytes Requests per second: 107.23 [#/sec] (mean) Time per request: 932.589 [ms] (mean) Time per request: 9.326 [ms] (mean, across all concurrent requests) Transfer rate: 19.84 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 4 9.7 0 36 Processing: 30 728 1111.7 176 9092 Waiting: 3 725 1112.6 176 9091 Total: 31 732 1111.0 177 9108 Percentage of the requests served within a certain time (ms) 50% 177 66% 910 75% 937 80% 938 90% 1030 95% 3103 98% 3148 99% 4285 100% 9108 (longest request)
ab -c 100 -n 1000 'http://192.168.0.30/mysql_write.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 192.168.0.30 (be patient) Server Software: Apache/2.2.3 Server Hostname: 192.168.0.30 Server Port: 80 Document Path: /mysql_write.php Document Length: 0 bytes Concurrency Level: 100 Time taken for tests: 1.484070 seconds Complete requests: 1000 Failed requests: 0 Write errors: 0 Total transferred: 190000 bytes HTML transferred: 0 bytes Requests per second: 673.82 [#/sec] (mean) Time per request: 148.407 [ms] (mean) Time per request: 1.484 [ms] (mean, across all concurrent requests) Transfer rate: 124.66 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 1.6 0 8 Processing: 41 142 165.8 129 1478 Waiting: 40 142 165.8 129 1478 Total: 41 143 165.8 129 1479 Percentage of the requests served within a certain time (ms) 50% 129 66% 131 75% 132 80% 133 90% 139 95% 144 98% 161 99% 1476 100% 1479 (longest request)
memcache_write.php
ab -c 100 -n 1000 'http://192.168.0.30/memcache_write.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 192.168.0.30 (be patient) Server Software: Apache/2.2.3 Server Hostname: 192.168.0.30 Server Port: 80 Document Path: /memcache_write.php Document Length: 0 bytes Concurrency Level: 100 Time taken for tests: 1.701421 seconds Complete requests: 1000 Failed requests: 0 Write errors: 0 Total transferred: 190380 bytes HTML transferred: 0 bytes Requests per second: 587.74 [#/sec] (mean) Time per request: 170.142 [ms] (mean) Time per request: 1.701 [ms] (mean, across all concurrent requests) Transfer rate: 108.73 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 17 11.0 18 44 Processing: 34 143 24.8 148 267 Waiting: 3 126 25.6 132 261 Total: 34 160 28.3 163 301 Percentage of the requests served within a certain time (ms) 50% 163 66% 175 75% 181 80% 185 90% 192 95% 195 98% 201 99% 205 100% 301 (longest request)
全体を通したまとめ
大分ざっくりとした検証で納得がいくのかわかりませんが個人的には概ね満足。
インストール〜設定〜動作等で見えた部分は勉強になりました。
検証前は圧倒的にmemcacheが一番早いだろうと思ったのですが、読み書きともMySQLとほぼ同じ位で驚きました。
その後僅差でMongoDB。
CouchDBはhttp通信をphpでしてしまってるので良い結果が得られなかった感じですか。
(couchdb.so作って!)
恐らく皆さんが書いているように、RDBMSも単体では速度的に問題なくて、複雑なSQLを処理しようとするとボトルネックになるのでしょうか。
スケーリングを意識したSQLを書く事で、KVS並に高速化になるのかもしれません。
参考:http://hyuki.com/yukiwiki/wiki.cgi?HowFriendFeedUsesMySqlToStoreSchemaLessData
あとがき
うーん…。
こうしたらMongoDBが早くなるよ!的なアドバイス欲しいな〜。
上記のテストサーバーは家でそのままにしてあるので、こんなテストして!っていう場合コメント下さい。
テストしてブログに書きます。
[PR]Spreeの情報を集めています。
ECを持ちたい方、仕事でECを使いたい方向けのコミュニティサイトです。
このサイトでは世界で最も使用されているECの1つであるSpreeについての情報を提供しています。
http://spreecommerce.jp/
CouchDBをphpから操作する方法。
前回の記事でCouchDBをインストールしましたので、CouchDBをphpから操作してみました。
CentOS5.4にCouchDBをインストールする方法! - @camelmasaの開発日記
testデータベース&testフィールドの作成
管理画面(_utils)の左上に表示されている"Create Database"リンクを押してデータベースを作成する事が出来ます。
画面の指示に従ってフィールド名も入力すると下記の画面が表示されました。
これでtestデータベース&testフィールドが作成出来ました。簡単ですね。
PECLパッケージphp_couchdbのインストール
phpから操作する為にcouchdb.soという野良PECLパッケージがあったので使用してみました。
Topdog.za.net :: PHP CouchDB Extension
…しかし下記のエラーが表示されてしまい、PHPでエラーになってしまいます。
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/modules/couchdb.so' - /usr/lib/php/modules/couchdb.so: undefined symbol: php_json_encode in Unknown on line 0
vim /usr/include/php/ext/json/php_json.h
* +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2009 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | http://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Omar Kilani <omar@php.net> | +----------------------------------------------------------------------+ */ /* $Id: php_json.h 283185 2009-06-30 17:52:21Z stas $ */ #ifndef PHP_JSON_H #define PHP_JSON_H #define PHP_JSON_VERSION "1.2.1" #include "ext/standard/php_smart_str.h" extern zend_module_entry json_module_entry; #define phpext_json_ptr &json_module_entry #if defined(PHP_WIN32) && defined(JSON_EXPORTS) #define PHP_JSON_API __declspec(dllexport) #else #define PHP_JSON_API PHPAPI #endif #ifdef ZTS #include "TSRM.h" #endif ZEND_BEGIN_MODULE_GLOBALS(json) int error_code; ZEND_END_MODULE_GLOBALS(json) #ifdef ZTS # define JSON_G(v) TSRMG(json_globals_id, zend_json_globals *, v) #else # define JSON_G(v) (json_globals.v) #endif PHP_JSON_API void php_json_encode(smart_str *buf, zval *val, int options TSRMLS_DC); PHP_JSON_API void php_json_decode(zval *return_value, char *str, int str_len, zend_bool assoc, long depth TSRMLS_DC); #endif /* PHP_JSON_H */ /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: * vim600: noet sw=4 ts=4 fdm=marker * vim<600: noet sw=4 ts=4 */
…うーん。エラーの原因がわからない。
alpha版なので、もっと作りこんでほしいなあと思う。
MongoDBの場合はPECL::MONGOがあってPHPer歓喜なんだけども。
別の方法でCouchDBにアクセスしてみる事にします。
PEARパッケージHTTP_Requestのインストール
CouchDBはHTTPリクエストでデータが取得出来るので、PEARパッケージHTTP_Requestをインストールして実行する事にしました。
pear install HTTP_Request
<?php require_once "HTTP/Request.php"; $http = new HTTP_Request('http://192.168.80.139:5984/test/93e4b62c166489b5ff94600e3003db88'); $response = $http->sendRequest(); var_dump($http->getResponseBody());
上記のphpの実行結果です。
php couchdb.php string(101) "{"_id":"93e4b62c166489b5ff94600e3003db88","_rev":"2-f62fade7a96a75f5bb109036ad107af0","test":"test"} "
[PR]Spreeの情報を集めています。
ECを持ちたい方、仕事でECを使いたい方向けのコミュニティサイトです。
このサイトでは世界で最も使用されているECの1つであるSpreeについての情報を提供しています。
http://spreecommerce.jp/
CentOS5.4にCouchDBをインストールする方法!
サムライファクトリーって知っていますか?ninja toolsのアクセス解析で有名ですよね?
私は社員でもなければ面識がある方もいないのですが、採用情報の"とんがった才能を世界に向けて活かしてみませんか?"のキャッチフレーズが気に入っています。
http://www.samurai-factory.jp/celebrity/
noSQLというのが盛り上がってますが、その中でも"とんがった"DB(?)であるCouchDBをインストールしてみましたので記事にしました。
(なんだかMongoDBの方が人気のようですけども…)
参考
CouchDBとMongoDBを比較してみた - Masatomo Nakano Blog
2010-02-05
CouchDBのインストール
依存パッケージのインストール
yum install automake gcc libtool erlang help2man icu libicu-devel js js-devel curl-devel
CouchDBのダウンロード
cd /usr/local/src wget http://ftp.kddilabs.jp/infosystems/apache/couchdb/0.10.1/apache-couchdb-0.10.1.tar.gz tar zxfv apache-couchdb-0.10.1.tar.gz
configureの実行
cd apache-couchdb-0.10.1 ./configure
configureが終わると下記の文字
You have configured Apache CouchDB, time to relax.
time to relax(笑)
本当かよ(笑)
次にmake&make installの実行
make make install
これでインストール完了です。
凄い簡単でした!!!
動作確認
CouchDBを起動しますが、デフォルトだとIPアドレスが127.0.0.1になっていてブラウザからアクセス出来ません。
ですので適切なIPアドレスを設定します。
(私の場合はVMwareのNAT環境でインストールしているので、192.168.80.139になります。)
local.iniの編集
cd /usr/local/etc/couchdb vim local.ini
local.iniのbind_addressの値を変更します。
;bind_address = 127.0.0.1 bind_address = 192.168.80.139
CouchDBの実行
couchdb Apache CouchDB 0.10.1 (LogLevel=info) is starting. Apache CouchDB has started. Time to relax. [info] [<0.1.0>] Apache CouchDB has started on http://192.168.80.139:5984/
ブラウザからアクセス(http://192.168.80.139:5984/)
左上にjson形式のデータが表示されています。
ブラウザからアクセス(http://192.168.80.139:5984/_utils)
管理画面が表示されました。
感動的ですね!
補足
ターミナルからCouchDBの実行をすると、rubyのwebrickの状態の様にターミナルが縛られてしまうのでscreenのインストール推奨です。
zsh + screen + vim のインストール&設定方法についてです。 - @camelmasaの開発日記
…と思ったら、下記のコマンドでバックグラウンドでcouchdbプロセス動かせました。
couchdb -b
知らなかった〜。。。
しかしログを見ながら操作したいならscreenの方が良いかも。
まとめ
CouchDBのインストールが難しいとの情報がありましたが、恐らくバージョンが上がっていたのでそれで簡単になったのではないでしょうか。
今度はphpからデータ操作やMySQLとの実行速度の比較等をしたいと思います!
[PR]Spreeの情報を集めています。
ECを持ちたい方、仕事でECを使いたい方向けのコミュニティサイトです。
このサイトでは世界で最も使用されているECの1つであるSpreeについての情報を提供しています。
http://spreecommerce.jp/