redisメモリの最適化--多くのドメインhash保存オブジェクトがあり、多くのキー値を確立するよりもメモリを節約できます.
1418 ワード
redisドキュメントでは、複数のドメインhash保存オブジェクトを使用すると、複数のキー値ペアを確立するよりもメモリを節約できますが、keyのみが生存期間を有し、hashがドメインに生存期間を設定できないという欠点があります.
具体的な原理は、redisがhashの項目数が一定数より少ない場合(この数はユーザが自分でフィールドを以下に設定できる)には、メモリをより節約するデータ構造を採用するが、このデータ構造はhashtableのO(1)定数時間複雑度ではなく、O(N)の時間複雑度をもたらすが、Nが小さいため、均等償却時間で定数時間と見なすことができ、zipmapはより良い局所性を有し、cacheのヒット率を向上させ、メモリアクセス速度を向上させ、時間的なコストを相殺することができます.
具体的なやり方は以下の通りです.
Now let's assume the objects we want to cache are numbered, like: object:102393 object:1234 object:5
This is what we can do. Every time there is to perform a SET operation to set a new value, we actually split the key into two parts, one used as a key, and used as field name for the hash. For instance the object named "object:1234"is actually split into: a Key named object:12 a Field named 34
So we use all the characters but the latest two for the key, and the final two characters for the hash field name. To set our key we use the following command:
As you can see every hash will end containing 100 fields, that is an optimal compromise between CPU and memory saved.
上の言叶は工事の経験かもしれませんが、覚えておけばいいのにふん!
その後zipmapがどのようなデータ構造なのか、こんなに高いメモリ効率があるのか、英語のドキュメントではメモリ効率が10倍(メモリ効率を評価するのは5倍)で、記録とストレージの違いは何なのか知りたいです.次のブログを見て
具体的な原理は、redisがhashの項目数が一定数より少ない場合(この数はユーザが自分でフィールドを以下に設定できる)には、メモリをより節約するデータ構造を採用するが、このデータ構造はhashtableのO(1)定数時間複雑度ではなく、O(N)の時間複雑度をもたらすが、Nが小さいため、均等償却時間で定数時間と見なすことができ、zipmapはより良い局所性を有し、cacheのヒット率を向上させ、メモリアクセス速度を向上させ、時間的なコストを相殺することができます.
hash-max-zipmap-entries 256( 256 zipmap )
具体的なやり方は以下の通りです.
Now let's assume the objects we want to cache are numbered, like:
This is what we can do. Every time there is to perform a SET operation to set a new value, we actually split the key into two parts, one used as a key, and used as field name for the hash. For instance the object named "object:1234"is actually split into:
So we use all the characters but the latest two for the key, and the final two characters for the hash field name. To set our key we use the following command:
HSET object:12 34 somevalue
As you can see every hash will end containing 100 fields, that is an optimal compromise between CPU and memory saved.
上の言叶は工事の経験かもしれませんが、覚えておけばいいのにふん!
その後zipmapがどのようなデータ構造なのか、こんなに高いメモリ効率があるのか、英語のドキュメントではメモリ効率が10倍(メモリ効率を評価するのは5倍)で、記録とストレージの違いは何なのか知りたいです.次のブログを見て