Skip to content

bigkey 过大时,会导致 OOM #57

@taylorwinslet2000

Description

@taylorwinslet2000

现象:单个大 Key 全量加载到内存,导致 rdb 进程 OOM

复现方式:

  1. 使用 lua 脚本创建大 Key。List 类型,5w 个元素,占用内存 4GB
  2. bgsave 生成 RDB 文件
  3. 使用 bigkey 分析命令

期望的解决方案:当 Key 超过一定大小时,仅存统计信息


为方便理解 issue 和复现问题,我将测试现场和相关脚本放在这里:

在 FindBiggestKeys 的 dec.Parse(func(object model.RedisObject) 代码段内放置 runtime,输出如下:

  1. 1w 个 key,接近 1GB 大小,runtime.MemStats 的 alloc 为:977 MiB
  2. 1.5w 个 key,接近 1.5GB 大小,runtime.MemStats 的 alloc 为:2255 MiB

debug 问题现场图片:

Image

生成 bigkey 的 lua 代码:
`
local element_size = 83800
local element_count = 10000
local payload = string.rep('X', element_size)

for i = 1, element_count do
redis.call('RPUSH', 'example:super_big_key', payload)
end
`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions