使用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;

 

 

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