redis advance

2020-02-27 201浏览

  • 1.Redis⾼级讲义 峰云就她了 xiaorui.cc github.com/rfyiamcool
  • 2.key的规范 加⼊业务的前缀 长度控制在30个字符以内 ⼀级key不要超过千万 同样ziplist类型的hash比strings省内存
  • 3.Value的规范 选择合适的数据结构 长字符压缩存取 (snappy, msgpack, more…) 避免big key ( 删除和迁移时阻塞) 避免hot key (单点性能)
  • 4.优化慢请求 避免使用O(n)的指令 (keys *, hgetall, smembers, sunion …) 使用scan, hscan, sscan, zscan 业务层规避这类设计
  • 5.提⾼吞吐 使用pipeline批量传输, 减少⽹络RTT 使用多值指令 (mset, hmset) 使用script lua ⼲掉aof ?
  • 6.(big key) or (hot key) big key scan / small range get del > unlink (redis 4.0 async del) hash shard hot key hash shard
  • 7.不推荐使用命令 pub sub redis transction more …
  • 8.redis lua 减少RTT消耗 保证多指令原⼦性 自定义指令
  • 9.lua 场景 zset的zpop semphore分布式锁 自增id⽣成器
  • 10.redis module 注册新指令 性能比redis lua更强劲 redis 4.0 以上
  • 11.经历过的性能指标 1w 的稳定长连接 9w TPS 队列千万级别 百万数量key
  • 12.单机进化到多实例 什么是多实例 为什么要多实例化 多实例化需要注意什么?
  • 13.what 多实例 6379 6380 6381 ++ redis1 redis2 redis3 more
  • 14.why 多实例 最⼤程度的使用内存 避免单实例RDB时 被kernel oom 使用swap造成阻塞. 单实例启动太慢 扩展, 迁移, 内存随便整理
  • 15.copy on write will block 绕开redis单⼯作线程的问题 阻塞指令 busy event hashcrc more …
  • 16.How 多实例 128G 总内存. 11G 为⼀个实例, 启动个10实例. 空出18G做缓冲. 后台脚本来触发bgsave. 启动时也是⼀个个的启动
  • 17.简约集群 vip多线程版 twemproxy codis redis cluster
  • 18.codis vs redis cluster cluster codis hash_tag y y design 中⼼化 去中⼼化 pipeline client move order 支持 slot y y 多租户 y y 性能 high this < cluster code 范围 复杂 简单 ⼴ 也有不少⼤厂
  • 19.redis cluster
  • 20.codis codis-proxy codis-proxy zookeeper redis-m redis-s 主机组 redis
  • 21.redis 使用的⾼级场景 定时器 去重优先级fifo队列 分布式锁 More …
  • 22.定时器 zset (score = timestamp, value=task) sadd zpop Feeds Feeds 任务去重 lua zpop func comsumer comsumer
  • 23.token bucket zset (score = timestamp, value=token) sadd zpop allow burst Feeds comsumer comsumer
  • 24.req rate limiter client client True False diff_ts := now - ts if diff_ts > period { return wait } return pass prefix period ts prefix counter ts
  • 25.伪ack队列 zset (score = timestamp, value=task) 4. ack pop, ack by lua !!! 1. push producter 3. add in zset list comsumer 2. pop comsumer
  • 26.去重优先级的FIFO队列 set ( 作为去重特性 ) queue_1 queue_2 redis lua 封装增删改查 queue_3
  • 27.分布式锁 安全可靠 lua make ( compare and set ) !!! say no 可重⼊锁 set + nx + ex client_1 Redis true say yes 公平调度 say hard { bll_lock_key:ident } client_2 set + nx + ex false
  • 28.排查问题 外部 redis-cli monitor 内部 keyspace slow log
  • 29.内存碎片 - - bigkeys string, bytes空间 set, list, zset, hash, 元素个数 rdb tool 具体占用空间
  • 30.memory usage key_name 阻塞及延迟 redis-cli --intrinsic-latency 10 redis-cli --latency-history
  • 31.监控 info -> instantaneous_ops_per_sec info -> used_memory_human /proc/{pid}/smaps connected_clients
  • 32.项目分享https://github.com/rfyiamcool/go_redis_semaphorehttps://github.com/rfyiamcool/zset_zpophttps://github.com/rfyiamcool/redis_unique_queuehttps://github.com/rfyiamcool/redis_modules_ackqueuehttps://github.com/rfyiamcool/go_redis_lockhttps://github.com/rfyiamcool/kvdis
  • 33.other ext redis 多线程⽅案 去除cow机制的rdb,进化binlog模式 redis rocksdb的持久化⽅案 more …
  • 34.“ 别说话 ! ” –峰云就她了