redis-内存异常 Redis is configured to save RDB snapshots解决

连接reids获取数据时提示

 Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands t

网上搜索资料http://www.cnblogs.com/qq78292959/p/3994349.html提示

在在/etc/sysctl.conf 添加一项 ‘vm.overcommit_memory = 1‘ 重启
or
运行命令‘sysctl vm.overcommit_memory=1‘ 

问题解决。

追究缘由:

简单地说:Redis在保存数据到硬盘时为了避免主进程假死,需要Fork一份主进程,然后在Fork进程内完成数据保存到硬盘的操作,如果主进程使用了4GB的内存,Fork子进程的时候需要额外的4GB,此时内存就不够了,Fork失败,进而数据保存硬盘也失败了。

Redis的数据丢失问题

网址:http://www.linuxidc.com/Linux/2012-07/66079.htm

Redis的数据回写机制分同步和异步两种

同步回写即SAVE命令,主进程直接向磁盘回写数据。在数据大的情况下会导致系统假死很长时间,所以一般不是推荐的。
异步回写即BGSAVE命令,主进程fork后,复制自身并通过这个新的进程回写磁盘,回写结束后新进程自行关闭。由于这样做不需要主进程阻塞,系统不会假死,一般默认会采用这个方法。

个人感觉方法2采用fork主进程的方式很拙劣,但似乎是唯一的方法。内存中的热数据随时可能修改,要在磁盘上保存某个时间的内存镜像必须要冻结。冻结就会导致假死。fork一个新的进程之后等于复制了当时的一个内存镜像,这样主进程上就不需要冻结,只要子进程上操作就可以了。

在小内存的进程上做一个fork,不需要太多资源,但当这个进程的内存空间以G为单位时,fork就成为一件很恐怖的操作。何况在16G内存的主机上fork 14G内存的进程呢?肯定会报内存无法分配的。更可气的是,越是改动频繁的主机上fork也越频繁,fork操作本身的代价恐怕也不会比假死好多少。

找到原因之后,直接修改内核参数vm.overcommit_memory = 1

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

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

redis-内存异常 Redis is configured to save RDB snapshots解决的相关文章

【redis】redis异常-MISCONF Redis is configured to save RDB snapshots

使用redis报错: 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 report errors during writes if RDB snapshotting

Redis "MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk"问题的解决(转)

今天第二次遇到Redis "MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk"的问题.这个错误信息是Redis客户端工具在保存数据时候抛出的异常信息. 网上查了一下,很多人都是建议"config set stop-writes-on-bgsave-error no".这样做其实是不好的,这仅仅是让程序忽略了这个异常,使得程序能

(error) MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk.

今天运行Redis时发生错误,错误信息如下: (error) 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被配置为保存数据库快照,

Redis "MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk"问题的解决

异常详细信息 Exception in thread "main" redis.clients.jedis.exceptions.JedisDataException: 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 chec

Redis "MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk"问题

今天在程序中,jedis put数据到redis过程中,“MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk”报错: 再查看Redis日志,看到有这样的错误提示“Can’t save in background: fork: Cannot allocate memory”,这个提示很明显"Fork进程时内存不够用了!",但内存明明还有一个多G: 经

(error) 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 t

运行redis过程中,突然报错如下: (error) 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. 解决方案(百度到的答案,不过确实有用):

(error) MISCONF Redis is configured to save RDB snapshots, but is currently

项目执行删除Redis缓存时发生错误,错误信息如下: (error) 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被配置为保存数据

[Bug]redis问题解决(MISCONF Redis is configured to save RDB snapshots)

redis问题解决(MISCONF Redis is configured to save RDB snapshots) (error) 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 deta

连接Redis后执行命令错误 MISCONF Redis is configured to save RDB snapshots

今天在redis中执行setrange name 1 chun 命令时报了如下错误提示: (error) 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 er