无法在后台保存(redis-server)

栏目: 数据库 · 发布时间: 5年前

内容简介:翻译自:https://stackoverflow.com/questions/42502636/unable-to-save-in-background-redis-server

我有两台 redis 服务器在同一台机器上运行.第二个日志文件有几个实例,其中包含以下通知:

[50818] 19 Feb 06:41:05.007 * 10 changes in 300 seconds. Saving...
[50818] 19 Feb 06:41:05.007 # Can't save in background: fork: Cannot allocate memory

相比之下,第一个日志文件仅包含成功的数据库保存.如果我内存不足,我估计两者都有类似的日志.令我感到困惑的是,只有一个有这个问题,另一个没有.任何线索?

此外,研究让我看到 this blog post ,它认为如果我在命令行上执行sysctl vm.overcommit_memory = 1,问题就可以得到改善.没有解释这有何帮助.有人可以在redis的背景下解释这里发生了什么吗?

按照 Redis FAQs

Background saving is failing with a fork() error under Linux even if I’ve a lot of free RAM!

Short answer: echo 1 > /proc/sys/vm/overcommit_memory

And now the long one:

Redis background saving schema relies on the copy-on-write semantic of

fork in modern operating systems: Redis forks (creates a child

process) that is an exact copy of the parent. The child process dumps

the DB on disk and finally exits. In theory the child should use as

much memory as the parent being a copy, but actually thanks to the

copy-on-write semantic implemented by most modern operating systems

the parent and child process will share the common memory pages. A

page will be duplicated only when it changes in the child or in the

parent. Since in theory all the pages may change while the child

process is saving, Linux can’t tell in advance how much memory the

child will take, so if the overcommit_memory setting is set to zero

fork will fail unless there is as much free RAM as required to really

duplicate all the parent memory pages, with the result that if you

have a Redis dataset of 3 GB and just 2 GB of free memory it will

fail. Setting overcommit_memory to 1 says Linux to relax and perform

the fork in a more optimistic allocation fashion, and this is indeed

what you want for Redis.

A good source to understand how Linux Virtual Memory work and other

alternatives for overcommit_memory and overcommit_ratio is this

classic from Red Hat Magazine, “Understanding Virtual Memory”. Beware,

this article had 1 and 2 configuration values for overcommit_memory

reversed: refer to the 07001 man page for the right meaning of

the available values.

翻译自:https://stackoverflow.com/questions/42502636/unable-to-save-in-background-redis-server


以上所述就是小编给大家介绍的《无法在后台保存(redis-server)》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

游戏引擎架构

游戏引擎架构

[美] Jason Gregory (杰森.格雷戈瑞) / 叶劲峰 / 电子工业出版社 / 2014-1 / 128.00元

《游戏引擎架构》同时涵盖游戏引擎软件开发的理论及实践,并对多方面的题目进行探讨。本书讨论到的概念及技巧实际应用于现实中的游戏工作室,如艺电及顽皮狗。虽然书中采用的例子通常依据一些专门的技术,但是讨论范围远超于某个引擎或API。文中的参考及引用也非常有用,可让读者继续深入游戏开发过程的任何特定方向。 《游戏引擎架构》为一个大学程度的游戏编程课程而编写,但也适合软件工程师、业余爱好者、自学游戏程......一起来看看 《游戏引擎架构》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具