Node 版本:v7.4.0
node-redis 版本:v.2.6.2
redis_version:2.8.4
ubuntu 14.04 2GB 内存 VPS 实例
我收到的迹象表明 node_redis hgetall 的性能不尽如人意,但可能是我做错了什么。我有一个包含 31669 个元素的排序集。元素是散列键,每个散列有 14 个字段,大约 256 字节。检索哈希需要大约 64 秒,这似乎太慢了。 该函数如下所示:
function getAllAnnotations()
{
var currentSeconds = Math.floor((new Date()).getTime() / 1000);
console.log('currentSeconds before zrange: ' + currentSeconds);
client.zrangebyscore("geoHashSortedSet", "-inf", "+inf", function(err, reply) {
multi = client.multi();
for (var uuid in reply) {
multi.hgetall(reply[uuid]);
}
multi.exec(function(err, replies) {
var currentSeconds = Math.floor((new Date()).getTime() / 1000);
console.log('currentSeconds after multi returns: ' + currentSeconds);
allAnnotations = replies;
});
});
}
这里的其他人是否同意这是糟糕的表现,我在上面的代码中所做的任何事情是否属于问题的一部分?
最佳答案
您也在为 zrangebyscore
计时,并且您正在使用 -inf
到 +inf
,这意味着整个元素。为什么要注意使用 zrange
而不是 0
和 -1
。那可能会更快。
试试这个
function getAllAnnotations()
{
var start = Date.now();
client.zrange("geoHashSortedSet", 0, -1, function(err, reply) {
console.log('zrange took ', Date.now() - start);
start = Date.now();
multi = client.multi();
reply.forEach(function(id) {
multi.hgetall(id);
});
multi.exec(function(err, replies) {
console.log('multi took', Date.now() - start);
allAnnotations = replies;
});
});
}
关于node.js - NodeRedis client.multi() hgetall 性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43409490/