Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the memory leak error caused by redis starting with lettuce

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to solve the memory leak error caused by redis using lettuce startup", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to solve the memory leak error caused by redis using lettuce startup.

Redis appears using lettuce

LEAK: hashedwheelTimer.release () was not called before it's garbage-collected. Enable advanced leak

Memory leak. In fact, the memory is not large enough.

Find window- > preferences- > Java- > Installed JRE in eclispe, click the Edit button on the right, and enter the following values in the "Default VM Arguments" option in the editing interface.

-Xms64m-Xmx128m

The memory adjustment is large enough to be solved.

Another method cannot be solved. I don't know if the method is set up incorrectly.

1. Open the eclipse configuration file eclipse.ini, and change the-Xmx (its value represents the maximum amount of memory that jvm can use)

two。 When running the java program, select run- > run configuration- > arguments, and enter-Xms100M-Xmx800M (- Xms represents the amount of memory allocated when jvm starts, and-Xmx represents the maximum amount of memory that can be allocated).

Add: Redis connection pool Lettuce crater record

I. introduction

Recently, the project has frequently deployed different test environments, and has stepped on a lot of Redis pitfalls in the process of building the operating environment and deploying the project. The project is based on SpringBoot2.1.12,SpringBoot2.1.X integration jar package Spring-data-redis-start using Lettuce as the Redis connection pool.

SpringBoot1.x defaults to Jedis as the redis client connection pool.

SpringBoot2.x,spring-data-redis defaults to Lettuce as the redis client driver connection pool.

Second, step on the pit scene

The unstable connection of a master node in the running environment Redis cluster causes the SpringBoot application to connect to Redis and timeout in error.

III. Solutions

Rewrite RedisConnectionFactory Bean based on Spring-data-redis. You need to set "unvalidate the membership of the cluster node": .validateClusterNodeMembership (false).

1 、 Redis configuration spring: redis: cluster: nodes:-${redis.host.cluster} # redis Cluster ip-port password: ${redis.password} timeout: 5000 # connection timeout lettuce: pool: max-active: 10 # connection pool maximum number of connections max-wait:-1 # connection pool maximum blocking time max-idle: 5 # maximum idle connections in the connection pool Min-idle: 1 # minimum idle connection in the connection pool redis: cluster: enabled: true2, Config configuration class @ Data@Component@ConditionalOnProperty (name = "redis.cluster.enabled" HavingValue = "true", matchIfMissing = false) public class RedisConfig {@ Autowired RedisProperties redisProperties / / when building LettuceConnectionFactory, if you do not use the built-in destroyMethod, it may cause the Redis connection to be terminated earlier than other Bean @ Bean (destroyMethod = "destroy") public RedisConnectionFactory newLettuceConnectionFactory () {/ / configure to enable adaptive refresh and scheduled refresh. If adaptive refresh is not enabled, Redis cluster changes will cause connection exception ClusterTopologyRefreshOptions clusterTopologyRefreshOptions = ClusterTopologyRefreshOptions.builder () .enablePeripheral Refresh (Duration.ofSeconds (60)) / / enable cycle refresh (default 60 seconds) .enableAdaptiveR efreshTriggers (RefreshTrigger.ASK_REDIRECT,RefreshTrigger.UNKNOWN_NODE) / / enable adaptive refresh .build () ClusterClientOptions clusterClientOptions = ClusterClientOptions.builder () .topologyRefresh options (clusterTopologyRefreshOptions) / / Topology refresh .disconnectedBehavior (ClientOptions.DisconnectedBehavior.REJECT_COMMANDS) .autoReconnect (true) .socketOptions (SocketOptions.builder () .socketOptions (true)) .build () .validateClusterNodeMembership (false) / / Uncheck the membership of the cluster node. Build () LettuceClientConfiguration clientConfig = LettuceClientConfiguration.builder () .clientOptions (clusterClientOptions) .readFrom (ReadFrom.SLAVE_PREFERRED) .build (); return new LettuceConnectionFactory (getClusterConfiguration (), clientConfig);} private RedisClusterConfiguration getClusterConfiguration () {RedisProperties.Cluster clusterProperties = redisProperties.getCluster (); RedisClusterConfiguration config = new RedisClusterConfiguration (clusterProperties.getNodes ()) If (clusterProperties.getMaxRedirects ()! = null) {config.setMaxRedirects (clusterProperties.getMaxRedirects ());} if (redisProperties.getPassword ()! = null) {config.setPassword (RedisPassword.of (redisProperties.getPassword ();} return config;}}

Note:

RedisClusterConfiguration getClusterConfiguration () needs to set Password, otherwise SpringBoot starts to report an authentication error:

"io.lettuce.core.RedisCommandExecutionException: NOAUTH Authentication required"

As follows:

In addition, the lettuce-core jar package version cannot be too low to avoid some configuration items that cannot be supported. The above configuration is lettuce-core-5.18.RELEASE.jar.

At this point, I believe you have a deeper understanding of "how to solve the memory leak error caused by redis using lettuce startup". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report