【发布时间】: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