- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我正在尝试用 Ruby 优化我的 Redis 代码中的 ZRANGEBYSCORE。
具体来说,Redis 网站 ( http://redis.io/commands/zrangebyscore ) 声明:
Time complexity: O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements being returned. If M is constant (e.g. always asking for the first 10 elements with LIMIT), you can consider it O(log(N)).
因此,正如我所读,只要我使用限制,无论限制设置为 48 还是 6,big(O) 都应该恒定为 O(log(N)。但是,我的基准测试似乎另有所指。
require 'redis'
def bench(descr)
start = Time.now
yield
puts "#{descr} #{Time.now-start} seconds"
end
def with_pipelining_48
id = 26053643
@@redis.pipelined {
1000.times {
@@redis.zrevrangebyscore("key:#{id}", "+inf", "-inf", :limit => [0, 48],:with_scores => true)
}
}
end
def with_pipelining_24
id = 26053643
@@redis.pipelined {
1000.times {
@@redis.zrevrangebyscore("key:#{id}", "+inf", "-inf", :limit => [0, 24],:with_scores => true)
}
}
end
def with_pipelining_12
id = 26053643
@@redis.pipelined {
1000.times {
@@redis.zrevrangebyscore("key:#{id}", "+inf", "-inf", :limit => [0, 12],:with_scores => true)
}
}
end
def with_pipelining_6
id = 26053643
@@redis.pipelined {
1000.times {
@@redis.zrevrangebyscore("key:#{id}", "+inf", "-inf", :limit => [0, 6],:with_scores => true)
}
}
end
bench("with pipelining_48") {
with_pipelining_48
}
bench("with pipelining_24") {
with_pipelining_24
}
bench("with pipelining_12") {
with_pipelining_12
}
bench("with pipelining_6") {
with_pipelining_6
}
返回以下结果:
with pipelining_48 1.709097 seconds
with pipelining_24 0.930054 seconds
with pipelining_12 0.801045 seconds
with pipelining_6 0.633037 seconds
我的结果似乎与 Redis 文档不一致。有人可以阐明可能导致差异的原因吗?
最佳答案
因此,首先,对于真正的基准测试,您应该在剔除异常值后取平均值。所有这些操作之间的差异都以毫秒为单位,因此,如果您只是遇到一个微小的网络问题,或者您的盒子上发生了一些奇怪的事情,它就会把数字丢掉。如果这样做,您的数字可能看起来会有所不同。
其次,当您对 Redis 运行操作时,发生的不仅仅是操作成本。与 Redis 的连接需要连同其他相关的启动成本。数据也需要传输,而且会有网络来回。您所安排的时间不仅仅是运营成本,还有所有这些辅助成本。这些也将是非线性的,因为可以根据数据大小使用不同的格式来保存数据。总而言之,主要的一点是zrevrangebyscore
是O(log(n)+m),但是操作中也有辅助成本,并且操作成本低(几乎总是Redis 的情况),这些成本使操作的实际成本相形见绌。这是好事。
关于ruby - Redis 和 Ruby 中的 ZRANGEBYSCORE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24397746/
这可能是愚蠢的事情.. 在 Redis 控制台中执行此操作 zincrby model 1 20140101 zincrby model 1 20141010 zincrby model 1 2014
我使用的是 Redis 2.6。我遇到过 ZRANGEBYSCORE 函数的奇怪行为。我有一个长度约为几百万个元素的排序集。像这样: 10 marry 15 john 25 bob ... 所以比较查
我总是收到这个错误 asp.net核心2.0 StackExchange.Redis.StrongName 1.2.6 3 redis server 1 master 2 replica 仅从副本读取
我正在使用Java中的排序集,并且我希望将分数在最小/最大之间的所有元素作为从最小分数到最大分数的有序列表来获取。然而,Jedis 实现返回一个 Set,并且我在文档中没有看到任何保证它被排序的地方j
现在我正在尝试类似以下命令的操作。 ZRANGEBYSCORE myzset myvalue inf 它为我提供了所有大于 myvalue 的结果。但是,我只想获得第一个结果。我该怎么做? 最佳答案
ZRANGEBYSCORE key min max [WITHSCORES] [LIMIT offset count] 什么是偏移和计数?如果我只想要得分最高的成员,我该如何使用它们? 最佳答案 写在
除了第二个具有可选的 LIMIT 参数外,这两个 Redis 命令是否不同? http://redis.io/commands/zrange http://redis.io/commands/zran
我想弄清楚如何在排序集上获取 ZRANGEBYSCORE 命令的结果并将结果作为新集保存在 Redis 中,我不希望数据返回给客户端。我知道可以在客户端读取结果,然后将结果作为一个新集合推送,但我不希
问题是关于这些 Redis 命令以及如何在单个调用中使用 3° 和 4°。 1) HMSET key field value [field value ...] 2) ZADD key [NX|XX]
我在 perl 脚本中使用 Redis.pm 并尝试执行下一个命令: zrevrangebyscore 0 WITHSCORES LIMIT 0 1 在我接下来编写的带有 redis 文档的设备中
我有一个使用 redis 排序集的队列系统。我的 lua 脚本看起来像: local moveElement = function(source, dest , score, destscore)
我正在尝试获取排序集中的最佳键的值。 这是我目前的查询: ZREVRANGEBYSCORE genre1 +inf -inf WITHSCORES LIMIT 0 1 这是我的集合中的一个添加示例:
在下一种情况下哪种方法更好: 我需要获取一些按分数排序的元素,我可以使用这两种方法: 1. zrange myZset 1 5 WITHSCORES 2. zrangebyscore myZset
我正在尝试用 Ruby 优化我的 Redis 代码中的 ZRANGEBYSCORE。 具体来说,Redis 网站 ( http://redis.io/commands/zrangebyscore )
zrangebyscore 的时间复杂度是 O(Log(N)) 如果我使用 min = -inf 运行 zrangebyscore 并限制为 1,它会不会低于 O(log(n))?或 O(1)? 最佳
我使用 ZADD 设置值并通过 ZRANGBYSCORE 获取值 redis 127.0.0.1:6379> ZADD mytest 1 "one" 2 "two" 3 "three" (intege
如何将 LIMIT 选项传递给 EVAL Redis 命令调用 ZRANGEBYSCORE命令? 对于像 SET 这样的简单命令,语法如下 eval "return redis.call('set',
我是一名优秀的程序员,十分优秀!