当前位置:网站首页>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 .
边栏推荐
- 使用Jedis监听Redis Stream 实现消息队列功能
- redis探索之布隆过滤器
- 【ARM】在NUC977上搭建基于boa的嵌入式web服务器
- 线程优先级
- 使用Jenkins执行TestNg+Selenium+Jsoup自动化测试和生成ExtentReport测试报告
- Experience of reading the road to wealth and freedom
- Vie procédurale
- [unity3d] human computer interaction input
- Anaconda creates tensorflow environment
- localStorage浏览器本地储存,解决游客不登录的情况下限制提交表单次数。
猜你喜欢

Status of processes and communication between processes

How does P2P technology reduce the bandwidth of live video by 75%?

国务院发文,完善身份认证、电子印章等应用,加强数字政府建设

Happy New Year!

LeetCode_二叉搜索树_简单_108.将有序数组转换为二叉搜索树

uni-app吸顶固定样式

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

Leetcode513. Find the value in the lower left corner of the tree

【红队】要想加入红队,需要做好哪些准备?

ECCV 2020 double champion team, take you to conquer target detection on the 7th
随机推荐
cartographer_pose_graph_2d
Mongodb image configuration method
PHP one sentence Trojan horse
Status of processes and communication between processes
Leetcode513. Find the value in the lower left corner of the tree
使用Jedis監聽Redis Stream 實現消息隊列功能
cartographer_fast_correlative_scan_matcher_2d分支定界粗匹配
Keras actual combat cifar10 in tensorflow
Decipher the AI black technology behind sports: figure skating action recognition, multi-mode video classification and wonderful clip editing
app 应用安装到手机,不显示图标,引发的思考
Mysql 源码阅读(二)登录连接调试
[unity3d] rigid body component
Implementation of IM message delivery guarantee mechanism (II): ensure reliable delivery of offline messages
Thoughts triggered by the fact that app applications are installed on mobile phones and do not display icons
Supplementary course on basic knowledge of IM development (II): how to design a server-side storage architecture for a large number of image files?
How to select the data transmission format of instant messaging application
Apktool tool usage document
百度API地图的标注不是居中显示,而是显示在左上角是怎么回事?已解决!
Fedora alicloud source
Protocol selection of mobile IM system: UDP or TCP?