Redis数据结构空间要求 [英] Redis Data Structure Space Requirements

查看:125
本文介绍了Redis数据结构空间要求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

redis中排序后的集合和列表之间的空间差异是什么?我的猜测是排序集是某种平衡的二叉树,而列表是链接列表.这意味着,在我为它们分别编码的三个值(键,分数,值)之上,尽管我将为链表的分数和值一起拼凑,但开销是链表需要跟踪一个其他节点,而二叉树需要跟踪两个,因此使用排序集的空间开销为O(N).

What is the difference in space between sorted sets and lists in redis? My guess is that sorted sets are some kind of balanced binary tree, and lists are a linked list. This means that on top of the three values that I'm encoding for each of them, key, score, value, although I'll munge together score and value for the linkedlist, the overhead is that the linkedlist needs to keep track of one other node, and the binary tree needs to keep track of two, so that the space overhead to using a sorted set is O(N).

如果我的值和得分都为long,而指向其他节点的指针也为long,则看起来在64位计算机上,单个节点的空间开销从3个long变为4个long.空间增加了33%.

If my value, and score are both longs, and the pointers to the other nodes are also longs, it seems like the space overhead of a single node goes from 3 longs to 4 longs on a 64-bit computer, which is a 33% increase in space.

这是真的吗?

推荐答案

远远超出您的估计.假设未使用ziplist(即您有很多商品).

It is much more than your estimation. Let's suppose ziplists are not used (i.e. you have a significant number of items).

Redis列表是经典的双向链接列表:每个项目3个指针(上一个,下一个,值).

A Redis list is a classical double-linked list: 3 pointers (prev,next,value) per item.

排序后的集合是字典和跳过列表.在字典中,项目也将与3个指针(键,值,下一个)一起存储.跳过列表的内存占用空间评估起来更为复杂:每个节点占用1个双精度值(分数),2个指针(obj,向后),n个对(指针,跨度值),n在1到32之间.大多数项仅占用1个或2对夫妇.

A sorted set is a dictionary plus a skip list. In the dictionary, items will be stored with 3 pointers as well (key,value,next). The skip list memory footprint is more complex to evaluate: each node takes 1 double (score), 2 pointers (obj,backward), plus n couples (pointer,span value) with n between 1 and 32. Most items will take only 1 or 2 couples.

换句话说,当排序列表不以ziplist表示时,它是迄今为止开销最大的Redis数据结构.与列表相比,内存开销超过200%(即3倍).

In other words, when it is not represented as a ziplist, a sorted set is by far the Redis data structure with the most overhead. Compared to a list, the memory overhead is more than 200% (i.e. 3 times).

注意:使用Redis评估内存消耗的最佳方法是尝试使用伪数据构建一个大列表或排序集,并使用INFO获取内存占用量.

Note: the best way to evaluate memory consumption with Redis is to try to build a big list or sorted set with pseudo-data and use INFO to get the memory footprint.

这篇关于Redis数据结构空间要求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆