问题描述
我找不到带redis的HGET,HSET(哈希表命令)基准测试的示例.关于此的任何示例或资源都将是有用的.
I could not find an example for bench marking of HGET , HSET (hash table commands) with redis. Any example or resource will be useful regarding this.
推荐答案
我刚刚意识到 redis-benchmark
命令没有对 hSet
和 hGet
命令.(我正在使用v2.8.5)
I just realized redis-benchmark
command does not benchmark hSet
and hGet
commands. (I'm using v2.8.5)
您可以做的是编写一个小程序来对性能进行基准测试:
What you could do is write a small program to benchmark the performance:
<?php
$redis = new Redis();
$redis->pconnect("127.0.0.1");
$count = 10000;
$start_t = microtime(true);
for ($i = 1; $i < $count; $i++) {
$redis->hSet("h{$i}", 'f', $i);
}
$end_t = microtime(true);
echo "Time taken for hSet = " . round(1000 * ($end_t - $start_t)) . "ms (for " . number_format($count) . " keys)\n";
$start_t = microtime(true);
$pipeline1 = $redis->pipeline();
for ($i = 1; $i < $count; $i++) {
$pipeline1->hSet("h{$i}", 'f', $i);
}
$result2 = $pipeline1->exec();
$end_t = microtime(true);
echo "Time taken for hSet (bulk) = " . round(1000 * ($end_t - $start_t)) . "ms (for " . number_format($count) . " keys)\n";
$start_t = microtime(true);
for ($i = 1; $i < $count; $i++) {
$redis->hGet("h{$i}", 'f');
}
$end_t = microtime(true);
echo "Time taken for hGet = " . round(1000 * ($end_t - $start_t)) . "ms (for " . number_format($count) . " keys)\n";
$start_t = microtime(true);
$pipeline2 = $redis->pipeline();
for ($i = 1; $i < $count; $i++) {
$pipeline2->hGet("h{$i}", 'f');
}
$result2 = $pipeline2->exec();
$end_t = microtime(true);
echo "Time taken for hGet (bulk) = " . round(1000 * ($end_t - $start_t)) . "ms (for " . number_format($count) . " keys)\n";
$start_t = microtime(true);
$pipeline3 = $redis->pipeline();
for ($i = 1; $i < $count; $i++) {
$pipeline3->hDel("h{$i}", 'f');
}
$result3 = $pipeline3->exec();
$end_t = microtime(true);
echo "Time taken for hDel (bulk) = " . round(1000 * ($end_t - $start_t)) . "ms (for " . number_format($count) . " keys)\n";
在我的测试服务器上,结果如下:
On my test server, results are as follows:
$ php redis/benchmark_redis.phphSet花费的时间= 557ms(用于10,000个键)hSet(批量)= 51ms(用于10,000个键)所花费的时间hGet花费的时间= 483ms(用于10,000个密钥)hGet(批量)花费的时间= 43ms(用于10,000个密钥)hDel(批量)花费的时间= 49ms(用于10,000个键)
这篇关于Redis对Hget和HSet命令的基准测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!