【问题标题】:Redis aborting for OUT OF MEMORYRedis 因内存不足而中止
【发布时间】:2015-07-20 20:38:20
【问题描述】:

我正在尝试将一个大文件(电影)分块移动到 redis 缓存中。 我在 Windows 机器上使用 stackexchange.redis。 redis 配置为执行 allkey-lru 并每秒使用 append。 Maxmemory 配置为 100mb。

ConnectionMultiplexer redis2 = ConnectionMultiplexer.Connect("localhost:6380, syncTimeout=100000");
IDatabase db2 = redis2.GetDatabase();

const int chunkSize = 4096;
string fileName = "D:\\movie.mp4";
using (var file = File.OpenRead(fileName))
{
    int bytesRead;
    int inCounter = 1;
    var buffer = new byte[chunkSize];
    while ((bytesRead = file.Read(buffer, 0, buffer.Length)) > 0)
    {
        db2.StringSet(file.Name + inCounter, buffer);
        inCounter++;
    }
}

当块大小为 chunkSize = 4096 时,一切正常。 但是,当我将块大小更改为 65536 时,服务器崩溃并显示以下日志:

[2816] 20 Jul 23:06:42.300 * Starting automatic rewriting of AOF on 6766592700% growth
[2816] 20 Jul 23:06:42.331 * Background append only file rewriting started by pid 3672
[3672] 20 Jul 23:06:42.331 # Write error writing append only file on disk: Invalid argument
[3672] 20 Jul 23:06:42.331 # rewriteAppendOnlyFile failed in qfork: Invalid argument
[2816] 20 Jul 23:06:42.440 # fork operation complete
[2816] 20 Jul 23:06:42.440 # Background AOF rewrite terminated with error
[2816] 20 Jul 23:06:42.549 * Starting automatic rewriting of AOF on 7232582200% growth
[2816] 20 Jul 23:06:42.581 * Background append only file rewriting started by pid 1440
[2816] 20 Jul 23:06:42.581 # Out Of Memory allocating 10485768 bytes!
[2816] 20 Jul 23:06:42.581 #

=== REDIS BUG REPORT START: Cut & paste starting from here ===
[2816] 20 Jul 23:06:42.581 # ------------------------------------------------
[2816] 20 Jul 23:06:42.581 # !!! Software Failure. Press left mouse button to continue
[2816] 20 Jul 23:06:42.581 # Guru Meditation: "Redis aborting for OUT OF MEMORY" #..\src\redis.c:3467
[2816] 20 Jul 23:06:42.581 # ------------------------------------------------
[1440] 20 Jul 23:06:42.581 # Write error writing append only file on disk: Invalid argument
[1440] 20 Jul 23:06:42.581 # rewriteAppendOnlyFile failed in qfork: Invalid argument

有什么想法吗?

【问题讨论】:

  • 当您(可能)分页到磁盘时,在 Redis 中进行缓存有什么意义?
  • 听起来您正在耗尽可用内存空间,并且无法足够快地刷新到磁盘。这可以解释为什么增加缓冲区大小会使其崩溃。

标签: c# redis stackexchange.redis


【解决方案1】:

结果是一个非常有趣和令人惊讶的问题!

造成这种情况的真正原因是他们正在使用的分配器中的内存碎片 (dlmalloc)。 希望 MSFT 能做得更好,但我预计这需要一些时间。

与此同时,解决方法。

解决此问题的正确方法(目前)

同时配置maxmemorymaxheap 参数。使maxheapmaxmemory 大很多。

因此,如果您想要 maxmemory=100MB,则将 maxheap 放大 5 倍甚至 10 倍,例如 maxheap=500MB 甚至 maxheap=1000MB。 我认为没有一个好的经验法则,maxheap 需要多大,这就是为什么它是一个如此棘手的问题。

这样的效果:Redis 仍然会尝试将内存使用量保持在100MB 之下,但实际使用的物理内存可能 大于那个值,可能高达maxheap 值。具体多少取决于碎片化程度。希望 在现实生活中,这将保持在合理的水平。


我已将问题记录在团队中。 https://github.com/MSOpenTech/redis/issues/274


编辑:根据新知识,我已经完全修改了这个答案。在编辑历史记录中查看以前的版本。

【讨论】:

  • 嗨 Komrade.P,首先感谢您的帮助。我尝试了您建议的修复程序,它处理了“内存不足”异常。然而,现在程序没有崩溃,但 appendonly 文件无法自行重写,只是继续增长,超过了 100MB 的限制。谢谢:)
  • 是的,对我也不起作用。也许与此有关:github.com/MSOpenTech/redis/issues/271。这有点蹩脚,但您可以通过设置 appendonly no 来禁用 aof。还可以使用save = "" 关闭 rdb 内容。至少这应该允许您继续。有趣的是,如果我在调试模式下编译,一切正常,这是内存问题的明确迹象。
  • 问题是我只需要附加功能。不管怎么说,还是要谢谢你。我想我会等待修复..
  • AOF 问题看起来已经解决了。 github.com/MSOpenTech/redis/issues/275,想试一试,看看现在是否适合您?
  • 我使用 2.8.2101 版本测试了该场景,问题似乎已解决。非常感谢@Komrade P。
【解决方案2】:

使用此命令设置最大堆大小它将明确起作用

redis-server redis.windows.conf --maxheap 1gb

【讨论】:

  • 我正在修复,但我们正在等待新版本
猜你喜欢
  • 1970-01-01
  • 2020-05-20
  • 1970-01-01
  • 2022-01-01
  • 2013-03-14
  • 2022-01-08
  • 2013-04-18
  • 2014-03-29
  • 1970-01-01
相关资源
最近更新 更多