Springboot uses redis stress test memory leak solution

We introduce redis dependency is

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>

The out-of- heap memory overflow caused by the pressure test : OutOfDirectMemoryError Reasons:
1) After Springboot 2.0 , Lettuce is used by default as the client for operating redis. It uses netty for network communication.
2), Lettuce’s bug caused netty off-heap memory to overflow -Xmx300m; if netty does not specify off-heap memory, Xmx300m
can be set by default by using -Dio.netty.maxDirectMemory.
Solution: You cannot use -Dio.netty.maxDirectMemory just to adjust A large amount of off-heap memory.
1). Lettuce client can be upgraded. 2) You can switch to use jedis.
Here we are switching to jedis, so we need to modify the corresponding default lettuce to exclude the adjustment and add jedis dependency.

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-data-redis</artifactId>
   <exclusions>
       <!-- Lettuce的bug导致netty堆外内存溢出 切换使用jedis-->
       <exclusion>
           <groupId>io.lettuce</groupId>
           <artifactId>lettuce-core</artifactId>
       </exclusion>
   </exclusions>
</dependency>
<!--       Lettuce的bug导致netty堆外内存溢出 切换使用jedis-->
<dependency>
   <groupId>redis.clients</groupId>
   <artifactId>jedis</artifactId>
</dependency>

Guess you like

Origin blog.csdn.net/u014496893/article/details/113847297