Cassandra phpcassaと爆速ネイティブPHPエクステンションkassandraのパフォーマンス比較
スポンサーリンク
このドキュメントの内容は、以下の通りです。
- はじめに
- エグゼクティブサマリ
- 仕様した技術やツール
- 実験環境
- ConsistencyLevel
- テストコード phpcassa
- テストコード kassandra
- abによるベンチマーク
- Benchmark/Timer.php によるベンチマーク
- ColumnFamily と phpcassa
- ColumnFamily と SuperColumnFamily の比較
- APCについて
- SuperColumnFamilyのab
- SuperColumnFamily単体ベンチマーク
- 結論
はじめに
このドキュメントは、適当なオレオレライブラリで、本当に小さなデータに対して、適当にベンチマークしただけです。
NoSQL の Cassandra のクライアントのベンチマークです。
phpcassa は、PHPと一部がC++でかかれた PHP 用の Cassandra クライアントです。
phpcassa でプログラムを書いていると、スピードが出ないということが問題になり、ためしにC++でプログラムを書いて、ネイティブのphp extensionを作って比較してみました。
libkassandra と php extension kassandra は、非公式で、かつ、非公開のオレオレライブラリとオレオレエクステンションです。
cassandra ノードの接続を永続的に持てます。
エグゼクティブサマリ
まず、最初に結論を書きます。
- PHP エクステンションは、爆速でした。低水準言語最強。
- APC をデフォルトで使うと phpcassa がなぜか爆遅。
仕様した技術やツール
言語
- C++
- boost
- thrift
- thrift コマンドで生成されたコード
- CodeGen_PECL
実験環境
仮想環境で実験しているため、実機ならもっと性能が出るはずです。
- VMWare Player 環境で実行
- FreeBSD 9.0-RELEASE i386
- CPU 4 Core
- メモリ 1GB
- マスターホストは Windows 7 64bit
- Apache/2.2.23
- httpd のクライアント用プロセスは 3プロセス
- PHP 5.4.11
- apc なし(apcありも一応やってみた)
- Cassandra 1.2.0
- Java
- java version "1.6.0_07"
- Diablo Java(TM) SE Runtime Environment (build 1.6.0_07-b02)
- Diablo Java HotSpot(TM) Client VM (build 10.0-b23, mixed mode, sharing)
ConsistencyLevel
コンカレントレベルの設定について。 hpcassa のデフォルトの ConsistencyLevel は 1 です。
オレオレライブラリとphpcassa は、どちらも ConsistencyLevel は 1 に設定しています。
テストコード phpcassa
phpcassa を使ったテストコードは以下の通りです。
<?php
require_once(__DIR__.'/../lib/autoload.php');
use phpcassa\Connection\ConnectionPool;
use phpcassa\ColumnFamily;
use phpcassa\SystemManager;
use phpcassa\Schema\StrategyClass;
// Start a connection pool, create our ColumnFamily instance
$pool = new ConnectionPool('test', array('127.0.0.1'));
$users = new ColumnFamily($pool, 'c1');
// Fetch a record
$r = $users->get('a');
var_dump ($r);
?>
テストコード kassandra
PHP extensionのテストコードは以下の通りです。
<?php
if (! kassandra_is_connected () ) {
$server ="127.0.0.1";
$b = kassandra_connect($server);
if ($b === false) {
error_log ("can not connect $server");
exit;
}
}
$a = kassandra_get_row("test", "c1", "a", 1);
print_r ($a);
?>
abによるベンチマーク
phpcassaのベンチマーク
phpcassa
ab -n 1000 -c 10 http://127.0.0.1/test.php
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 127.0.0.1 (be patient)
Server Software: Apache/2.2.23
Server Hostname: 127.0.0.1
Server Port: 80
Document Path: /test.php
Document Length: 99 bytes
Concurrency Level: 10
Time taken for tests: 26.828 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 310000 bytes
HTML transferred: 99000 bytes
Requests per second: 37.28 [#/sec] (mean)
Time per request: 268.275 [ms] (mean)
Time per request: 26.828 [ms] (mean, across all concurrent requests)
Transfer rate: 11.28 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.4 0 8
Processing: 222 267 44.4 259 648
Waiting: 222 267 44.4 259 648
Total: 222 267 44.4 259 648
Percentage of the requests served within a certain time (ms)
50% 259
66% 270
75% 281
80% 289
90% 303
95% 357
98% 414
99% 466
100% 648 (longest request)
kassandra 接続永続化
kassandra
ab -n 1000 -c 10 http://127.0.0.1/kassandra_test.php
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 127.0.0.1 (be patient)
Server Software: Apache/2.2.23
Server Hostname: 127.0.0.1
Server Port: 80
Document Path: /kassandra_test.php
Document Length: 487 bytes
Concurrency Level: 10
Time taken for tests: 1.700 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 699000 bytes
HTML transferred: 487000 bytes
Requests per second: 588.30 [#/sec] (mean)
Time per request: 16.998 [ms] (mean)
Time per request: 1.700 [ms] (mean, across all concurrent requests)
Transfer rate: 401.58 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.8 0 20
Processing: 5 17 11.2 13 92
Waiting: 5 16 11.0 13 92
Total: 5 17 11.5 14 93
Percentage of the requests served within a certain time (ms)
50% 14
66% 15
75% 16
80% 17
90% 22
95% 44
98% 58
99% 66
100% 93 (longest request)
kassandra 毎回接続を切る
echo "kassandra disconnect"
kassandra disconnect
ab -n 1000 -c 10 http://127.0.0.1/kassandra_test_disconnect.php
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 127.0.0.1 (be patient)
Server Software: Apache/2.2.23
Server Hostname: 127.0.0.1
Server Port: 80
Document Path: /kassandra_test_disconnect.php
Document Length: 501 bytes
Concurrency Level: 10
Time taken for tests: 1.737 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 713713 bytes
HTML transferred: 501501 bytes
Requests per second: 575.83 [#/sec] (mean)
Time per request: 17.366 [ms] (mean)
Time per request: 1.737 [ms] (mean, across all concurrent requests)
Transfer rate: 401.35 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.2 0 2
Processing: 1 17 12.9 14 145
Waiting: 1 17 12.8 14 144
Total: 1 17 13.0 14 145
Percentage of the requests served within a certain time (ms)
50% 14
66% 16
75% 17
80% 17
90% 23
95% 38
98% 57
99% 90
100% 145 (longest request)
ab によるテストのまとめ
phpcassa と接続永続板のkassandra の時間のかかり方が圧倒的に違いますwww。
- phpcassa: Time taken for tests: 26.828 seconds
- kassandra: Time taken for tests: 1.700 seconds
- phpcassa: Time per request: 268.275 [ms] (mean)
- kassandra: Time per request: 16.998 [ms] (mean)
Benchmark/Timer.php によるベンチマーク
phpcassa
<?php
include ('Benchmark/Timer.php');
$oTimer =new Benchmark_Timer();
$oTimer->start ();
require_once(__DIR__.'/../lib/autoload.php');
use phpcassa\Connection\ConnectionPool;
use phpcassa\ColumnFamily;
use phpcassa\SystemManager;
use phpcassa\Schema\StrategyClass;
// Start a connection pool, create our ColumnFamily instance
$oTimer->setMarker( 'connect' );
$pool = new ConnectionPool('test', array('127.0.0.1'));
$users = new ColumnFamily($pool, 'c1');
$oTimer->setMarker( 'get row 1' );
// Fetch a user record
$user = $users->get('a');
$oTimer->stop ();
$oTimer->display ();
?>
-------------------------------------------------------- marker time index ex time perct -------------------------------------------------------- Start 1361199567.23655100 - 0.00% -------------------------------------------------------- connect 1361199567.27422900 0.037678 17.99% -------------------------------------------------------- get row 1 1361199567.39927800 0.125049 59.70% -------------------------------------------------------- Stop 1361199567.44601300 0.046735 22.31% -------------------------------------------------------- total - 0.209462 100.00% --------------------------------------------------------
kassandra
<?php
include ('Benchmark/Timer.php');
$oTimer =new Benchmark_Timer();
$oTimer->start ();
if (! kassandra_is_connected () ) {
$server ="127.0.0.1";
$oTimer->setMarker( 'connect' );
$b = kassandra_connect($server);
if ($b === false) {
error_log ("can not connect $server");
exit;
}
}
$oTimer->setMarker( 'get row' );
$a = kassandra_get_row("test", "c1", "a", 1);
$oTimer->stop ();
$oTimer->display ();
?>
------------------------------------------------------ marker time index ex time perct ------------------------------------------------------ Start 1361198652.00585000 - 0.00% ------------------------------------------------------ connect 1361198652.00611300 0.000263 1.07% ------------------------------------------------------ get row 1361198652.01227900 0.006166 25.05% ------------------------------------------------------ Stop 1361198652.03046200 0.018183 73.88% ------------------------------------------------------ total - 0.024612 100.00% ------------------------------------------------------
ColumnFamily と phpcassa
ConnectionPoolとColumnFamilyをnewしただけだと接続されないのか、最初の get に時間がかかることがわかりました。
<?php
$pool = new ConnectionPool('test', array('127.0.0.1'));
$users = new ColumnFamily($pool, 'c1');
$oTimer->setMarker( 'get row 1' );
$user = $users->get('a');
$oTimer->setMarker( 'get row 2' );
$user = $users->get('a');
$oTimer->setMarker( 'new super column family' );
$s1 = new SuperColumnFamily($pool, 's1');
$oTimer->setMarker( 'get row super column' );
$a = $s1->get_super_column("a", "b1");
?>
---------------------------------------------------------------------- marker time index ex time perct ---------------------------------------------------------------------- Start 1361199140.88125400 - 0.00% ---------------------------------------------------------------------- connect 1361199140.88159400 0.000340 0.17% ---------------------------------------------------------------------- get row 1 1361199141.01177100 0.130177 66.25% ---------------------------------------------------------------------- get row 2 1361199141.05777700 0.046006 23.41% ---------------------------------------------------------------------- new super column family 1361199141.06445000 0.006673 3.40% ---------------------------------------------------------------------- get row super column 1361199141.07216500 0.007715 3.93% ---------------------------------------------------------------------- Stop 1361199141.07773500 0.005570 2.83% ---------------------------------------------------------------------- total - 0.196481 100.00% ----------------------------------------------------------------------
ColumnFamily と SuperColumnFamily の比較
SuperColumn だとphpcassaと差がないように見える。。。
php kassandra
------------------------------------------------------------------- marker time index ex time perct ------------------------------------------------------------------- Start 1361199434.42020400 - 0.00% ------------------------------------------------------------------- connect 1361199434.42046000 0.000256 0.88% ------------------------------------------------------------------- get row 1361199434.42669600 0.006236 21.44% ------------------------------------------------------------------- get row super column 1361199434.44267300 0.015977 54.94% ------------------------------------------------------------------- Stop 1361199434.44928400 0.006611 22.73% ------------------------------------------------------------------- total - 0.029080 100.00% -------------------------------------------------------------------
APCについて
入ってて当然、と思ってたけど、実は apc が入ってなかったということに、ベンチマークをだいたいとって気づきました。
ただたんに apc を入れて、apache を再起動して ab を走らせたら、不思議なことに phpcassa が爆遅になって、ネイティブエクステンションは、爆速になったという結果でした。
phpcassa
ab -n 1000 -c 10 http://127.0.0.1/test.php
Document Path: /test.php
Document Length: 99 bytes
Concurrency Level: 10
Time taken for tests: 41.528 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 310000 bytes
HTML transferred: 99000 bytes
Requests per second: 24.08 [#/sec] (mean)
Time per request: 415.275 [ms] (mean)
Time per request: 41.528 [ms] (mean, across all concurrent requests)
Transfer rate: 7.29 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.2 0 3
Processing: 358 413 72.3 374 957
Waiting: 358 413 72.2 374 957
Total: 358 414 72.4 374 958
Percentage of the requests served within a certain time (ms)
50% 374
66% 452
75% 476
80% 479
90% 484
95% 491
98% 567
99% 772
100% 958 (longest request)
kassandra
ab -n 1000 -c 10 http://127.0.0.1/kassandra_test.php
Document Path: /kassandra_test.php
Document Length: 487 bytes
Concurrency Level: 10
Time taken for tests: 0.942 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 699000 bytes
HTML transferred: 487000 bytes
Requests per second: 1061.63 [#/sec] (mean)
Time per request: 9.419 [ms] (mean)
Time per request: 0.942 [ms] (mean, across all concurrent requests)
Transfer rate: 724.69 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.8 0 19
Processing: 1 9 6.7 6 46
Waiting: 1 9 6.6 6 43
Total: 1 9 6.9 6 46
Percentage of the requests served within a certain time (ms)
50% 6
66% 8
75% 10
80% 14
90% 19
95% 22
98% 28
99% 39
100% 46 (longest request)
kassandra disconnect
ab -n 1000 -c 10 http://127.0.0.1/kassandra_test_disconnect.php
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Document Path: /kassandra_test_disconnect.php
Document Length: 501 bytes
Concurrency Level: 10
Time taken for tests: 1.109 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 713713 bytes
HTML transferred: 501501 bytes
Requests per second: 901.47 [#/sec] (mean)
Time per request: 11.093 [ms] (mean)
Time per request: 1.109 [ms] (mean, across all concurrent requests)
Transfer rate: 628.31 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.7 0 18
Processing: 1 11 6.3 9 45
Waiting: 1 10 6.2 8 45
Total: 1 11 6.4 9 45
Percentage of the requests served within a certain time (ms)
50% 9
66% 10
75% 11
80% 13
90% 22
95% 26
98% 29
99% 32
100% 45 (longest request)
SuperColumnFamilyのab
phpcassa
Time taken for tests: 25.821 seconds
Total transferred: 278000 bytes
HTML transferred: 67000 bytes
Requests per second: 38.73 [#/sec] (mean)
Time per request: 258.211 [ms] (mean)
Time per request: 25.821 [ms] (mean, across all concurrent requests)
Transfer rate: 10.51 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.2 0 5
Processing: 86 257 26.0 251 355
Waiting: 85 257 26.0 251 355
Total: 86 257 26.0 251 355
kassandra
Concurrency Level: 10 Time taken for tests: 1.507 seconds Complete requests: 1000 Total transferred: 721000 bytes HTML transferred: 509000 bytes Requests per second: 663.68 [#/sec] (mean) Time per request: 15.068 [ms] (mean) Time per request: 1.507 [ms] (mean, across all concurrent requests) Transfer rate: 467.30 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.7 0 8 Processing: 5 15 16.2 12 195 Waiting: 4 15 16.2 12 195 Total: 5 15 16.6 12 197
SuperColumnFamily単体ベンチマーク
phpcassa
------------------------------------------------------------------- marker time index ex time perct ------------------------------------------------------------------- Start 1361282357.67336200 - 0.00% ------------------------------------------------------------------- connect 1361282357.70912200 0.035760 16.27% ------------------------------------------------------------------- get row super column 1361282357.84196800 0.132846 60.45% ------------------------------------------------------------------- Stop 1361282357.89311100 0.051143 23.27% ------------------------------------------------------------------- total - 0.219749 100.00% -------------------------------------------------------------------
kassandra
------------------------------------------------------------------- marker time index ex time perct ------------------------------------------------------------------- Start 1361282257.60718500 - 0.00% ------------------------------------------------------------------- connect 1361282257.60764500 0.000460 1.45% ------------------------------------------------------------------- get row super column 1361282257.61404600 0.006401 20.14% ------------------------------------------------------------------- Stop 1361282257.63897000 0.024924 78.41% ------------------------------------------------------------------- total - 0.031785 100.00% -------------------------------------------------------------------
結論
- ネイティブのエクステンション最強です。爆速です。
- 単体で見て10倍ぐらい違う。
- 1000回のリクエストで20倍ぐらいは余裕で違う。
- 永続的コネクションと毎回コネクションを張るのは、1000程度のリクエストだと大きな差は見えないけど、やっぱり永続的コネクションのほうが速い(に決まってる)です。
- Column Family と Super Column Family のcolumn取得時間の差は、ネイティブコードだと 0.01 秒の差がありました。
- phpcassaのColumnFamilyとSuper Column Familyでも0.01 秒でした。
- apc 入れたら phpcassa が爆遅になってしまった。
- まったくチューニングしてないからかもしれない。
- 「圧倒的じゃないか、我が軍は。」
- 「言語の性能の差が戦力の決定的な差」
スポンサーリンク
スポンサーリンク
いつもシェア、ありがとうございます!
もっと情報を探しませんか?
関連記事
最近の記事
- パナソニック ジェットウォッシャードルツ EW-DJ61-Wのホースの修理
- LinuxセキュリティモジュールIntegrity Policy Enforcement
- アマゾンのEcho Show 5を買ったのでレビューします
- アマゾンのサイバーマンデーはAlexa Echo Show 5が安い
- Android スマートフォン OnePlus 7T と OnePlus 7の違い
- Android スマートフォン OnePlus 7 をAndroid10にアップデートしてみた
- クレジットカードのバーチャルカードの比較のまとめ
- 活動量計 Xiaomi Mi Band 4を買ってみたのでレビュー
- Android スマートフォン OnePlus 7 のレビュー
- AliExpressでスマートフォンを買い物してみた
- パソコンのホコリ対策 レンジフードフィルターと養生テープ
- 80PLUS GOLDのPC電源ユニットAntec NeoEco 750 Goldのレビュー
- イギリスの付加価値税 VAT は払い戻しを受けられる
- イギリスのロンドンでスーツケースなど荷物を預けられる場所は
- イギリスのロンドンで地下鉄やバスに乗るならオイスターカードを使おう
- イギリスのヒースロー空港からロンドン市内への行き方
- 航空便でほかの航空会社に乗り継ぎがある場合のオンラインチェックイン
- SFC会員がANA便ではなくベトナム航空のコードシェアを試して解ったこと
- ベトナムの入国審査でeチケットの掲示が必要だった話
- シアトルの交通ICカードはオルカカード(Orca)です
人気のページ
- Windows7 IME 辞書ツールで単語の登録に失敗しました
- C言語 popen()でコマンドを実行して出力を読み込む
- Windows7で休止状態にする方法
- CentOS MySQLの起動、停止、再起動
- loggerコマンドでsyslogにエラーを出力する方法
- パソコンパーツの買取をしてくれる店のまとめ
- Java Mapの使い方 get(),put(),remove(),size(),clear()
- 楽天のRポイントカードを作ってみた
- iPhone 5 から iPhone 6 に乗り換えたのでレビュー
- netstatコマンドのステータスの意味
スポンサーリンク
過去ログ
2020 : 01 02 03 04 05 06 07 08 09 10 11 122019 : 01 02 03 04 05 06 07 08 09 10 11 12
2018 : 01 02 03 04 05 06 07 08 09 10 11 12
2017 : 01 02 03 04 05 06 07 08 09 10 11 12
2016 : 01 02 03 04 05 06 07 08 09 10 11 12
2015 : 01 02 03 04 05 06 07 08 09 10 11 12
2014 : 01 02 03 04 05 06 07 08 09 10 11 12
2013 : 01 02 03 04 05 06 07 08 09 10 11 12
2012 : 01 02 03 04 05 06 07 08 09 10 11 12
2011 : 01 02 03 04 05 06 07 08 09 10 11 12
2010 : 01 02 03 04 05 06 07 08 09 10 11 12
2009 : 01 02 03 04 05 06 07 08 09 10 11 12
2008 : 01 02 03 04 05 06 07 08 09 10 11 12
2007 : 01 02 03 04 05 06 07 08 09 10 11 12
2006 : 01 02 03 04 05 06 07 08 09 10 11 12
2005 : 01 02 03 04 05 06 07 08 09 10 11 12
2004 : 01 02 03 04 05 06 07 08 09 10 11 12
2003 : 01 02 03 04 05 06 07 08 09 10 11 12