springboot整合redis報錯:OutOfDirectMemoryError
阿新 • • 發佈:2020-09-02
錯誤資訊
壓力測試時產生堆外記憶體溢位:OutOfDirectMemoryError
原因
- springboot 2.0 以後預設使用
lettuce
作為操作 redis 的客戶端,它使用netty
進行通訊 - lettuce 的 bug 導致 netty 堆外記憶體溢位
-Xmx300m
:如果沒有指定堆外記憶體,netty 預設使用堆記憶體(Xmx)
作為 堆外記憶體
pom
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency>
解決
方法一:
不能使用 -Dio.netty.maxDirectMemory 只調大堆外記憶體
- 升級 lettuce 客戶端
- 使用 Jedis(推薦)
pom
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> <exclusions> <exclusion> <groupId>io.lettuce</groupId> <artifactId>lettuce-core</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> </dependency>