Skip to content

Commit

Permalink
Merge pull request #1224 from lsst-sqre:tickets/DM-48495
Browse files Browse the repository at this point in the history
DM-48495: Tweak Redis connection pool settings
  • Loading branch information
rra authored Jan 22, 2025
2 parents 2504ca8 + 60acc89 commit 70c4043
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
14 changes: 11 additions & 3 deletions src/gafaelfawr/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
"OIDC_AUTHORIZATION_LIFETIME",
"REDIS_BACKOFF_MAX",
"REDIS_BACKOFF_START",
"REDIS_POOL_SIZE",
"REDIS_EPHEMERAL_POOL_SIZE",
"REDIS_PERSISTENT_POOL_SIZE",
"REDIS_POOL_TIMEOUT",
"REDIS_RATE_LIMIT_POOL_SIZE",
"REDIS_RETRIES",
"REDIS_TIMEOUT",
"SCOPE_REGEX",
Expand Down Expand Up @@ -141,8 +143,14 @@
REDIS_RETRIES = 10
"""How many times to try to connect to Redis before giving up."""

REDIS_POOL_SIZE = 25
"""Size of the Redis connection pool."""
REDIS_EPHEMERAL_POOL_SIZE = 5
"""Size of the ephemeral Redis connection pool (without rate limiting.)"""

REDIS_PERSISTENT_POOL_SIZE = 25
"""Size of the persistent Redis connection pool."""

REDIS_RATE_LIMIT_POOL_SIZE = 25
"""Size of the rate limiting Redis connection pool."""

REDIS_POOL_TIMEOUT = 30
"""Seconds to wait for a connection from the pool before giving up."""
Expand Down
15 changes: 11 additions & 4 deletions src/gafaelfawr/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
from .constants import (
REDIS_BACKOFF_MAX,
REDIS_BACKOFF_START,
REDIS_POOL_SIZE,
REDIS_EPHEMERAL_POOL_SIZE,
REDIS_PERSISTENT_POOL_SIZE,
REDIS_POOL_TIMEOUT,
REDIS_RATE_LIMIT_POOL_SIZE,
REDIS_RETRIES,
REDIS_TIMEOUT,
)
Expand Down Expand Up @@ -167,19 +169,24 @@ async def from_config(cls, config: Config) -> Self:
ephemeral_redis_pool = BlockingConnectionPool.from_url(
str(config.redis_ephemeral_url),
password=redis_password,
max_connections=REDIS_POOL_SIZE,
max_connections=REDIS_EPHEMERAL_POOL_SIZE,
retry=Retry(backoff, REDIS_RETRIES),
retry_on_timeout=True,
socket_keepalive=True,
socket_timeout=REDIS_TIMEOUT,
timeout=REDIS_POOL_TIMEOUT,
)
ephemeral_redis_client = Redis.from_pool(ephemeral_redis_pool)
rate_limiter_storage = RedisStorage(config.redis_rate_limit_url)
rate_limiter_storage = RedisStorage(
config.redis_rate_limit_url,
max_connections=REDIS_RATE_LIMIT_POOL_SIZE,
stream_timeout=REDIS_TIMEOUT,
connect_timeout=REDIS_TIMEOUT,
)
persistent_redis_pool = BlockingConnectionPool.from_url(
str(config.redis_persistent_url),
password=redis_password,
max_connections=REDIS_POOL_SIZE,
max_connections=REDIS_PERSISTENT_POOL_SIZE,
retry=Retry(backoff, REDIS_RETRIES),
retry_on_timeout=True,
socket_keepalive=True,
Expand Down

0 comments on commit 70c4043

Please sign in to comment.