Uuids和Redis

pap*_*del 2 performance uuid ruby-on-rails redis

Antirez在本文中详细讨论了Hashes的内存优化问题 - http://redis.io/topics/memory-optimization

我有一个生产的应用程序,有大约50个实体(表)和几百万uuids,结合各种实体.我希望大量利用Redis的排序集,列表和哈希.

从记忆和性能的角度来看,将uuids/guids作为redis键(以及集合和列表的成员)(如果有的话)的含义是什么?

我使用postgre作为另一个数据存储区和rails 3.2.9和ruby 1.9.3.

Did*_*zia 5

如果使用有序集,列表和散列,则没有特定含义.

您可以将您的uuids存储为字符串,例如:

 110E8400-E29B-11D4-A716-446655440000
Run Code Online (Sandbox Code Playgroud)

在这种情况下,每个值需要38个字节.如果您不关心存储人类可读值,您可能更愿意利用Redis功能存储二进制数据(对于键和值),并将uuids仅存储为16个字节.

您的短列表,有序集和哈希将按照Redis文档中的说明进行序列化.您可能需要调整以下参数以调整Redis对工作负载的行为:

# 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

# Similarly to hashes, small lists are also encoded in a special way in order
# to save a lot of space. The special representation is only used when
# you are under the following limits:
list-max-ziplist-entries 512
list-max-ziplist-value 64

# Sets have a special encoding in just one case: when a set is composed
# of just strings that happens to be integers in radix 10 in the range
# of 64 bit signed integers.
# The following configuration setting sets the limit in the size of the
# set in order to use this special memory saving encoding.
set-max-intset-entries 512

# Similarly to hashes and lists, sorted sets are also specially encoded in
# order to save a lot of space. This encoding is only used when the length and
# elements of a sorted set are below the following limits:
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
Run Code Online (Sandbox Code Playgroud)

现在,如果您计划使用集合(简单集,而不是有序集),则会有一个名为intset的特定优化,如果您将UUID用作键,则不会从中受益.intset只能用于编码64位数字,因此16字节的UUID不适合.如果您计划存储大量集合,则添加间接可能有好处,并使用整数作为主键而不是UUID.否则它毫无意义.