Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lettuce client reconnecting frequently #2848

Closed
sksamuel opened this issue May 6, 2024 · 1 comment
Closed

Lettuce client reconnecting frequently #2848

sksamuel opened this issue May 6, 2024 · 1 comment

Comments

@sksamuel
Copy link

sksamuel commented May 6, 2024

Current Behavior

We are seeing that AWS elasticache redis is reporting connections are being made constantly.

image

The slight peaks in that chart are the periodic refreshes we have enabled at 30 minute intervals.

Input Code

Here is the basic setup code.

   val clientResources = DefaultClientResources.builder()
      .commandLatencyRecorder(DefaultCommandLatencyCollector.disabled())
      .reconnectDelay(
         Delay.fullJitter(
            /* lower = */ Duration.ofMillis(100),     // minimum 100 millisecond delay
            /* upper = */ Duration.ofSeconds(10),      // maximum 10 second delay
            /* base = */ 100, /* targetTimeUnit = */ TimeUnit.MILLISECONDS // 100 millisecond base
         ),
      ).build()

   val topologyRefreshOptions = ClusterTopologyRefreshOptions.builder()
      .closeStaleConnections(true)
      .enableAllAdaptiveRefreshTriggers()
      .dynamicRefreshSources(true)
      .enablePeriodicRefresh(30.minutes.toJavaDuration())
      .build()

   val clusterClient = RedisClusterClient.create(clientResources, uri).apply {
      setOptions(
         ClusterClientOptions
            .builder()
            .topologyRefreshOptions(topologyRefreshOptions)
            .maxRedirects(10)
            .pingBeforeActivateConnection(false)
            .validateClusterNodeMembership(false)
            .build()
      )
   }

And then we simply do client.connect(codec)
And .async() each time we need the connection

The last part .async() is called repeatedly, but the docs say this does not cause a new connection.

The AWS metrics for new connections should not be reporting constant new connections.

Environment

  • Lettuce version(s): [6.3.2]
  • Redis version: [various, mostly 7.07, some 7.10]

Additional context

In order to check what the AWS metrics are showing correctly, I've tried various combinations of validate node membership, ping before activate connection. Changing periodic refresh to say 30 seconds, increases the number of new connections massively. But even putting this at 8 hours or off completely does not eridicate this base line of new connections.

We also have around 25 redis instances, of varying master and replica counts, and this happens on all. All our caches are in cluster mode.

@sksamuel
Copy link
Author

I've figured it out. Changing the periodic refresh was the fix, we still had the old value of 30 seconds in another service.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant