Skip to content

Commit

Permalink
Merge pull request #887 from lsst-sqre/tickets/DM-41424
Browse files Browse the repository at this point in the history
DM-41424: Improve Redis pool configuration
  • Loading branch information
rra authored Oct 27, 2023
2 parents 011d93f + f14d1e0 commit 32384ca
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
3 changes: 3 additions & 0 deletions changelog.d/20231027_101349_rra_DM_41424.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Bug fixes

- Add a socket timeout, enable keepalive, and fix the retry specification for the Redis connection pool to help Gafaelfawr recover from Redis outages.
6 changes: 5 additions & 1 deletion src/gafaelfawr/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"REDIS_POOL_SIZE",
"REDIS_POOL_TIMEOUT",
"REDIS_RETRIES",
"REDIS_TIMEOUT",
"SCOPE_REGEX",
"TOKEN_CACHE_SIZE",
"UID_BOT_MIN",
Expand Down Expand Up @@ -117,7 +118,10 @@
"""Size of the Redis connection pool."""

REDIS_POOL_TIMEOUT = 10
"""How long to wait for a connection from the pool before giving up."""
"""Seconds to wait for a connection from the pool before giving up."""

REDIS_TIMEOUT = 5
"""Timeout in seconds for a Redis network operation (including connecting)."""

# The following constants define per-process cache sizes.

Expand Down
15 changes: 9 additions & 6 deletions src/gafaelfawr/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
REDIS_POOL_SIZE,
REDIS_POOL_TIMEOUT,
REDIS_RETRIES,
REDIS_TIMEOUT,
)
from .exceptions import NotConfiguredError
from .models.ldap import LDAPUserData
Expand Down Expand Up @@ -142,13 +143,15 @@ async def from_config(cls, config: Config) -> Self:
config.redis_url,
password=config.redis_password,
max_connections=REDIS_POOL_SIZE,
timeout=REDIS_POOL_TIMEOUT,
),
retry=Retry(
ExponentialBackoff(
base=REDIS_BACKOFF_START, cap=REDIS_BACKOFF_MAX
retry=Retry(
ExponentialBackoff(
base=REDIS_BACKOFF_START, cap=REDIS_BACKOFF_MAX
),
REDIS_RETRIES,
),
REDIS_RETRIES,
socket_keepalive=True,
socket_timeout=REDIS_TIMEOUT,
timeout=REDIS_POOL_TIMEOUT,
),
)

Expand Down

0 comments on commit 32384ca

Please sign in to comment.