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)

write 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)

write async

主要代码

除 $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)

read

主要代码

$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个节点负载都在1左右之间。

发表评论