Redis note Eight memory settings and optimization _redis

Source: Internet
Author: User
Tags allkeys memory usage redis volatile

Theoretically, Redis can store 2 of the 32-time key, each instance at least 250 million keys, but because the Redis is a memory based database so it means that it is not possible to store a lot of data, it should be said that Redis storage limit is the system's available memory.

I generated 1 million keys on my computer through Jedis to actually occupy memory 108M

# Memory

used_memory:104730792

used_memory_human:99.88m

used_memory_rss:123080704

used_memory_peak:113668232

used_memory_peak_human:108.40m

used_memory_lua:35840

mem_fragmentation_ratio:1.18

mem_allocator:jemalloc-3.6.0

# Keyspace

Db0:keys=1000000,expires=0,avg_ttl=0


Memory settings

MaxMemory and Maxmemory_policy parameters

Use these two parameters to configure Redis memory usage in redis.conf. Redis's available memory is related to the system's memory, and generally we need to set its maximum available memory, unless you are certain that the Redis memory in your business is not very large and has sufficient system memory.

MaxMemory parameters

Not set

1: Not set or 0, 64-bit system is not limited to use, 32 bits up to 3G

2: If you do not set the maximum memory system how much memory Redis will be used as soon as you start writing to swap virtual memory, the later query speed will slow.

Set up

If the RDB persistence mode is turned on, because the child process will increase memory usage by one time while copying all the data, the maximum is set to 45% of the system memory. If you do not open the maximum setting of 95% of the system memory.

Maxmemory_policy parameters

1: Set the maximum memory after the need to set the deletion policy or when the memory is not enough to add data will be an error.

2: There are six kinds of deletion strategies.

VOLATILE-LRU: Uses the LRU algorithm to retire data from a set of data that has expired time.

Volatile-ttl: Select obsolete data from the set of data sets that expire.

Volatile-random: Randomly select data obsolescence from a set of data sets that have expired time.

ALLKEYS-LRU: Use the LRU algorithm to eliminate data from all data sets, eliminating the key that uses the least frequency.

Allkeys-random: Arbitrary selection of data elimination from the data set

No-enviction: Prohibit the elimination of data.


Optimization principle:

1:key name as much as possible use simple and clear keywords, such as Stu on behalf of students not too long.

2: Turn off persistence if you just use Redis to act as a cache.

3:redis provides two internal encodings for each data type, and Redis automatically adjusts the encoding using the data type at the time of generation.

4:slowlog Slow Log Query

These commands can be found by Slowlog when we find that the Redis command is slow to execute. In redis.conf, there are two parameters slowlog-log-slower-than10000 and Slowlog-max-len 128.

slowlog-log-slower-than10000 indicates that the command will be saved when the command executes longer than 10000

slowlog-max-len128 says Redis will save up to 128 commands.

Slowlog get can view all currently executing slow commands

Slowlog Len can see how many commands are currently logged.

Slowlog Reset can perform a reset

We can modify these two parameters in redis.conf according to the actual situation of the project


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.