redis : Can't save in background: fork: Cannot allocate memory

redis : Can‘t save in background: fork: Cannot allocate memory

JAVA程序报错信息:

MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis logs for details about the error

查看redis日志:

18793:S 02 Dec 10:02:02.069 # Can‘t save in background: fork: Cannot allocate memory
18793:S 02 Dec 10:02:08.088 # Can‘t save in background: fork: Cannot allocate memory
18793:S 02 Dec 10:02:14.006 # Can‘t save in background: fork: Cannot allocate memory
18793:S 02 Dec 10:02:20.021 # Can‘t save in background: fork: Cannot allocate memory
18793:S 02 Dec 10:02:26.038 # Can‘t save in background: fork: Cannot allocate memory
18793:S 02 Dec 10:02:32.054 # Can‘t save in background: fork: Cannot allocate memory
18793:S 02 Dec 10:02:38.067 # Can‘t save in background: fork: Cannot allocate memory
18793:S 02 Dec 10:02:44.086 # Can‘t save in background: fork: Cannot allocate memory
18793:S 02 Dec 10:02:50.002 # Can‘t save in background: fork: Cannot allocate memory
18793:S 02 Dec 10:02:56.017 # Can‘t save in background: fork: Cannot allocate memory
18793:S 02 Dec 10:03:02.037 # Can‘t save in background: fork: Cannot allocate memory
18793:S 02 Dec 10:03:08.056 # Can‘t save in background: fork: Cannot allocate memory
18793:S 02 Dec 10:03:14.073 # Can‘t save in background: fork: Cannot allocate memory
18793:S 02 Dec 10:03:20.091 # Can‘t save in background: fork: Cannot allocate memory
18793:S 02 Dec 10:03:26.007 # Can‘t save in background: fork: Cannot allocate memory

数据回写分同步和异步两种方式:
同步回写(SAVE), 主进程直接向磁盘回写数据. 在数据量大的情况下会导致系统假死很长时间
异步回写(BGSAVE), 主进程fork后, 复制自身并通过这个新的进程回写磁盘, 回写结束后新进程自行关闭

由于 BGSAVE 不需要主进程阻塞, 系统也不会假死, 一般会采用 BGSAVE 来实现数据回写.

redis在dump数据的时候会启动fork子进程,由于内存不够,导致无法持久化落盘

redis有个默认的选项:

stop-writes-on-bgsave-error yes

这个选项默认情况下,如果在RDB snapshots持久化过程中出现问题,设置该参数后,Redis是不允许用户进行任何更新操作。

不彻底的解决方式是,将这个选项改为false

stop-writes-on-bgsave-error false

但是这样只是当redis写硬盘快照出错时,可以让用户继续做更新操作,但是写硬盘仍然是失败的

彻底解决方案:直接修改内核参数 vm.overcommit_memory = 1
编辑文件 /etc/sysctl.conf 添加:
vm.overcommit_memory=1
执行sysctl -p使其生效

Linux内核会根据参数vm.overcommit_memory参数的设置决定是否放行。

vm.overcommit_memory = 1,直接放行
vm.overcommit_memory = 0:则比较 此次请求分配的虚拟内存大小和系统当前空闲的物理内存加上swap,决定是否放行。
vm.overcommit_memory = 2:则会比较进程所有已分配的虚拟内存加上此次请求分配的虚拟内存和系统当前的空闲物理内存加上swap,决定是否放行。

redis : Can't save in background: fork: Cannot allocate memory

原文地址:https://www.cnblogs.com/hankyoon/p/11969716.html

时间: 2024-09-29 11:04:46

redis : Can't save in background: fork: Cannot allocate memory的相关文章

Can't save in background: fork: Cannot allocate memory

今天服务器提示不可用,查了了redis日志发现: cat /data/redis/redis-server.log [1316] 17 Jun 13:49:28.032 * 1 changes in 900 seconds. Saving... [1316] 17 Jun 13:49:28.032 # Can't save in background: fork: Cannot allocate memory [1316] 17 Jun 13:49:34.059 * 1 changes in 9

Can't rewrite append only file in background: fork: Cannot allocate memory

今天发现redis服务日志报了以下的错误: Can't rewrite append only file in background: fork: Cannot allocate memory Starting automatic rewriting of AOF on 138% growth 从日志看是aof持久化时内存不够用了导致.再看了一下maxmemory的值刚好是物理内存的一半.应该是服务redis持久化内存分配原则的,要给fork出的备份进程流出一半内存的富裕.又执行free命令查看

-bash: fork: Cannot allocate memory

linux -bash: fork: Cannot allocate memory 执行命令显示: -bash: fork: Cannot allocate memory 排查发现原因:系统的pid_max不够用了 echo 1493909 > /proc/sys/kernel/pid_max 执行命令后,系统正常

redis写磁盘报错Cannot allocate memory

查看 Redis 日志发现系统在频繁报错: [1821] 10 Nov 09:59:04.086 # Can't save in background: fork: Cannot allocate memory [1821] 10 Nov 09:59:10.002 * 1 changes in 900 seconds. Saving... 在小内存的进程上做一个fork,不需要太多资源,但当这个进程的内存空间以G为单位时,fork就成为一件很恐怖的操作.何况在16G内存的主机上fork 14G内

fork failed.: Cannot allocate memory

在做压力测试时候: [[email protected] ok]# webbench -c 5000 -t30 http://10.100.0.61/ Webbench - Simple Web Benchmark 1.5 Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software. Benchmarking: GET http://10.100.0.61/ 5000 clients, running 30 sec. Speed=1

Redis报错“ OOM command not allowed when used memory > 'maxmemory' ”

生产环境上遇到这个问题,控制台不停打印 “OOM command not allowed when used memory > 'maxmemory' ”; 起初不知道是什么,经过一番搜索: 1.登陆redis客户端:./redis-cli -h IP -p port -a passwd 2.执行命令:redis>info memory 若配置文件中,最大内存的策略设置为 maxmemory-policy volatile-lru 此配置只是清楚设置过期时间的key值,然而本应用并没有设置过期

安装composer后报错proc_open(): fork failed - Cannot allocate memory

1.问题描述: 在linux服务器使用composer 安装插件时,出现“proc_open(): fork failed - Cannot allocate memory” 也就是提示“提示内存不足”,我们可以通过创建swap分区解决这个问题. 2.解决方法: 先运行 free -m 看下空间是多少 在命令行环境依次运行以下三条命令 dd if=/dev/zero of=/var/swap.1 bs=1M count=1024 mkswap /var/swap.1 swapon /var/sw

redis内存不够 : OOM command not allowed when used memory > ‘maxmemory’

Redis内存不够,报错. 三种解决思路 注:如修改了配置文件需重启redis 1. 增加redis内存,修改redis.conf(集群中为redis-env.sh),默认为1024MB,增加到合适的内存. maxmemory 2gb 2. 修改redis存储策略 默认的redis设置是非常保守的,即内存超限后就不在存储,可以把策略修改为LRU算法(最近最少使用算法)--新存储的信息会替换掉旧的信息,从而不会是内存越线,修改redis.conf.这个必须结合业务场景,如果没有自动加载数据到red

Redis BGSAVE因为内存不足 fork 失败导致目标 Redis 无法访问的问题

中秋的时候正在外面愉快的在外卖喝着咖啡玩电脑......突发 redis 报警从 sentry 应用端曝出的错误 MISCONF Redis is configured to save RDB snapshots, but it is currently not able to persist on disk. Commands that may modify the data set are disabled, because this instance is configured to re