bigywater.tech
常见报错 · 53

Redis LOADING Redis is loading the dataset in memory:端口 0.02 秒就通、400 万 key 加载约 3 秒,PING 型健康检查会误杀,loading_eta_seconds 开头不准

Redis 重启后立刻连接,会得到 “LOADING Redis is loading the dataset in memory”。这篇用 Redis 8.10.2 在本机造一个 400 万 key 的数据集:看端口什么时候通、加载要多久、哪些命令加载期间还能用、INFO 里的进度字段靠不靠谱、为什么 PING 型的健康检查会出问题,以及从库全量同步时是什么表现。

0.02 s / 2.99 s
启动后端口已通、第一次 PING 得到 LOADING 的时间 / PING 开始返回 PONG 的时间
141.8 MB
400 万个 key 的 RDB 文件大小,本机加载约 3 秒
5 + 6
加载期间被拒的 5 个命令(PING、GET、SET、DBSIZE、KEYS)与仍可用的 6 个(INFO、CONFIG GET、CLIENT LIST、PUBLISH、ROLE、AUTH)

端口通了但还在加载

实测 · 本机执行输出
  DEBUG POPULATE 用时 2.0 s,DBSIZE = 4000000
  SAVE 用时 2.4 s,dump.rdb = 141.8 MB
  启动后第一次得到的 PING 回复(第 0.02 s):(error) LOADING Redis is loading the dataset in memory
  加载完成、PING 开始返回 PONG 的时间:2.99 s(进程启动起)
  加载期间每 0.25 s 采样一次 INFO persistence:
      t= 0.03s loading=1 loading_loaded_perc=0.74 loading_eta_seconds=1 loaded_bytes=1048573/141775871
      t= 0.29s loading=1 loading_loaded_perc=12.20 loading_eta_seconds=1 loaded_bytes=17301487/141775871
      t= 0.57s loading=1 loading_loaded_perc=23.30 loading_eta_seconds=3 loaded_bytes=33030139/141775871
      t= 0.84s loading=1 loading_loaded_perc=34.02 loading_eta_seconds=1 loaded_bytes=48234491/141775871
      t= 1.11s loading=1 loading_loaded_perc=44.38 loading_eta_seconds=1 loaded_bytes=62914540/141775871
      t= 1.38s loading=1 loading_loaded_perc=54.73 loading_eta_seconds=1 loaded_bytes=77594611/141775871
      t= 1.65s loading=1 loading_loaded_perc=64.72 loading_eta_seconds=1 loaded_bytes=91750395/141775871
      t= 1.92s loading=1 loading_loaded_perc=74.33 loading_eta_seconds=0 loaded_bytes=105381871/141775871
      t= 2.20s loading=1 loading_loaded_perc=83.57 loading_eta_seconds=0 loaded_bytes=118489083/141775871
      t= 2.47s loading=1 loading_loaded_perc=90.60 loading_eta_seconds=0 loaded_bytes=128450557/141775871
      t= 2.74s loading=1 loading_loaded_perc=99.85 loading_eta_seconds=0 loaded_bytes=141557759/141775871

先监听、后加载;PING 在加载期间返回 LOADING,loading_eta_seconds 开头不准。

哪些命令能用

实测 · 本机执行输出
  > PING                         (error) LOADING Redis is loading the dataset in memory
  > GET k:1                      (error) LOADING Redis is loading the dataset in memory
  > SET x 1                      (error) LOADING Redis is loading the dataset in memory
  > DBSIZE                       (error) LOADING Redis is loading the dataset in memory
  > KEYS zzz*                    (error) LOADING Redis is loading the dataset in memory
  > INFO server                  "# Server\r\nredis_version:8.10.2\r\nredis_git_sha1:00000000\r\nredis_git_dirty:1\r\nredis_build_id:764b3e4506
  > INFO persistence             "# Persistence\r\nloading:1\r\nasync_loading:0\r\ncurrent_cow_peak:0\r\ncurrent_cow_size:0\r\ncurrent_cow_size
  > INFO keyspace                "# Keyspace\r\ndb0:keys=133128,expires=0,avg_ttl=0,subexpiry=0\r\n"
  > CONFIG GET maxmemory         1) "maxmemory"
2) "0"
  > CLIENT LIST                  "id=4 addr=127.0.0.1:60224 laddr=127.0.0.1:8200 fd=10 name= age=0 idle=0 flags=N db=0 sub=0 psub=0 ssub=0 mult
  > PUBLISH ch m                 (integer) 0
  > AUTH x                       (error) ERR AUTH <password> called without any password configured for the default user. Are you sure your con
  > ROLE                         1) "master"
2) (integer) 0
3) (empty array)
  (之后加载结束,PING -> "PONG")

INFO、CONFIG GET、PUBLISH 等可用,读写命令被拒;PING 探针会误杀。

从库全量同步

实测 · 本机执行输出
  repl-diskless-load disabled(默认):replica 上 CONFIG GET repl-diskless-load = disabled,master 的 repl-diskless-sync = yes
  同步期间 (loading, async_loading, GET old_only) 的分布(共 42 次采样):
       22 次  loading=1 async_loading=0  GET old_only -> (error) LOADING Redis is loading the dataset in memory
       19 次  loading=0 async_loading=0  GET old_only -> "stale-value"
        1 次  loading=0 async_loading=0  GET old_only -> (nil)
  同步结束后 DBSIZE = 4000000
  repl-diskless-load swapdb:replica 上 CONFIG GET repl-diskless-load = swapdb,master 的 repl-diskless-sync = yes
  同步期间 (loading, async_loading, GET old_only) 的分布(共 17 次采样):
       15 次  loading=1 async_loading=0  GET old_only -> (error) LOADING Redis is loading the dataset in memory
        1 次  loading=0 async_loading=0  GET old_only -> "stale-value"
        1 次  loading=0 async_loading=0  GET old_only -> (nil)
  同步结束后 DBSIZE = 4000000

同步期间读得到 LOADING,swapdb 在本机没有改变这一点。

分步演示

启动加载
本步的对象

    本文用到的工具与边界

    • 本机 macOS 27 arm64 / MySQL 26.10.0 与 Redis 8.10.2(Homebrew,每个实验自己起实例,端口 9150 以上,只监听 127.0.0.1,不碰本机已有的实例)/ Python 3.15.0 + PyMySQL(按各篇注明用到哪些及版本);报错文本都是真实复现时原样捕获的;计时用 time.perf_counter,数字每次运行会有小幅抖动。本篇只用 Redis,Redis 8.10.2,端口 8200(主)、8201(从);数据集由 DEBUG POPULATE 生成(400 万个 key,key 名 k:N,value 64 字节),实验结束后数据目录删除;加载时间是这台机器上 SSD 的 RDB 加载,磁盘与 CPU 不同数字会很不一样
    • 没有验证:AOF 加载的耗时与表现(混合 RDB 前缀的 AOF 另当别论);repl-diskless-load swapdb 在什么条件下才会出现 async_loading=1(这里没有观察到);大 value / 大集合的 RDB 加载速度;loading-process-events-interval-bytes 等参数对加载期间响应的影响;Kubernetes 里 startupProbe / readinessProbe 的具体配置;Redis Cluster 节点加载时的集群状态
    京ICP备2026067502号-1京公网安备11010502063487号