diff --git a/compose/production/django/entrypoint b/compose/production/django/entrypoint index 599841ed..dd8fc324 100755 --- a/compose/production/django/entrypoint +++ b/compose/production/django/entrypoint @@ -7,7 +7,7 @@ set -o nounset # N.B. If only .env files supported variable expansion... -export CELERY_BROKER_URL="${REDIS_URL}" +export CELERY_BROKER_URL="${CELERY_BROKER_URL:-${REDIS_URL}}" if [ -z "${POSTGRES_USER}" ]; then diff --git a/config/settings/base.py b/config/settings/base.py index b42087fc..0e3bbff6 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -490,6 +490,11 @@ CELERY_BROKER_URL = env("CELERY_BROKER_URL") # http://docs.celeryproject.org/en/latest/userguide/configuration.html#std:setting-result_backend CELERY_RESULT_BACKEND = CELERY_BROKER_URL +# Redis broker/backend connection pools are per process. Keep them bounded so +# web, worker, beat and monitoring replicas cannot accumulate thousands of idle +# sockets after traffic or pod churn. +CELERY_BROKER_POOL_LIMIT = env.int("CELERY_BROKER_POOL_LIMIT", default=5) +CELERY_REDIS_MAX_CONNECTIONS = env.int("CELERY_REDIS_MAX_CONNECTIONS", default=20) # http://docs.celeryproject.org/en/latest/userguide/configuration.html#std:setting-accept_content CELERY_ACCEPT_CONTENT = ["json"] # http://docs.celeryproject.org/en/latest/userguide/configuration.html#std:setting-task_serializer @@ -721,4 +726,4 @@ # LINK TO OLD SCIELO -SCIELO_OLD_URL = env.str("SCIELO_OLD_URL", default="http://old.scielo.org/") \ No newline at end of file +SCIELO_OLD_URL = env.str("SCIELO_OLD_URL", default="http://old.scielo.org/") diff --git a/config/settings/local.py b/config/settings/local.py index 77f7fdbd..8c0bd947 100755 --- a/config/settings/local.py +++ b/config/settings/local.py @@ -22,6 +22,18 @@ "LOCATION": "redis://redis:6379", "OPTIONS": { "CLIENT_CLASS": "django_redis.client.DefaultClient", + "CONNECTION_POOL_CLASS": "redis.BlockingConnectionPool", + "CONNECTION_POOL_KWARGS": { + "max_connections": env.int("REDIS_CACHE_MAX_CONNECTIONS", default=20), + "timeout": env.int("REDIS_CACHE_POOL_TIMEOUT", default=2), + "health_check_interval": env.int( + "REDIS_HEALTH_CHECK_INTERVAL", default=30 + ), + }, + "SOCKET_CONNECT_TIMEOUT": env.int( + "REDIS_SOCKET_CONNECT_TIMEOUT", default=2 + ), + "SOCKET_TIMEOUT": env.int("REDIS_SOCKET_TIMEOUT", default=2), } } } diff --git a/config/settings/production.py b/config/settings/production.py index ab0e4875..785b21b5 100755 --- a/config/settings/production.py +++ b/config/settings/production.py @@ -30,6 +30,18 @@ "LOCATION": env("REDIS_URL"), "OPTIONS": { "CLIENT_CLASS": "django_redis.client.DefaultClient", + "CONNECTION_POOL_CLASS": "redis.BlockingConnectionPool", + "CONNECTION_POOL_KWARGS": { + "max_connections": env.int("REDIS_CACHE_MAX_CONNECTIONS", default=20), + "timeout": env.int("REDIS_CACHE_POOL_TIMEOUT", default=2), + "health_check_interval": env.int( + "REDIS_HEALTH_CHECK_INTERVAL", default=30 + ), + }, + "SOCKET_CONNECT_TIMEOUT": env.int( + "REDIS_SOCKET_CONNECT_TIMEOUT", default=2 + ), + "SOCKET_TIMEOUT": env.int("REDIS_SOCKET_TIMEOUT", default=2), # Mimicing memcache behavior. # https://github.com/jazzband/django-redis#memcached-exceptions-behavior "IGNORE_EXCEPTIONS": True,