Redis memory-related configuration conf

Source: Internet
Author: User
Tags compact redis

Redis installed in/usr/local/redis

Run: Cd/usr/local/redis->./redis-server &

Test: [Root@chbjt redis]#./redis-cli
127.0.0.1:6379> set Foo Bar
Ok
127.0.0.1:6379> get foo
"Bar"


# Requirepass foobared To remove the annotation, foobared changed to its own password, I changed it here to 888888

Requirepass 888888


Redis memory-related configuration conf (excerpt from: http://tech.it168.com/a2011/0818/1234/000001234478_all.shtml)

Using the Redis five data types, you can see that Redis actually has a very high cost of memory management, which consumes too much memory, and provides a range of parameters and tools to control and conserve memory.

The first and most important point is not to turn on the redis VM option, the virtual Memory feature, which was originally used as a redis for storing data beyond physical memory as a persistent strategy for swapping memory and disk.

But the cost of memory management is also very high, and this persistence strategy is not mature, so to turn off VM functionality, please check your redis.conf file vm-enabled as No.

Next, it is best to set the MaxMemory option in the lower redis.conf, which tells Redis to start rejecting subsequent write requests when the amount of physical memory is used, 1024*1024=1048576 bytes=1m

This parameter is good at protecting your redis from using too much physical memory to cause swap, which can eventually severely affect performance or even crash.

In addition, Redis provides a set of parameters for different data types to control memory usage.

Redis Hash is a hashmap within value, and if the map has fewer members, the map is stored in a compact format similar to one-dimensional linear, which eliminates the memory overhead of a large number of pointers, which control the following 2 items in the redis.conf configuration file:

Hash-max-zipmap-entries 64

Hash-max-zipmap-value 512

Hash-max-zipmap-entries meaning is that when the value of this map does not exceed the number of members will be used in a linear compact format storage, the default is 64, that is, value within 64 of the following members is the use of linear compact storage, This value is automatically turned into a real hashmap.

The hash-max-zipmap-value implication is that when value is within the map, the length of each member value is no more than the number of bytes, the linear compact storage is used to save space.

The above 2 conditions any one condition exceeds the setting value will convert to the real hashmap, also will no longer save memory, then this value is not set the bigger the better, the answer is certainly negative, hashmap advantage is to find and operate the time complexity is O (1), And to discard the hash using one-dimensional storage is the time complexity of O (n), if

A small number of members, the impact is not significant, otherwise it will seriously affect performance, so to weigh the setting of this value, the overall or the most fundamental time cost and space costs on the balance.

Similarly, the same parameters are:

List-max-ziplist-entries 512

Description: The number of nodes in the list data type follows the compact storage format of the pointer.

List-max-ziplist-value 64

Description: The list data type node value size less than how many bytes will be in a compact storage format.

Set-max-intset-entries 512

Note: Set data type internal data if all are numeric, and how many nodes are included, the following will be stored in compact format.

Redis internal implementations do not optimize memory allocations to some extent, but in most cases this will not be a performance bottleneck for Redis.

If most of the data stored inside the Redis is numeric, a shared integer is used internally redis to omit the overhead of allocating memory, that is, when the system starts, it allocates a number of numeric objects from 1~n to a pool. The data stored is exactly the data in the range of this value, the object is taken directly from the pool and shared by reference counting, so that when the system stores a large number of values, it can also save some memory and improve performance, the setting of this parameter value n needs to modify a line of macro definitions in the source code Redis_ Shared_integers, the default is 10000, you can make changes according to their needs, and then recompile after the revision can be.

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.