RedisCommandExecutionException: OOM command not allowed when used memory > ‘maxmemory‘.

喜欢ヅ旅行 2022-10-24 05:58 107阅读 0赞

最近服务上的Redis有部分业务报错了,很是奇怪,有部分正常,部分报错了,错误信息如下:

  1. 2021-01-28 13:48:25 [http-nio-8082-exec-9] ERROR org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].[dispatcherServlet] -Servlet.service() for servlet [dispatcherServlet] threw exception
  2. org.springframework.data.redis.RedisSystemException: Error in execution; nested exception is io.lettuce.core.RedisCommandExecutionException: OOM command not allowed when used memory > 'maxmemory'.
  3. at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:54)
  4. at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:52)
  5. at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:41)

看错误字面意思是描述内存超过了最大值,

Redis使用的是阿里云的集群版,配置是:一共20个,每个2G,

查询集群总内存的时候,看到的是才用了30G,还有10G剩余,总内存还是有空间的,为什么会出现内存不够的错误信息呢?

接着查询每一个Redis的使用情况,结果发现,其中有大概10个节点的使用率是100%了,问题找到了!!!

继续排查,查看到里面有好一些大Key,有些甚至占用一两G的,这些单个大key是不会切分到其他节点的,

每当流量进入的时候分发到各个节点,有部分节点由于内存满了就无法正常执行,内存足够的那部分节点到时正常。

找到原因了,那就好办,有多个解决方法,

第一个是把大的Key删掉,或者业务上优化掉;

第二个是把集群环境升级,比如说可以缩减为10个,每个4G,这样可以稍微容忍一些稍微大的key

所以最终的结论是,在使用Redis的时候,单个的大Key是很严重的,使用的时候一定要注意,预估一下每个Key的数量再选择相应的Redis数据类型,

发表评论

表情:
评论列表 (有 0 条评论,107人围观)

还没有评论,来说两句吧...

相关阅读