Created
January 9, 2020 01:45
-
-
Save kmuthukk/0a789f2330b89780683ba725af5bead5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$ip = '127.0.0.1'; | |
$cluster = Cassandra::cluster() | |
->withDefaultConsistency(Cassandra::CONSISTENCY_QUORUM) | |
->withContactPoints($ip) | |
->build(); | |
$session = $cluster->connect(); | |
$session->execute("CREATE KEYSPACE IF NOT EXISTS k"); | |
$session->execute("USE k"); | |
$session->execute("DROP TABLE IF EXISTS users"); | |
print("Dropped users table (if exists)\n"); | |
$session->execute(" | |
CREATE TABLE IF NOT EXISTS users( | |
id text, | |
name text, | |
age int, | |
PRIMARY KEY(id) | |
) WITH TRANSACTIONS = {'enabled' : false}"); | |
print("Created users table\n"); | |
print("-------\n"); | |
$statement = new Cassandra\SimpleStatement('INSERT INTO users (id, name, age) VALUES (?, ?, ?)'); | |
$start = microtime(true); | |
$row_cnt=4000; | |
for($idx=0;$idx<$row_cnt;$idx++) { | |
$options = array('arguments' => array('user-0-' . $idx, 'name--'.$idx, 20+($idx%50))); | |
$rows = $session->execute($statement, $options); | |
} | |
$taken = round(microtime(true)-$start,2); | |
echo 'Insert ops per sec: '. $row_cnt/$taken."\n"; | |
echo 'Avg insert latency (ms): ' . round($taken*1000/$row_cnt, 2) . "\n"; | |
print("-------\n"); | |
$statement = new Cassandra\SimpleStatement('SELECT * FROM k.users where id = ?'); | |
$start = microtime(true); | |
for($idx=0;$idx<$row_cnt;$idx++) { | |
$options = array('arguments' => array('user-0-' . $idx)); | |
$rows = $session->execute($statement, $options); | |
} | |
$taken = round(microtime(true)-$start,2); | |
print_r($rows->first()); | |
echo 'Read ops per sec: '.$row_cnt/$taken."\n"; | |
echo 'Avg read latency (ms): ' . round($taken*1000/$row_cnt, 2) . "\n"; | |
print("-------\n"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment