您的位置:首页 > 数据库 > Memcache

新浪云计算数据缓存性能测试(文件、KVDB、Memcache)

2015-05-28 11:17 543 查看
<?php
$times = 1000; //测试的次数
$str_len = 50000; //数据长度
$storage_domain = 'test1'; //存储域

function genRandomString($len)
{
$chars = array(
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",
"l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",
"w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G",
"H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R",
"S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2",
"3", "4", "5", "6", "7", "8", "9"
);

$output = "";
for ($i=0; $i<$len; $i++)
{
$output .= $chars[mt_rand(0, 61)];
}

return $output;
}

$content = genRandomString($str_len);

//写入文本文件测试
$s = new SaeStorage();
$starttimer = microtime(true);
for($o = 0 ; $o < $times; $o++){
$s->write($storage_domain, 'test'.$o.'.txt', $content);
}
$stoptimer = microtime(true);

$timer = $stoptimer-$starttimer;
echo "Data Write $times times by txt in $timer seconds.<br />";

//读取文本文件测试
$starttimer = microtime(true);
for($o = 0 ; $o < $times; $o++){
$s->read($storage_domain, 'test'.$o.'.txt');
}
$stoptimer = microtime(true);

$timer = $stoptimer-$starttimer;
echo "Data Read $times times by txt in $timer seconds.<br />";
unset($s);

//KVDB写入测试
$kv = new SaeKVClient();
$kv->init();
$starttimer = microtime(true);
for($o = 0 ; $o < $times; $o++){
$kv->set('test'.$o, $content);
}
$stoptimer = microtime(true);

$timer = $stoptimer-$starttimer;
echo "Data Write $times times by KVDB in $timer seconds.<br />";

//KVDB读取测试
$starttimer = microtime(true);
for($o = 0 ; $o < $times; $o++){
$kv->get('test'.$o);
}
$stoptimer = microtime(true);

$timer = $stoptimer-$starttimer;
echo "Data Read $times times by KVDB in $timer seconds.<br />";
unset($kv);

//Memcache写入测试
$mmc = memcache_init();
$starttimer = microtime(true);
for($o = 0 ; $o < $times; $o++){
memcache_set($mmc, 'test'.$o, $content);
}
$stoptimer = microtime(true);

$timer = $stoptimer-$starttimer;
echo "Data Write $times times by Memcache in $timer seconds.<br />";

//Memcache读取测试
$starttimer = microtime(true);
for($o = 0 ; $o < $times; $o++){
memcache_get($mmc, 'test'.$o);
}
$stoptimer = microtime(true);

$timer = $stoptimer-$starttimer;
echo "Data Read $times times by Memcache in $timer seconds.<br />";
unset($mmc);
?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  sae
相关文章推荐