Redis translation memory optimization and redis Translation Memory Optimization

Source: Internet
Author: User

Redis translation memory optimization and redis Translation Memory Optimization
Special encoding of small aggregate data types Special encoding small set data type Since Redis 2.2 bytes 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 ).
From redis2.2, some data types can specify a certain size to use smaller memory. Hashes, List, and Sets only need one configuration number, and Sorted sets. When the maximum size of the given element and element is smaller than the configured number, logs are recorded using less than 10 times of memory (less than 5 times of memory ). 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.
From the user's perspective and API, this is completely transparent. The following configuration command is used to configure the number of these data types:

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.
If the value of this special encoding is greater than the configured value, Redis will automatically convert it to a normal encoding. If you want to increase the configuration, you 'd better test it over and over again.

Using 32 bit instances use 32 for 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.
Because the pointer in the 32-bit operating system is small, every key in the Redis instance using 32 occupies a small memory, but the maximum memory used by the 32-bit redis instance is 4 GB. You can compile redis into 32 bits. RDB and AOF files can be used in both 32-bit and 64-bit formats. Therefore, you can enable Redis to convert each other in 32-bit and 64-bit formats. bit and byte level operations (bit and byte operations) 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 newly introduced bit and byte-level operations: GETRANGE, SETRNGE, GETBIT and SETBIT. Using these commands, You can regard the String type of redis as a random access array. For example, if you have an app and all users in the app have a unique number (such as id), you can use a bitmap to save the Gender Information of the user and set the bit to male, or vice versa. In this way, only 12 Mb is required for the 1 million user to save the information. You can also use GETRANGE and SETRANGE to save user information in the same way. This is just an example, but in fact it shows the small space storage standard.
Use hashes when possible Use 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.

Small hash encoding consumes a small amount of space, so you should try it if possible. For example, in a web application, users use different keys to represent name, seruname, email, and password, which can be replaced by fields in hash.

If you want to know more about this, read the next section.

If you want to know

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.