redis翻譯_記憶體最佳化,redis翻譯記憶體最佳化
Special encoding of small aggregate data types特別編碼小集合的資料類型Since Redis 2.2 many data types are optimized to use less space up to a certain size. Hashes, Lists, Sets composed of just integers, and Sorted Sets, when smaller than a given number of elements, and up to a maximum element size, are encoded in a very memory efficient way that uses up to 10 times less memory (with 5 time less memory used being the average saving).
從redis2.2開始,一些資料類型可以指定一定的size使用更小的記憶體。Hashes,List,Sets僅僅需要一個配置數字,還有Sorted sets,當給定的元素和元素的最大size小於配置的數字,將使用小於10倍的記憶體做記錄(少於5倍的記憶體去儲存)。This is completely transparent from the point of view of the user and API. Since this is a CPU / memory trade off it is possible to tune the maximum number of elements and maximum element size for special encoded types using the following redis.conf directives.
從使用者的角度和API來看,這是完全透明的。下面的配置指令就是對這些資料類型這個數位配置:
hash-max-zipmap-entries 64 (hash-max-ziplist-entries for Redis >= 2.6)hash-max-zipmap-value 512 (hash-max-ziplist-value for Redis >= 2.6)list-max-ziplist-entries 512list-max-ziplist-value 64zset-max-ziplist-entries 128zset-max-ziplist-value 64set-max-intset-entries 512
If a specially encoded value will overflow the configured max size, Redis will automatically convert it into normal encoding. This operation is very fast for small values, but if you change the setting in order to use specially encoded values for much larger aggregate types the suggestion is to run some benchmark and test to check the conversion time.
如果這個特殊的編碼的值大於配置的值,Redis將自動轉換成普通的編碼。配置小值的情況下操作是非常快的,但是如果你想加大配置,你最好反覆測試。
Using 32 bit instances使用32為redis執行個體Redis compiled with 32 bit target uses a lot less memory per key, since pointers are small, but such an instance will be limited to 4 GB of maximum memory usage. To compile Redis as 32 bit binary use
make 32bit. RDB and AOF files are compatible between 32 bit and 64 bit instances (and between little and big endian of course) so you can switch from 32 to 64 bit, or the contrary, without problems.
因為在32位作業系統中指標比較小,所以使用32為的Redis每一個key占的記憶體都比較小,但是32為的redis執行個體只能使用的最大記憶體為4G。可以將redis編譯成32位。RDB和AOF檔案在32為和64位都可以使用,因此你可以使Redis在32和64位中相互轉換沒有任何問題.Bit and byte level operations(bit和byte層級的操作)Redis 2.2 introduced new bit and byte level operations: GETRANGE, SETRANGE, GETBIT and SETBIT. Using this commands you can treat the Redis string type as a random access array. For instance if you have an application where users are identified by an unique progressive integer number, you can use a bitmap in order to save information about sex of users, setting the bit for females and clearing it for males, or the other way around. With 100 millions of users this data will take just 12 megabyte of RAM in a Redis instance. You can do the same usingGETRANGE and SETRANGE in order to store one byte of information for user. This is just an example but it is actually possible to model a number of problems in very little space with this new primitives.
Redis2.2新引進bit和byte層級的操作:GETRANGE,SETRNGE,GETBIT和SETBIT。使用這些命令你可以將redis的String類型看成一個隨機訪問的數組。比如,你有一個app,app中所有的user都有一個唯一的數字(比如id),你可以使用一個位元影像儲存user的性別資訊,設定bit位成男,或者相反。這樣設定之後100 萬的user儲存這樣的資訊只需要12M。還可以以同樣的方式使用GETRANGE和SETRANGE儲存user的資訊。這僅僅是一個例子,但是從事實上說明小空間儲存標準。
Use hashes when possible在可能的時候使用hashSmall hashes are encoded in a very small space, so you should try representing your data using hashes every time it is possible. For instance if you have objects representing users in a web application, instead of using different keys for name, surname, email, password, use a single hash with all the required fields.
小hash編碼消耗的空間很小,因此如果可能的話應該嘗試使用它。比如,在web應用中user,使用不同的key表示name,seruname,email,password,這些可以使用hash中的fields代替。
If you want to know more about this, read the next section.
如果想知道