From 30ed419a09586cf1349c3a67985690b12d26a8b8 Mon Sep 17 00:00:00 2001 From: Marco Donadoni Date: Tue, 6 Aug 2024 16:41:26 +0200 Subject: [PATCH] perf(config): make closing of database connections optional (#463) Closes reanahub/reana#819 --- reana_job_controller/config.py | 6 ++++++ reana_job_controller/factory.py | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/reana_job_controller/config.py b/reana_job_controller/config.py index e1bc02bb..0774e5e2 100644 --- a/reana_job_controller/config.py +++ b/reana_job_controller/config.py @@ -8,12 +8,18 @@ """Flask application configuration.""" +from distutils.util import strtobool import os from reana_commons.config import REANA_COMPONENT_PREFIX from werkzeug.utils import import_string +REANA_DB_CLOSE_POOL_CONNECTIONS = bool( + strtobool(os.getenv("REANA_DB_CLOSE_POOL_CONNECTIONS", "false")) +) +"""Determine whether to close each database connection when it is returned to the pool.""" + CACHE_ENABLED = False """Determines if jobs caching is enabled.""" diff --git a/reana_job_controller/factory.py b/reana_job_controller/factory.py index 82694734..87557203 100644 --- a/reana_job_controller/factory.py +++ b/reana_job_controller/factory.py @@ -36,7 +36,8 @@ def receive_checkin(dbapi_connection, connection_record): # To improve scalability, we should consider refactoring job-controller to avoid # accessing the database, or at least consider using external connection pooling # mechanisms such as pgBouncer. - connection_record.close() + if config.REANA_DB_CLOSE_POOL_CONNECTIONS: + connection_record.close() def shutdown_session(response_or_exc):