redis产生堆外内存溢出:OutOfDirectMemoryError

产生原因:

  • 1.springboot2.0以后,使用默认的lettuce作为操作reids的客户端,它使用netty进行网络通信
  • 2.lettuce的bug导致netty堆外内存溢出 -Xmx300m; netty如果没有指定堆外内存,默认使用-Xmx300m
    可以通过-Dio.netty.maxDirectMemory进行设置

解决方案:

不能使用 -Dio.netty.maxDirectMemory 只去调大堆外内存(时间长了,终究会撑爆)

  1. 升级letture客户端 2) 切换使用jedis
    redisTemplate:
    lettuce,jedis操作redis的底层客户端,Spring再次封装redisTemplate;

解决方法

  <!--        引入redis作为缓存-->
        <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>
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐