- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我做了一些实验,似乎 Redis 哈希几乎总是比字符串更节省空间,即使哈希包含单个字段也是如此!
import redis
rc = redis.Redis(host='127.0.0.1',port=1234)
rc.flushdb()
pipe = rc.pipeline()
for i in range(1000000):
pipe.set('stream:'+str(i)+':target',True)
f = pipe.execute()
# uses 236 MB
rc.flushdb()
pipe = rc.pipeline()
for i in range(1000000):
pipe.hset('stream:'+str(i),'target',True)
f = pipe.execute()
# uses 170 MB
rc.flushdb()
pipe = rc.pipeline()
for i in range(500000):
pipe.set('stream:'+str(i)+':target',True)
pipe.set('stream:'+str(i)+':ws',True)
f = pipe.execute()
# uses 238 MB
rc.flushdb()
pipe = rc.pipeline()
for i in range(500000):
pipe.hset('stream:'+str(i),':target',True)
pipe.hset('stream:'+str(i),':ws',True)
f = pipe.execute()
# uses 113 MB
哈希和字符串都具有 O(1) 的平摊写入/读取成本。如果我不需要使用最花哨的操作,如 APPEND、GETBIT、SETBIT、RANGE 等,而只使用纯粹的 SET/GET 语义,那么散列不是总是更可取吗?我想念什么疯狂的东西吗?另外,我很想知道为什么哈希的空间效率要高得多。
最佳答案
这Memory Optimization文章讨论了您提出的一些问题。
如果您可以这样表示数据,redis 的建议是使用哈希。 “小散列被编码在一个非常小的空间中,所以你应该尽可能地尝试使用散列来表示你的数据”。
如果 Redis 可以将散列打包到一个数组中,并且仍然以 O(1) 的速度进行查询,那么 Redis 认为散列很小。将数据放在连续的内存区域中也有助于提高性能,特别是如果数组的相邻元素是在您的盒子上的缓存行的框架内读取的。
在redis config中你可以找到以下设置,
# Hashes are encoded using a memory efficient data structure when they have a
# small number of entries, and the biggest entry does not exceed a given
# threshold. These thresholds can be configured using the following directives.
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
您需要在上述阈值的两侧重复测试。总的来说,最好让您的测试尽可能地模仿您的真实数据和访问模式。您的问题的前提是应始终使用哈希,但请记住,您指望优化启发式算法对您作为用户而言并不完全透明。
关于Redis 哈希与字符串内存成本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20811335/
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 4 年前。 Improve this ques
声明引用会导致运行时成本吗? Typename a; auto& b=a; func(b); 在循环内声明引用会导致多倍的运行时成本吗? Typename a=Typename();//defa
给定一组代表(成本, yield )的样本数据 items = [ (1000, 300), (500, 150), (400, 120), (300, 100), (200, 50), (55, 2
我从 link 得到这个其中谈到了外部归并排序。 来自幻灯片 6 示例:使用 5 个缓冲页,对 108 页文件进行排序 第 0 次:[108/5] = 22 次排序运行,每次运行 5 页(最后一次运行
使用 Javascript 在 localStorage 中查找值的速度有多快? 有没有人有指向任何性能测试的链接,这些测试表明是否值得在 JavaScript 对象中缓存数据?或者浏览器是否已经缓存
我正在尝试创建一个电子表格,以跟踪具有已知保质期的元素的当前和 future 成本。这包括产品是什么、产品成本、产品生命周期(以月为单位)和最后购买日期。 我已经尝试了几种方法来摆弄 Excel 公式
我正在使用最佳匹配算法在 TraMineR 中进行序列分析。不幸的是,我的 由于右删失数据,序列长度不等 .我的序列的最小长度是 5,最大长度是 11。长度的变化对于我感兴趣的序列之间的差异没有意义。
我读过一些文章说你应该将成本设置为至少 16 (216),但其他人说 8 左右就可以了。 是否有任何官方标准应该将成本设置为多高? 最佳答案 您应该使用的成本取决于您的硬件(和实现)的速度。 一般来说
我记得在我的架构类中假设L1缓存命中为1个周期(即与寄存器访问时间相同),但是在现代x86处理器上实际上是真的吗? L1缓存命中需要几个周期?与注册访问权限相比如何? 最佳答案 这是一篇很棒的文章:
我正在尝试确定来自托管我的 azure 函数的 azure 存储帐户的成本。我主要在本地进行开发,并使用 azure 存储模拟器并运行 func start cmd。我的问题是,此设置是否仍然会增加我
我有一个为工作编写的大型复杂 VBA 脚本。我正在清理它,并注意到我可以用比我所做的更动态的方式定义我的数组。 最初我将数组定义为字符串,如下所示: Dim header_arr(6) As Stri
任何人都可以为我指定以下情况下的费用: 当使用快照监听器的查询监听集合并且集合中的一个文档将被添加或更新时,我是否需要为已更新的文档或查询中的所有文档付费? 示例:我在用户集合上有一个快照监听器,其中
摘要 我正在使用 Octave 和 Ling-Spam 语料库构建垃圾邮件与普通邮件的分类器;我的分类方法是逻辑回归。 较高的学习率会导致计算成本为 NaN 值,但它不会破坏/降低分类器本身的性能。
我正在从事一个项目,其中我的代码的吞吐量非常重要,经过一番考虑后我选择让我的程序线程化。 主线程和子线程都在两个共享字典中添加和删除。考虑到在 python 中锁定的性能,我一直在通过互联网查看一些输
所以我在 TCP 套接字上发送数据,以数据大小为前缀,如下所示: write(socket, &length, sizeof(length)); write(socket, data, length)
我正在评估 Azure 媒体服务作为我们正在构建的解决方案的托管平台。我已成功使用 DRM 设置动态加密并使用 Azure AD 设置内容保护。我还检查了定价,我知道您必须为编码作业(一次性)、流媒体
AWS S3 Java SDK 提供了一种方法 doesObjectExist()检查 S3 中是否存在对象。它内部使用什么操作?是吗GET , LIST , 或 HEAD ? 我的担忧主要与它的成本
我一直在使用 three.js 来试验和学习 GLSL 和 WebGL。我来自 3d 艺术世界,所以我了解网格、3d 数学、照明等的概念。虽然我确实查阅了 OpenGL 和 WebGL 文献(以及 g
我正在 Azure 中设计一个 Web 服务。是否可以计量每个最终用户的实际 Azure 平台使用成本? Azure 是否向最终用户提供计费服务? 最佳答案 如今的 Windows Azure 计费模
我目前在 MySql 中有一个表,如果我运行此查询,则有 730 万行,大小为 1.5GB: How to get the sizes of the tables of a mysql databas
我是一名优秀的程序员,十分优秀!