3

Antirez は、この記事でハッシュを使用したメモリの最適化について詳しく説明しています - http://redis.io/topics/memory-optimization

私は、約 50 のエンティティ (テーブル) と数百万の UUID をさまざまなエンティティにまたがって組み合わせた実稼働中のアプリを持っています。Redis の Sorted Set、List、Hash を大いに活用したいと考えています。

メモリとパフォーマンスの観点から、uuid/guid を redis キー (およびセットとリストのメンバー) として持つことの意味は何ですか?

別のデータストアとして postgre を使用し、rails 3.2.9 と ruby​​ 1.9.3 を使用しています。

4

1 に答える 1

6

ソートされたセット、リスト、およびハッシュを使用する場合、特定の意味はありません。

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の代わりに整数を主キーとして使用すると便利な場合があります。そうでなければそれは無意味です。

于 2012-12-27T16:36:21.330 に答える