Skip to content

Instantly share code, notes, and snippets.

@eb-eoliveira
Created February 20, 2013 02:11
Show Gist options
  • Save eb-eoliveira/4992122 to your computer and use it in GitHub Desktop.
Save eb-eoliveira/4992122 to your computer and use it in GitHub Desktop.
Fatcache second test
<?php
$m = new Memcached();
$m->addServer('localhost', 11211, 33);
$items = 500000;
$keysToGet = array();
for ($i = 1; $i <= $items; ++$i) {
$key = md5(rand());
$value = md5(rand()). md5(rand()) . md5(rand()) . md5(rand()) . md5(rand());
$m->set($key, $value, rand(60, 600));
if (rand(1,10) == 1) {
$keysToGet[] = $key;
}
}
echo "Sleeping...\n";
sleep(10); // give enough time to flush to disk
// add more keys to replace the hot keys inserted before
for ($i = 1; $i <= $items; ++$i) {
$key = md5(rand());
$value = md5(rand()). md5(rand()) . md5(rand()) . md5(rand()) . md5(rand());
$m->set($key, $value, rand(60, 600));
}
$start = time();
foreach ($keysToGet as $key) {
$m->get($key);
}
$end = time();
echo "\nSummary\n";
echo "Items: " . count($keysToGet) . "\n";
echo "Start time: $start\n";
echo "End time: $end\n";
echo "Operations/s: " . (count($keysToGet)/($end-$start)) . "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment