Cassandra集群在同步写、异步写及读取的性能测试
环境和说明
同机房,硬件不完全一样
CPU大概为
Thread(s) per core: 1
Core(s) per socket: 4
Socket(s): 2
NUMA node(s): 2
Vendor ID: GenuineIntel
CPU family: 6
Model: 26
Stepping: 5
CPU MHz: 2128.028
BogoMIPS: 4255.36
内存:16G
本集群replication_factor 为2
都用6个php-cli进程执行
Step Length,为每批执行的次数
写入
同步写入(execute)
主要代码
$statement = $ca->prepare("insert into users(uid,name,dateline,credit,grade,sign) values (?, ?, ?, ?, ?, ?)");
$i = 1;
$batchNum = 10000;
$now = time();
$mtime = microtime(1);
$start = $now * 10000 * 10000;
$batchNum = mdlInput::get('step');
while (1) {
$name = '';
$j = 10;
while (--$j) {
$name .= chr(mt_rand(65, 90));
}
$args = new \Cassandra\ExecutionOptions([
'arguments' => [new \Cassandra\Bigint($start + $i), $name, time(), mt_rand(1, 9999), mt_rand(1, 99), str_repeat($name, 3)]
]);
$ca->execute($statement, $args);
if ($i % $batchNum == 0) {
$cost = microtime(1) - $mtime;
$cost = round($cost, 6);
$mtime = microtime(1);
$cur = $start + $i;
echo "Step Length: $batchNum, Current: $cur, cost $cost sec\n";
}
$i++;
}
部分输出内容
Step Length: 10000, Current: 143685842502460000, cost 5.561623 sec
Step Length: 10000, Current: 143685844202450000, cost 5.364269 sec
Step Length: 10000, Current: 143685842202460000, cost 5.220673 sec
Step Length: 10000, Current: 143685845102380000, cost 5.470677 sec
Step Length: 10000, Current: 143685843102510000, cost 5.519043 sec
Step Length: 10000, Current: 143685842502470000, cost 5.460956 sec
...
5个节点负载都在1-2之间。
异步写入(executeAsync)
主要代码
除 $ca->executeAsync($statement, $args);
其他同上
部分输出内容
Step Length: 100000, Current: 143686070908800000, cost 5.215121 sec
Step Length: 100000, Current: 143686069709000000, cost 4.712783 sec
Step Length: 100000, Current: 143686072308300000, cost 4.613689 sec
Step Length: 100000, Current: 143686070409000000, cost 5.161028 sec
Step Length: 100000, Current: 143686069209400000, cost 5.324405 sec
...
读取(execute)
主要代码
$statement = $ca->prepare("select name from users_100w where uid = ?");
//
$i = 1;
$max = 100 * 10000;
$mtime = microtime(1);
$batchNum = 1000;
while (1) {
$args = new \Cassandra\ExecutionOptions([
'arguments' => [new \Cassandra\Bigint(mt_rand(1, $max))]
]);
$ret = $ca->execute($statement, $args);
if ($i % $batchNum == 0) {
$cost = microtime(1) - $mtime;
$cost = round($cost, 6);
$mtime = microtime(1);
echo "Num: $batchNum, cost $cost sec\n";
}
$i++;
}
部分输出内容
Num: 1000, cost 0.849658 sec
Num: 1000, cost 0.824387 sec
Num: 1000, cost 0.850895 sec
Num: 1000, cost 0.769483 sec
...
本集群有5个Cassandra节点,replication_factor为2。用6个php-cli进程执行,每次10000条。分别测试Cassandra集群在同步写、异步写及读取的性能测试。
测试以Datastax Opscenter图表,去除波峰、波谷按平稳的数值为结果。分别为同步写入9500次/秒,异步写入71000次/秒,49000次/秒。明显可以看出同步写入因为等写入结果阻塞了后续的写入,速度仅为异步写入的13%左右,所以在一些不要求实时返回结果的情况的下,要用异步写入。



发表评论