Created
November 2, 2016 22:02
-
-
Save mpenick/9b796167d865e6ade10cacc06f3dab74 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 | |
| #$cluster = Dse::cluster()->build(); | |
| define("NUM_ITERATIONS", 1000); | |
| define("MICROSECONDS", 1000 * 1000); | |
| define("PERCENTILES", array(0.0, 0.5, 0.75, 0.95, 0.98, 0.99, 0.999, 0.9999, 1.0)); | |
| function print_histogram($histogram) { | |
| ksort($histogram); | |
| printf("Percentiles (microseconds): "); | |
| foreach (PERCENTILES as $percentile) { | |
| $count = 0; | |
| $total = NUM_ITERATIONS * $percentile; | |
| foreach($histogram as $time => $num) { | |
| $count += $num; | |
| if ($count >= $total) { | |
| $label = $percentile == 0 ? "min" : ($percentile == 1 ? "max" : (string)$percentile); | |
| printf("%s: %d ", $label, $time); | |
| break; | |
| } | |
| } | |
| } | |
| printf("\n"); | |
| } | |
| function test_whitelist($hosts, $use_persistent) { | |
| $accumulated = 0; | |
| $histogram = array(); | |
| $statement = new Cassandra\SimpleStatement("SELECT * FROM system.peers"); | |
| $start_total = microtime(true); | |
| for ($i = 0; $i < NUM_ITERATIONS; $i++) { | |
| $start = microtime(true); | |
| $cluster = Cassandra::cluster() | |
| ->withContactPoints($hosts) | |
| ->withWhiteListHosts($hosts) | |
| ->withPersistentSessions($use_persistent) | |
| ->withTokenAwareRouting(false) | |
| ->withSchemaMetadata(false) | |
| ->build(); | |
| $session = $cluster->connect(); | |
| $session->execute($statement); | |
| $session->close(); | |
| $elapsed = (microtime(true) - $start) * MICROSECONDS; | |
| $accumulated += $elapsed; | |
| $histogram[(int)$elapsed] += 1; | |
| } | |
| $elapsed_total = microtime(true) - $start_total; | |
| printf("Average time (microseconds): %f\n", $accumulated / NUM_ITERATIONS); | |
| printf("Total time (seconds): %f\n", $elapsed_total); | |
| print_histogram($histogram); | |
| } | |
| function test_regular($hosts, $use_persistent) { | |
| $accumulated = 0; | |
| $histogram = array(); | |
| $statement = new Cassandra\SimpleStatement("SELECT * FROM system.peers"); | |
| $start_total = microtime(true); | |
| for ($i = 0; $i < NUM_ITERATIONS; $i++) { | |
| $start = microtime(true); | |
| $cluster = Cassandra::cluster() | |
| ->withContactPoints($hosts) | |
| ->withPersistentSessions($use_persistent) | |
| ->withTokenAwareRouting(false) | |
| ->withSchemaMetadata(false) | |
| ->build(); | |
| $session = $cluster->connect(); | |
| $session->execute($statement); | |
| $session->close(); | |
| $elapsed = (microtime(true) - $start) * MICROSECONDS; | |
| $accumulated += $elapsed; | |
| $histogram[(int)$elapsed] += 1; | |
| } | |
| $elapsed_total = microtime(true) - $start_total; | |
| printf("Average time (microseconds): %f\n", $accumulated / NUM_ITERATIONS); | |
| printf("Total time (seconds): %f\n", $elapsed_total); | |
| print_histogram($histogram); | |
| } | |
| printf("Whitelist w/o persistent sessions:\n"); | |
| test_whitelist("127.0.0.1", false); | |
| printf("\n"); | |
| printf("Whitelist w/ persistent sessions:\n"); | |
| test_whitelist("127.0.0.1", true); | |
| printf("\n"); | |
| printf("No whitelist w/o persistent sessions:\n"); | |
| test_regular("127.0.0.1", false); | |
| printf("\n"); | |
| printf("No whitelist w/ persistent sessions:\n"); | |
| test_regular("127.0.0.1", true); | |
| printf("\n"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment