流水线时Redis中的MemoryError

时间:2017-08-31 07:39:14

标签: python redis amazon-elasticache redis-py

我正在使用此python脚本将数据从一个ElastiCache redis实例迁移到另一个。它使用redis管道传输以块的形式迁移数据。

https://gist.github.com/thomasst/afeda8fe80534a832607

但我收到了这个奇怪的错误:

Traceback (most recent call last):###########                                         | ETA:  0:00:12
  File "migrate-redis.py", line 95, in <module>
    migrate()
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 664, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 644, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 837, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 464, in invoke
    return callback(*args, **kwargs)
  File "migrate-redis.py", line 74, in migrate
    results = pipeline.execute(False)
  File "/usr/local/lib/python2.7/dist-packages/redis/client.py", line 2593, in execute
    return execute(conn, stack, raise_on_error)
  File "/usr/local/lib/python2.7/dist-packages/redis/client.py", line 2446, in _execute_transaction
    all_cmds = connection.pack_commands([args for args, _ in cmds])
  File "/usr/local/lib/python2.7/dist-packages/redis/connection.py", line 637, in pack_commands
    output.append(SYM_EMPTY.join(pieces))
MemoryError

RAM没有问题,因为节点有6 GB的RAM。

源redis的内存配置文件如下:

used_memory:1483900120
used_memory_human:1.38G
used_memory_rss:1945829376
used_memory_peak:2431795528
used_memory_peak_human:2.26G
used_memory_lua:86016
mem_fragmentation_ratio:1.31
mem_allocator:jemalloc-3.6.0

可能的原因是什么?

1 个答案:

答案 0 :(得分:0)

从您的错误日志中,它与您的redis服务器无关。当redis客户端将所有命令打包到内存缓冲区时,会发生错误。

也许您可以尝试减少migrate-redis.py中的SCAN计数选项,以测试它是否太大而无法打包。