REdis之maxmemory解读
redis.conf中的maxmemory定义REdis可用最大物理内存,有多种书写方式,以下均为合法:
|
maxmemory 1048576 maxmemory 1048576B maxmemory 1000KB maxmemory 100MB maxmemory 1GB maxmemory 1000K maxmemory 100M maxmemory 1G |
没有带单位尾巴的为字节数,以B结尾的表示相应的大小。但需要注意KB和K、MB和M、GB和G是不同的,如1K表示1000字节,而1KB则为1024字节。如果maxmemory值为0,表示不做限制。
如果是32位系统,当maxmemory值为0时,redis启动时会记录WARN日志:
|
Warning: 32 bit instance detected but no memory limit set. Setting 3 GB maxmemory limit with 'noeviction' policy now. |
并强制将最大内存设置为3GB,同时将内存策略设置为MAXMEMORY_NO_EVICTION(超出maxmemory后,所有写操作失败,读操作成功):
|
server.maxmemory = 3072LL*(1024*1024); /* 3 GB */ server.maxmemory_policy = MAXMEMORY_NO_EVICTION; |
如果设置的maxmemory小于1MB,则redis启动时记录如下日志:
|
WARNING: You specified a maxmemory value that is less than 1MB (current value is %llu bytes). Are you sure this is what you really want? |
相关的源代码如下:
|
/* Convert a string representing an amount of memory into the number of * bytes, so for instance memtoll("1Gb") will return 1073741824 that is * (1024*1024*1024). * * On parsing error, if *err is not NULL, it's set to 1, otherwise it's * set to 0. On error the function return value is 0, regardless of the * fact 'err' is NULL or not. */ long long memtoll(const char *p, int *err) { const char *u; char buf[128]; long mul; /* unit multiplier */ long long val; unsigned int digits; if (err) *err = 0; /* Search the first non digit character. */ u = p; if (*u == '-') u++; while(*u && isdigit(*u)) u++; if (*u == '\0' || !strcasecmp(u,"b")) { // 调用strcasecmp不区分大小比较 mul = 1; } else if (!strcasecmp(u,"k")) { mul = 1000; // 不带尾巴B或b的 } else if (!strcasecmp(u,"kb")) { mul = 1024; // 带尾巴B或b的 } else if (!strcasecmp(u,"m")) { mul = 1000*1000; // 不带尾巴B或b的 } else if (!strcasecmp(u,"mb")) { mul = 1024*1024; // 带尾巴B或b的 } else if (!strcasecmp(u,"g")) { mul = 1000L*1000*1000; // 不带尾巴B或b的 } else if (!strcasecmp(u,"gb")) { mul = 1024L*1024*1024; // 带尾巴B或b的 } else { if (err) *err = 1; return 0; } /* Copy the digits into a buffer, we'll use strtoll() to convert * the digit (without the unit) into a number. */ digits = u-p; if (digits >= sizeof(buf)) { if (err) *err = 1; return 0; } memcpy(buf,p,digits); buf[digits] = '\0'; char *endptr; errno = 0; val = strtoll(buf,&endptr,10); if ((val == 0 && errno == EINVAL) || *endptr != '\0') { if (err) *err = 1; return 0; } return val*mul; } // 有关REdis内存策略的实现,请参见REdis源码文件evict.c。 |
如果没有禁用config命令,则可用它动态实时修改maxmemory的值,如将maxmemory设置为15GB:
|
redis-cli -h 192.168.31.8 -p 6379 config set maxmemory 15GB |
如果要查看maxmemory的值,有如下两种方法:
|
redis-cli -h 192.168.31.8 -p 6379 config get maxmemory 或 redis-cli -h 192.168.31.8 -p 6379 info memory | grep maxmemory |
由于REdis一般占大内存,所以通常需要关闭系统的OOM,方法为将“/proc/sys/vm/overcommit_memory”的值设置为1(通常不建议设置为2),也可以使用命令sysctl设置,如:sysctl vm.overcommit_memory=1,但注意一定要同时修改文件/etc/sysctl.conf,以便得系统重启后仍然生效:
|
# vi /etc/sysctl.conf vm.overcommit_memory=1 |
修改sysctl.conf后,需要执行“sysctl -p”以使生效。
REdis之maxmemory解读的更多相关文章
- redis的maxmemory设置以及淘汰策略介绍
转载地址:http://www.2cto.com/database/201507/420889.html redis的maxmemory参数用于控制redis可使用的最大内存容量.如果超过maxmem ...
- redis的maxmemory与maxmemory-policy关系
如果redis配置了maxmemory和maxmemory-policy策略,则当redis内存数据达到maxmemory时,会根据maxmemory-policy配置来淘汰内存数据,以避免OOM.r ...
- Redis 的 maxmemory 和 dbnum 默认值都是多少?对于最大值会有限制吗?
一.Redis 的默认配置 了解 Redis 的都知道,Redis 服务器状态有很多可配置的默认值. 例如:数据库数量,最大可用内存,AOF 持久化相关配置和 RDB 持久化相关配置等等.我相信,关于 ...
- Redis protected-mode属性解读
redis3.2版本后新增protected-mode配置,默认是yes,即开启.设置外部网络连接redis服务,设置方式如下: 1.关闭protected-mode模式,此时外部网络可以直接访问 2 ...
- (十)redis源码解读
一.redis工作机制 redis是 单线程,所有命令(set,get等)都会加入到队列中,然后一个个执行. 二.为什么redis速度快? 1.基于内存 2.redis协议resp 简单.可读.效率高 ...
- redis源码解读--内存分配zmalloc
目录 主要函数 void *zmalloc(size_t size) void *zcalloc(size_t size) void zrealloc(void ptr, size_t size) v ...
- redis 哨兵配置文件解读sentinel.conf
# Example sentinel.conf # port <sentinel-port>port 8001 # 守护进程模式daemonize yes # 指明日志文件名logfile ...
- Redis: OOM command not allowed when used memory > ‘maxmemory’
现象 日志里出现异常: OOM command not allowed when used memory > 'maxmemory' 原因 内存已满,不允许再存数据了,可以通过redis-cli ...
- redis之哨兵部署运行日志解读
转载自http://www.run-debug.com/?p=674 192.168.110.21 主 192.168.110.31 从 #两台服务器都安装redis #下载最新稳定版本:http:/ ...
随机推荐
- 2019 字节跳动java面试笔试题 (含面试题解析)
本人5年开发经验.18年年底开始跑路找工作,在互联网寒冬下成功拿到阿里巴巴.今日头条.字节跳动等公司offer,岗位是Java后端开发,因为发展原因最终选择去了字节跳动,入职一年时间了,也成为了面 ...
- IDEA中调试时F8,F7快捷键失效
idea中调试时F8,F7快捷键失效 原因:相关软件的快捷键占用了F8,F7,如我的有道词典占用F8了这个快捷键,导致idea调试时不能使用F8,改变有道词典的快捷键即可.
- 学习vue生命周期
首先,每个Vue实例在被创建之前都要经过一系列的初始化过程,这个过程就是vue的生命周期.首先看一张图吧~这是官方文档上的图片相信大家一定都会很熟悉: 可以看到在vue一整个的生命周期中会有很多钩子函 ...
- 利用onMouseOver和onMouseOut实现图像翻滚
代码: <img src="images/001.jpg" alt="pic" onmouseover="this.src='images/00 ...
- Hybris服务器启动日志分析
build文件检测,使用b2c_acc recipit启动服务器:/home/jerrywang/Hybris/installer/recipes/b2c_acc/build.gradle The T ...
- Hive架构分析
一.Hive三种设计模式 1.默认配置[使用Netty存储元数据] 2.mysql[使用mysql存储元数据] 3.配置Thrift[使用mysql存储元数据] 二.执行步骤 三.scala访问Hiv ...
- SpringBoot2.x服务器端主动推送技术
一.服务端推送常用技术介绍 服务端主流推送技术:websocket.SSE等 1.客户端轮询:ajax定时拉取后台数据 js setInterval定时函数 + ajax异步加载 定时向服务 ...
- cookie登录及其保存
requests中request携带cookie请求1 将一个Session实例的cookies属性设置赋值成 一个 CookieJar 实例 import http.cookiejar s = re ...
- VMware15.5版本通过挂载系统光盘搭建yum仓库
VMware15.5版本通过挂载系统光盘搭建yum仓库一.1.打开CentOS 7虚拟机. 2.登录虚拟机,选择未列出 用户名:root 密码:输入自己设置的密码 点击登录. 3.右键单击打开终端. ...
- MySQL优化整理
一.SQL优化 1.show status查看各种sql的执行频率 SHOW STATUS 可以根据需要显示 session 级别的统计结果和 global级别的统计结果. 显示当前sessi ...