if (!$db->isConnected()) { echo fail("Could not connect to host {$addr}:{$port} [{$db->errorno()}]: {$db->error()}"); exit(1); } echo success(); echo colorize("Assuming that write.php was run before to create {$total_ops} records in test.performance\n", 'black', false); $key = $db->initKey("test", "performance", "write"); $v = 0; $reads = 0; $read_fails = 0; $begin = microtime(true); echo colorize("Read {$total_ops} records ≻", 'black', true); for ($num_ops = 1; $num_ops <= $total_ops; $num_ops++) { $v++; $key['key'] = 'write-' . $v; $res = $db->get($key, $record); $reads++; if ($res !== Aerospike::OK) { $read_fails++; $v--; } } $end = microtime(true); if ($read_fails == 0) { echo success(); } else { echo standard_fail($db); } echo colorize("{$reads} sequential reads\n", 'green', true); $color = $read_fails > 0 ? 'red' : 'green'; echo colorize("Failed reads: {$read_fails}\n", $color, true);
$kv = array('v' => 0); $res = $db->put($key, $kv); if ($res !== Aerospike::OK) { $end = microtime(true); $delta = $end - $begin; $tps = 1 / $delta; file_put_contents($log, "{$pid}|1|{$delta}|{$tps}|0|0|1|1\n", FILE_APPEND); exit(2); } $writes++; for ($num_ops = 1; $num_ops < $total_ops; $num_ops++) { if ($num_ops % $write_every == 0) { $kv['v'] = $num_ops; $res = $db->put($key, $kv); $writes++; if ($res !== Aerospike::OK) { $write_fails++; } } else { $res = $db->get($key, $r); $reads++; if ($res !== Aerospike::OK) { $read_fails++; } } } $end = microtime(true); $delta = $end - $begin; $tps = $num_ops / $delta; file_put_contents($log, "{$pid}|{$num_ops}|{$delta}|{$tps}|{$reads}|{$read_fails}|{$writes}|{$write_fails}\n", FILE_APPEND); $db->close();
$record = array("name" => "name" . $i, "age" => $i); $status = $db->put($key, $record); if ($status != Aerospike::OK) { echo "\nMultiput failed at " . $i . "th record"; break; } } $db->close(); } else { echo "Aerospike DB connection is not established"; } }); $app->get('/get', function () use($db) { if ($db->isConnected()) { $key = $db->initKey("test", "demo", "key1"); $status = $db->get($key, $record); var_dump($record); if ($status != Aerospike::OK) { echo "Get operation failed"; } $db->close(); } else { echo "Aerospike DB connection is not established"; } }); $app->get('/multiget', function () use($db) { if ($db->isConnected()) { for ($i = 0; $i < 100; $i++) { $key = $db->initKey("test", "demo", "key" . $i); $status = $db->get($key, $record); var_dump($record);