gpt4 book ai didi

caching - 用于 hget 和 hset 命令的 Redis 基准测试

转载 作者:IT王子 更新时间:2023-10-29 06:09:11 24 4
gpt4 key购买 nike

我找不到使用 Redis 对 HGET 和 HSET(哈希表命令)进行基准测试的示例。任何示例或资源都会对此有所帮助。

最佳答案

我刚刚意识到 redis-benchmark 命令不会对 hSethGet 命令进行基准测试。 (我使用的是 v2.8.5)

你可以做的是编写一个小程序来对性能进行基准测试:

<?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";

在我的测试服务器上,结果如下:

$ php redis/benchmark_redis.php
hSet 花费的时间 = 557 毫秒(对于 10,000 个键)
hSet(批量)花费的时间 = 51 毫秒(对于 10,000 个键)
hGet 花费的时间 = 483 毫秒(对于 10,000 个键)
hGet(批量)花费的时间 = 43ms(10,000 个键)
hDel(批量)花费的时间 = 49 毫秒(10,000 个键)

关于caching - 用于 hget 和 hset 命令的 Redis 基准测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22822543/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com