前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >redis4的自动内存整理

redis4的自动内存整理

作者头像
保持热爱奔赴山海
发布2019-09-17 14:13:33
1.9K2
发布2019-09-17 14:13:33
举报
文章被收录于专栏:数据库相关

redis4里面自带了内存整理,可以避免内存碎片率过大的问题。

使用命令: 

config set activedefrag yes

执行完上面的命令后,稍等片刻再查看碎片率:

redis-cli -p 6379 info | grep ratio

我们在线上遇到的问题:

127.0.0.1:7001> config set activedefrag yes

(error) ERR Active defragmentation cannot be enabled: it requires a Redis server compiled with a modified Jemalloc like the one shipped by default with the Redis source distribution

看这个报错提示,貌似是jemalloc的版本与redis需要的不一致

查看下报错机器的jemalloc的版本:

redis-cli -c -p 7000 | grep jemalloc 

mem_allocator:jemalloc-3.6.0

我们的机器的redis-server的版本是4.0.10的,和jemalloc的版本差异较大。

后续: 

    我们换一台全新编译的redis-server机器, 再次执行 config set activedefrag yes  发现不再报错了。 

示例:

代码语言:javascript
复制
127.0.0.1:7001> info memory
# Memory
used_memory:5505886616
used_memory_human:5.13G
used_memory_rss:8171044864
used_memory_rss_human:7.61G
used_memory_peak:7923672456
used_memory_peak_human:7.38G
used_memory_peak_perc:69.49%
used_memory_overhead:99658336
used_memory_startup:1534088
used_memory_dataset:5406228280
used_memory_dataset_perc:98.22%
total_system_memory:135076163584
total_system_memory_human:125.80G
used_memory_lua:37888
used_memory_lua_human:37.00K
maxmemory:10737418240
maxmemory_human:10.00G
maxmemory_policy:volatile-lfu
mem_fragmentation_ratio:1.48
mem_allocator:jemalloc-4.0.3
active_defrag_running:0
lazyfree_pending_objects:0


127.0.0.1:7001> config set activedefrag yes


稍等一会,再看下结果,碎片率恢复了:
127.0.0.1:7001> info memory
# Memory
used_memory:5504344840
used_memory_human:5.13G
used_memory_rss:6649913344
used_memory_rss_human:6.19G
used_memory_peak:7923672456
used_memory_peak_human:7.38G
used_memory_peak_perc:69.47%
used_memory_overhead:99362374
used_memory_startup:1534088
used_memory_dataset:5404982466
used_memory_dataset_perc:98.22%
total_system_memory:135076163584
total_system_memory_human:125.80G
used_memory_lua:37888
used_memory_lua_human:37.00K
maxmemory:10737418240
maxmemory_human:10.00G
maxmemory_policy:volatile-lfu
mem_fragmentation_ratio:1.21
mem_allocator:jemalloc-4.0.3
active_defrag_running:0
lazyfree_pending_objects:0


可以看到  mem_fragmentation_ratio 从1.48 降低到了1.21了

redis4 碎片整理相关的配置说明:

代码语言:javascript
复制
# Enabled active defragmentation
# 碎片整理总开关
# activedefrag yes

# Minimum amount of fragmentation waste to start active defrag
# 内存碎片达到多少的时候开启整理
active-defrag-ignore-bytes 100mb

# Minimum percentage of fragmentation to start active defrag
# 碎片率达到百分之多少开启整理
active-defrag-threshold-lower 30

# Maximum percentage of fragmentation at which we use maximum effort
# 碎片率小余多少百分比开启整理
active-defrag-threshold-upper 100

# Minimal effort for defrag in CPU percentage
active-defrag-cycle-min 25

# Maximal effort for defrag in CPU percentage
active-defrag-cycle-max 75
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2018/10/21 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云数据库 Redis
腾讯云数据库 Redis(TencentDB for Redis)是腾讯云打造的兼容 Redis 协议的缓存和存储服务。丰富的数据结构能帮助您完成不同类型的业务场景开发。支持主从热备,提供自动容灾切换、数据备份、故障迁移、实例监控、在线扩容、数据回档等全套的数据库服务。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档