From fbaeb90268c82045afb0c408e1c374818a6c2649 Mon Sep 17 00:00:00 2001 From: Alan Rominger Date: Thu, 1 Jun 2023 14:59:18 -0400 Subject: [PATCH] Apply conservative database connection reduction changes (#14066) This is expected to free up 4 additional database connections per traditional node compare to roughly 12 in total before this change Out of these 3 are accomplished by using existing connection for recently added services then 1 is obtained by closing the connection for the idle callback receiver main process Signed-off-by: jessicamack Co-authored-by: jessicamack --- awx/main/dispatch/worker/base.py | 3 ++- awx/main/management/commands/run_cache_clear.py | 3 ++- awx/main/management/commands/run_rsyslog_configurer.py | 2 +- awx/main/management/commands/run_ws_heartbeat.py | 6 +++--- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/awx/main/dispatch/worker/base.py b/awx/main/dispatch/worker/base.py index c10564f6dd..bc2c0a043b 100644 --- a/awx/main/dispatch/worker/base.py +++ b/awx/main/dispatch/worker/base.py @@ -143,9 +143,10 @@ class AWXConsumerRedis(AWXConsumerBase): def run(self, *args, **kwargs): super(AWXConsumerRedis, self).run(*args, **kwargs) self.worker.on_start() + logger.info(f'Callback receiver started with pid={os.getpid()}') + db.connection.close() # logs use database, so close connection while True: - logger.debug(f'{os.getpid()} is alive') time.sleep(60) diff --git a/awx/main/management/commands/run_cache_clear.py b/awx/main/management/commands/run_cache_clear.py index 61e4b03c49..bba9cd8f68 100644 --- a/awx/main/management/commands/run_cache_clear.py +++ b/awx/main/management/commands/run_cache_clear.py @@ -2,6 +2,7 @@ import logging import json from django.core.management.base import BaseCommand + from awx.main.dispatch import pg_bus_conn from awx.main.dispatch.worker.task import TaskWorker @@ -18,7 +19,7 @@ class Command(BaseCommand): def handle(self, *arg, **options): try: - with pg_bus_conn(new_connection=True) as conn: + with pg_bus_conn() as conn: conn.listen("tower_settings_change") for e in conn.events(yield_timeouts=True): if e is not None: diff --git a/awx/main/management/commands/run_rsyslog_configurer.py b/awx/main/management/commands/run_rsyslog_configurer.py index 61e7aa14a6..bc68370987 100644 --- a/awx/main/management/commands/run_rsyslog_configurer.py +++ b/awx/main/management/commands/run_rsyslog_configurer.py @@ -22,7 +22,7 @@ class Command(BaseCommand): def handle(self, *arg, **options): try: - with pg_bus_conn(new_connection=True) as conn: + with pg_bus_conn() as conn: conn.listen("rsyslog_configurer") # reconfigure rsyslog on start up reconfigure_rsyslog() diff --git a/awx/main/management/commands/run_ws_heartbeat.py b/awx/main/management/commands/run_ws_heartbeat.py index e7f08b1d89..1cb4c8d028 100644 --- a/awx/main/management/commands/run_ws_heartbeat.py +++ b/awx/main/management/commands/run_ws_heartbeat.py @@ -30,11 +30,11 @@ class Command(BaseCommand): sys.exit(0) def do_hearbeat_loop(self): - with pg_bus_conn(new_connection=True) as conn: - while True: + while True: + with pg_bus_conn() as conn: logger.debug('Sending heartbeat') conn.notify('web_ws_heartbeat', self.construct_payload()) - time.sleep(settings.BROADCAST_WEBSOCKET_BEACON_FROM_WEB_RATE_SECONDS) + time.sleep(settings.BROADCAST_WEBSOCKET_BEACON_FROM_WEB_RATE_SECONDS) def handle(self, *arg, **options): signal.signal(signal.SIGTERM, self.notify_listener_and_exit)