Created
October 26, 2015 03:16
-
-
Save safecat/21c0c1f39763aa62ba88 to your computer and use it in GitHub Desktop.
Memcached Benchmark Script
This file contains 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 | |
if(!class_exists('Memcached')){ | |
die('class Memcached not found.'); | |
} | |
$mc = new Memcached(); | |
$mc->addServer('127.0.0.1', 11211); | |
if(!$mc){ | |
die('Memcached connection error.'); | |
} | |
$data = str_pad('', 1000); | |
$msetData = []; | |
for ($i=0; $i < 10000; $i++) { | |
$msetData[$i%10]['bench_'.$i] = $data; | |
} | |
$start = microtime(1); | |
$time = []; | |
echo "Start testing.\r\n"; | |
$mc->touch('bench_test', 1); | |
recordTime('touch'); | |
echo "1KB data set, 10000 times, starting... "; | |
for ($i=0 ; $i< 10000 ; $i++) { | |
$mc->set('bench_'.$i, $data); | |
if($i % 100 != 0) continue; | |
echo "\033[5D"; | |
echo str_pad($i/100+1, 3, ' ', STR_PAD_LEFT) . " %"; | |
} | |
echo "\r\n"; | |
recordTime('set'); | |
echo "1KB data get, 10000 times, starting... "; | |
for ($i=0 ; $i< 10000 ; $i++) { | |
$mc->get('bench_'.$i); | |
if($i % 100 != 0) continue; | |
echo "\033[5D"; | |
echo str_pad($i/100+1, 3, ' ', STR_PAD_LEFT) . " %"; | |
} | |
echo "\r\n"; | |
recordTime('get'); | |
echo "1KB data delete, 10000 times, starting... "; | |
for ($i=0 ; $i< 10000 ; $i++) { | |
$mc->delete('bench_'.$i); | |
if($i % 100 != 0) continue; | |
echo "\033[5D"; | |
echo str_pad($i/100+1, 3, ' ', STR_PAD_LEFT) . " %"; | |
} | |
echo "\r\n"; | |
recordTime('delete'); | |
echo "1KB data, 1000 row setMulti, 10 times, starting... "; | |
for ($i=0 ; $i< 10 ; $i++) { | |
$mc->setMulti($msetData[$i]); | |
echo "\033[5D"; | |
echo str_pad($i*10+10, 3, ' ', STR_PAD_LEFT) . " %"; | |
} | |
echo "\r\n"; | |
recordTime('setMulti'); | |
echo "1KB data, 1000 row getMulti, 10 times, starting... "; | |
for ($i=0 ; $i< 10 ; $i++) { | |
$s = $mc->getMulti(array_keys($msetData[$i])); | |
echo "\033[5D"; | |
echo str_pad($i*10+10, 3, ' ', STR_PAD_LEFT) . " %"; | |
} | |
echo "\r\n"; | |
recordTime('getMulti'); | |
echo "1KB data, 1000 row deleteMulti, 10 times, starting... "; | |
for ($i=0 ; $i< 10 ; $i++) { | |
$s = $mc->deleteMulti(array_keys($msetData[$i])); | |
echo "\033[5D"; | |
echo str_pad($i*10+10, 3, ' ', STR_PAD_LEFT) . " %"; | |
} | |
echo "\r\n"; | |
recordTime('deleteMulti'); | |
print_r($time); | |
function recordTime($action){ | |
global $start; | |
global $time; | |
static $last; | |
if(!$last) $last = $start; | |
$time[$action] = number_format((microtime(1) - $last)*1000, 2); | |
$last = microtime(1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
test result on my MBA and ucloud