使用spring boot 2.0后集成的redis报直接内存溢出异常

 

在使用spring boot 2.0后集成的redis,在高并发的情况下报 如上图所示的异常:

Redis exception; nested exception is io.lettuce.core.RedisException: io.netty.util.internal.OutOfDirectMemoryError: failed to allocate 37748736 byte(s) of direct

原因有如下:
1、spring boot 2.0以后默认使用的是lettuce作为操作redis的客户端。它使用netty进行网络通信;

2、lettuce的bug导致netty堆外内存溢出,netty如果没有指定堆外内存,默认使用 -Xmx100m(堆的大小); netty可以通过

-Dio.netty.maxDirectMemory进行设置;

解决方案:不要使用-Dio.netty.maxDirectMemory进行调大堆外内存;

a、升级lettuce 客户端;

b、切换到jedis;

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章