當進行壓力測試時后期后出現堆外內存溢出OutOfDirectMemoryError
產生原因:
1)、springboot2.0以后默認使用lettuce作為操作redis的客戶端,它使用netty進行網絡通信
2)、lettuce的bug導致netty堆外內存溢出。netty如果沒有指定堆外內存,默認使用Xms的值,可以使用-Dio.netty.maxDirectMemory進行設置
解決方案:由於是lettuce的bug造成,不能直接使用-Dio.netty.maxDirectMemory去調大虛擬機堆外內存,治標不治本。
1)、升級lettuce客戶端。但是沒有解決的
2)、切換使用jedis
<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>
