Skip to content

feat(pool): add ConnMaxLifetimeJitter to prevent connection thundering herd#3666

Merged
ndyakov merged 3 commits into
redis:masterfrom
cyningsun:feat/conn_max_lifetime_jitter
Jan 15, 2026
Merged

feat(pool): add ConnMaxLifetimeJitter to prevent connection thundering herd#3666
ndyakov merged 3 commits into
redis:masterfrom
cyningsun:feat/conn_max_lifetime_jitter

Conversation

@cyningsun

Copy link
Copy Markdown
Contributor

Summary

Adds ConnMaxLifetimeJitter configuration to distribute connection expiration times and prevent the thundering herd problem when many connections expire simultaneously.

Changes

  • Added ConnMaxLifetimeJitter time.Duration to all client options (Client, Sentinel, Ring, Universal, Cluster)
  • Implemented calcConnExpiresAt() method that applies random jitter in range [-jitter, +jitter]
  • Added URL parameter support: conn_max_lifetime_jitter
  • Jitter is automatically capped at ConnMaxLifetime value

Usage

// Programmatic
client := redis.NewClient(&redis.Options{
    Addr:                  "localhost:6379",
    ConnMaxLifetime:       1 * time.Hour,
    ConnMaxLifetimeJitter: 5 * time.Minute,
})

// URL
opt, _ := redis.ParseURL("redis://localhost:6379/?conn_max_lifetime=1h&conn_max_lifetime_jitter=5m")

@ndyakov

ndyakov commented Jan 12, 2026

Copy link
Copy Markdown
Member

Hello @cyningsun and thank you for this contribution, i will review around end of week, will this work for you?

@cyningsun

Copy link
Copy Markdown
Contributor Author

Absolutely, that works for me. Thank you for the update.

@ndyakov ndyakov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cyningsun thank you, I like the refactoring for calculation the connection expiry. Nice and clean code 👌

@ndyakov ndyakov merged commit 1bf873e into redis:master Jan 15, 2026
33 checks passed
ndyakov pushed a commit that referenced this pull request Jan 24, 2026
…g herd (#3666)

* add connection max lifetime jitter

* refactor calcConnExpiresAt
ndyakov pushed a commit that referenced this pull request Jan 24, 2026
…g herd (#3666)

* add connection max lifetime jitter

* refactor calcConnExpiresAt
mwhooker added a commit to mwhooker/go-redis that referenced this pull request Feb 9, 2026
…g herd (redis#3666)

* add connection max lifetime jitter

* refactor calcConnExpiresAt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants