当前位置:网站首页>Redis usage and memory optimization
Redis usage and memory optimization
2022-06-26 05:23:00 【Air transport Alliance】
About Redis Installation configuration , You can refer to : https://blog.csdn.net/weixin_46307478/article/details/122204294
About Python Use Redis, You can refer to :https://blog.csdn.net/weixin_46307478/article/details/122953512
3、 ... and 、Redis Usage and memory optimization
redis In fact, the cost of memory management is very high , That is, it takes up too much memory , It belongs to trading space for time . The author is also very clear about this , Therefore, it provides a series of parameters and means to control and save memory
It is recommended not to turn on VM( Virtual memory ) Options
VM Option is as Redis A persistence strategy that stores data that exceeds physical memory and is swapped in and out of memory and disk , It will seriously slow down the running speed of the system , So close VM function , Please check your redis.conf In file vm-enabled by no.
Set the maximum memory option
It is better to set redis.conf Medium maxmemory Options , This option is to tell Redis How much is used Physical memory Then it starts to reject subsequent write requests , This parameter can protect your Redis Will not be caused by using too much physical memory swap, Eventually, it will seriously affect the performance and even crash .
Generally, you also need to set the memory saturation recovery policy
- volatile-lru: From the set of data for which the expiration time has been set (server.db[i].expires) Select the least recently used data in
- volatile-ttl: From the set of data for which the expiration time has been set (server.db[i].expires) To select the data to be expired
- volatile-random: From the set of data for which the expiration time has been set (server.db[i].expires) In the arbitrary selection of data elimination
- allkeys-lru: From the data set (server.db[i].dict) Select the least recently used data in
- allkeys-random: From the data set (server.db[i].dict) In the arbitrary selection of data elimination
- no-enviction( deportation ): Exclusion data
Parameters that control memory usage
Redis A set of parameters is provided for different data types to control memory usage
- Hash
redis.conf Below the configuration file 2 term
- **hash-max-zipmap-entries 64 **
The meaning is when value This Map When there are no more than a few internal members, it will be stored in a linear compact format , The default is 64, namely value Internal 64 Less than members use linear compact storage zipmap, If the value is exceeded, it will be automatically converted to real HashMap(ht).
- hash-max-zipmap-value 512
hash-max-zipmap-value The meaning is when value This Map The length of each internal member value does not exceed
How many bytes will use linear compact storage zipmap To save space .
above 2 Conditions any condition that exceeds the set value will be converted into a real HashMap, It will no longer save memory , But the bigger the better ( The space and the efficiency of checking and modifying need to be weighed according to the actual situation )
- List
- list-max-ziplist-entries 512
list How many nodes of the data type are followed by a compact storage format with no pointer ziplist - list-max-ziplist-value 64
list Data type node values smaller than what bytes are stored in a compact format ziplist.
- Set
- set-max-intset-entries 512
set Data type internal data if all are numeric , And how many nodes are included below will be stored in compact format
Redis Internal optimization
- Redis The internal implementation does not optimize the memory allocation too much , There will be memory fragmentation to some extent , But most of the time this won't be Redis Performance bottlenecks .
- Redis Cache a certain range of Constant number Share as a resource , In many cases, numeric data types can greatly reduce memory overhead , The default is 1-10000, You can recompile the configuration to modify a line of macro definitions in the source code REDIS_SHARED_INTEGERS.
How to clean up memory fragments ?
restart Redis example :
- If Redis The data in is not persistent , that , The data is lost ;
- Even if Redis Data persistence , We still need to pass AOF or RDB Resume , The length of recovery depends on AOF or RDB Size , If only one Redis example , There is no service available in the recovery phase .
Fortunately, , from 4.0-RC3 After the version ,Redis It provides a method to clean up memory fragments automatically :
The basic mechanism :
- Memory fragmentation , Simply speaking , Namely “ Move to give way , Merge spaces ”.

Redis Parameters specially set for automatic memory fragment cleaning mechanism :
- Control the start and end time of debris cleaning
- The amount of CPU The proportion
- So as to reduce the impact of debris cleaning on Redis Performance impact of request processing itself
First ,Redis Automatic memory defragmentation needs to be enabled , You can put activedefrag Configuration item set to yes, The order is as follows :

Conditions that trigger cleanup ( Need to meet at the same time ):
- active-defrag-ignore-bytes 100mb: The number of bytes representing memory fragmentation reaches 100MB when , Start cleaning ;
- active-defrag-threshold-lower 10: Represents the percentage of memory fragmentation allocated by the operating system to Redis The proportion of total space reached 10% when , Start cleaning .
In order to minimize debris cleaning on Redis The impact of normal request processing , When the automatic memory fragmentation function is executed , It will also monitor the occupancy of the cleaning operation CPU Time , And there are two parameters , They are used to control the occupation of CPU In proportion to time 、 Lower limit , Ensure that the cleaning work can be carried out normally , And avoid lowering Redis performance . These two parameters are as follows :
- active-defrag-cycle-min 25: Represents the automatic cleaning process CPU The proportion of time is no less than 25%, Make sure the cleaning can be carried out normally ;
- active-defrag-cycle-max 75: Represents the automatic cleaning process CPU The proportion of time is not higher than 75%, Once you surpass , Just stop cleaning up , In order to avoid cleaning , A lot of memory copies are blocked Redis, This leads to an increase in response delay .
边栏推荐
- cartographer_ optimization_ problem_ 2d
- Supplementary course on basic knowledge of IM development (II): how to design a server-side storage architecture for a large number of image files?
- As promised: Mars, the mobile terminal IM network layer cross platform component library used by wechat, has been officially open source
- The beautiful scenery is natural, and the wonderful pen is obtained by chance -- how is the "wonderful pen" refined?
- Protocol selection of mobile IM system: UDP or TCP?
- Two step processing of string regular matching to get JSON list
- 【ARM】在NUC977上搭建基于boa的嵌入式web服务器
- Classic theory: detailed explanation of three handshakes and four waves of TCP protocol
- [unity3d] rigid body component
- thread priority
猜你喜欢

cartographer_fast_correlative_scan_matcher_2d分支定界粗匹配
Technical past: tcp/ip protocol that has changed the world (precious pictures, caution for mobile phones)

Ai+ remote sensing: releasing the value of each pixel

Happy New Year!

Codeforces Round #802 (Div. 2)(A-D)

Could not get unknown property ‘*‘ for SigningConfig container of type org.gradle.api.internal

Ad tutorial series | 4 - creating an integration library file

使用Jenkins执行TestNg+Selenium+Jsoup自动化测试和生成ExtentReport测试报告

The beautiful scenery is natural, and the wonderful pen is obtained by chance -- how is the "wonderful pen" refined?

Create SSH key pair configuration steps
随机推荐
百度API地图的标注不是居中显示,而是显示在左上角是怎么回事?已解决!
[unity3d] human computer interaction input
data = self._ data_ queue. get(timeout=timeout)
[greedy college] recommended system engineer training plan
Mysql 源码阅读(二)登录连接调试
Gd32f3x0 official PWM drive has a small positive bandwidth (inaccurate timing)
使用Jedis监听Redis Stream 实现消息队列功能
FastAdmin Apache下设置伪静态
Tensorflow and deep learning day 3
Second day of deep learning and tensorfow
thread priority
AutowiredAnnotationBeanPostProcessor什么时候被实例化的?
Could not get unknown property ‘*‘ for SigningConfig container of type org. gradle. api. internal
PHP二维/多维数组按照指定的键值来进行升序和降序
PHP之一句话木马
cartographer_ fast_ correlative_ scan_ matcher_ 2D branch and bound rough matching
Vie procédurale
Computer Vision Tools Chain
[leetcode] 713: subarray with product less than k
How to make your big file upload stable and fast?