Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Uuids和Redis_Ruby On Rails_Performance_Redis_Uuid - Fatal编程技术网

Ruby on rails Uuids和Redis

Ruby on rails Uuids和Redis,ruby-on-rails,performance,redis,uuid,Ruby On Rails,Performance,Redis,Uuid,安特里兹在这篇文章中详细介绍了使用哈希优化内存的方法- 我有一个正在生产的应用程序,它有大约50个实体(表)和几百万个UUID,这些实体组合在一起。我希望充分利用Redis的排序集、列表和散列 从内存和性能的角度来看,将uuid/guid作为redis键(以及集合和列表的成员,如果有的话)意味着什么 我使用postgre作为另一个数据存储,rails 3.2.9和ruby 1.9.3。如果使用排序集、列表和哈希,则没有具体含义 您可以将UUID存储为字符串,例如: 110E8400-E29B-

安特里兹在这篇文章中详细介绍了使用哈希优化内存的方法-

我有一个正在生产的应用程序,它有大约50个实体(表)和几百万个UUID,这些实体组合在一起。我希望充分利用Redis的排序集、列表和散列

从内存和性能的角度来看,将uuid/guid作为redis键(以及集合和列表的成员,如果有的话)意味着什么


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

如果使用排序集、列表和哈希,则没有具体含义

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

 110E8400-E29B-11D4-A716-446655440000
在这种情况下,每个值需要38字节。如果您不关心存储人类可读的值,那么您可能更愿意利用Redis存储二进制数据(对于键和值),并将UUID仅存储为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

现在,如果您计划使用集合(简单集合,而不是排序集合),那么有一个名为intset的特定优化,如果您使用uuid作为键,您将不会从中受益。intset只能用于编码64位数字,因此16字节UUID将不适合。如果您计划存储很多集合,那么添加一个间接寻址并使用整数作为主键而不是UUID可能会有好处。否则就没有意义了。

谢谢迪迪埃。从redis docs()-“集合可以编码为intset或hashtable。intset是一种特殊编码,用于仅由整数组成的小集合”-您知道“small”大致意味着什么吗?“small”由set max intset entries参数定义。在默认配置下,少于512项的集合被视为小集合,因此将存储为整数集。需要注意的是,只有集合中的元素需要是64位整数才能装入紧凑集合。集合本身的主键可以是任何东西,包括UUID的字节或字符串表示。