一、Redis 深度优化手册
1.1 内存管理高级配置
# 内存淘汰策略(6种模式详解)
maxmemory-policy volatile-lru # 生产推荐使用
/* 策略说明:
- volatile-lru:只淘汰有过期时间的key
- allkeys-lru:所有key参与LRU
- volatile-ttl:淘汰即将过期的
- volatile-random:随机淘汰带过期key
- noeviction:不淘汰(可能引发OOM)*/
# 内存碎片整理(Redis 4.0+)
activedefrag yes
active-defrag-ignore-bytes 100mb
active-defrag-threshold-lower 10
active-defrag-threshold-upper 100
1.2 持久化优化方案
RDB与AOF混合模式:
save 900 1 # 触发快照的条件
appendonly yes # 开启AOF
appendfsync everysec # 折衷方案
aof-rewrite-incremental-fsync yes
# 重写触发条件
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
性能测试命令:
redis-benchmark -h 127.0.0.1 -p 6379 -n 100000 -c 100 -P 16
# 参数说明:
# -n 请求总数
# -c 并发连接数
# -P 管道请求数
1.3 集群优化策略
数据分片规则:
slot = CRC16(key) mod 16384
跨机房同步方案:
- 使用Redis-Shake工具同步
- 配置
replica-announce-ip
解决NAT问题 - 设置
cluster-node-timeout 15000
(毫秒)
本文来自投稿,不代表本站立场,如若转载,请注明出处: