In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
All data in Redis is stored in memory, so the monitoring and management of memory is very important to redis. Let's talk about the memory of redis from three aspects: memory monitoring, management and optimization.
Memory monitoring
Redis provides us with the info memory command to view memory usage. This command shows a lot of data, so let's just look at some of the more important ones.
Used_memory:1146648 (amount of memory allocated by the redis allocator)
Used_memory_human:1.09M (presented in a readable manner)
Used_memory_rss:4358144 (total amount of memory consumed by redis)
Used_memory_rss_human:4.16M (shows the total amount of memory consumed by redis in a readable manner)
Used_memory_peak:1229448 (userd_memory_peak peak)
Used_memory_peak_human:1.17M
Used_memory_overhead:857036 (memory occupied by buffer, backlog, etc.)
Used_memory_startup:791384 (memory consumed by starting redis)
Used_memory_dataset:289612 (memory occupied by redis data)
Used_memory_lua:37888 (memory consumed by lua scripts)
Used_memory_lua_human:37.00K (readable presentation)
Mem_fragmentation_ratio:4.02 (memory fragmentation rate, used_memory_rss / used_memory)
A mem_fragmentation_ratio greater than 1 indicates memory fragmentation, and a lower value indicates a more serious fragmentation rate. If the application allows, you can restart redis to reduce the fragmentation rate. When it is less than 0, you should be very careful, indicating that there is not enough memory and some swap is used.
Memory management
It is generally recommended to set the memory limit for redis, maxmory.
There are two ways to modify it.
Modify the configuration file
Dynamic setting
The dynamic settings are shown below
127.0.0.1 6379 > config set maxmemory 1GOK127.0.0.1:6379 > config rewriteOK
Setting the maximum memory has two effects. First, you can limit the amount of memory consumed by redis to prevent it from exceeding the physical memory size. In addition, when the maximum memory is set and the redis exceeds the maximum memory, the memory recovery policy can be triggered (usually applied to cache scenarios)
Redis can dynamically adjust the maximum memory is very easy to use, when the server memory is not enough, need to increase memory, when the server memory increases, and then dynamically adjust the mammemory of redis.
In addition, there are several maxmemory-policy configurations for redis's memory recovery policy, of which two words often appear, LRU and LFU, with the following meanings:
Least recently used (Least Recently Used)
The least commonly used recently (Least Frequently Used)
Let's take a look at all the recycling strategies and their implications:
Noeviction: the default policy, which does not delete any keys, rejects any write commands when the maximum memory is exceeded, and only responds to read commands
Volatile-lru: delete expired keys according to the lru algorithm. If there are no keys to delete, fall back to the noeviction policy.
Allkeys-lru: delete the key according to the lru algorithm, regardless of whether the key expires or not, until the memory consumption is less than maxmeory.
Allkeys-lfu: same meaning as above, except that the lfu algorithm is used to delete it.
Allkeys-random: when the maximum memory is reached, delete the key randomly.
Volatile-ttl: delete keys that are about to expire. If not, fall back to noeviction.
Memory optimization
The above mentioned redis recycling policy, which belongs to the passive delete policy, we can actively delete keys that have not been accessed for a long time. You can delete keys that have not been accessed for a long time by using scan to traverse the keys and then using object ideltime to see the idle time of the keys.
In addition, you can reduce the memory footprint by reducing key-value objects.
127.0.1 story:course:1681 6379 > scan 01) "272" 2) 1) "story:course:3915" 2) "story:course:1681" 3) "story:course:4982".
For example, the above key can be changed to: sy:cos:id to reduce the length of the key. For values, compression techniques can be used to reduce the length of the values. (compression will increase the pressure on cpu, which can be applied according to the specific application.)
These are the details of Redis memory monitoring and management, please pay attention to other related articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.