From 90a585370cc59a2886f8c353f45b69cc0c349b05 Mon Sep 17 00:00:00 2001 From: Guillaume Boutry Date: Mon, 17 Jun 2024 11:31:47 +0200 Subject: [PATCH] [all] reduce mysql-pooling to sensible defaults Reduce the max_pool_size parameter from default 5 to 2, to reduce the max number of connections each process needs. Reduce connection_recycle_time from 200 to 20, to reduce life duration of a connection, allowing faster recovery in case of failure of a mysql-router. Configure horizon-k8s to persist connections for 20 seconds, and enable connection healthchecks to make sure the connection is usable. Change-Id: Id88d5a8643b8dd2db618e18c8ad556f3e92282ba --- .../barbican-k8s/src/templates/barbican.conf | 3 +- .../src/templates/cinder.conf.j2 | 6 +- .../src/templates/designate.conf.j2 | 2 +- .../src/templates/local_settings.py.j2 | 2 + charms/nova-k8s/src/templates/nova.conf.j2 | 2 +- .../src/templates/placement.conf | 1 + .../tests/unit/test_placement_charm.py | 2 + common.sh | 82 +++++++++++-------- rebuild | 2 +- templates/parts/database-connection-settings | 2 + templates/parts/section-database | 2 +- 11 files changed, 62 insertions(+), 44 deletions(-) create mode 100644 templates/parts/database-connection-settings diff --git a/charms/barbican-k8s/src/templates/barbican.conf b/charms/barbican-k8s/src/templates/barbican.conf index bd76ac38..208a8f42 100644 --- a/charms/barbican-k8s/src/templates/barbican.conf +++ b/charms/barbican-k8s/src/templates/barbican.conf @@ -6,8 +6,7 @@ state_path = /var/lib/barbican host_href = "" transport_url = {{ amqp.transport_url }} -sql_connection = {{ database.connection }} -db_auto_create = false +{% include "parts/section-database" %} {% include "parts/section-identity" %} # XXX Region should come from the id relation here diff --git a/charms/cinder-ceph-k8s/src/templates/cinder.conf.j2 b/charms/cinder-ceph-k8s/src/templates/cinder.conf.j2 index b736915f..189380bf 100644 --- a/charms/cinder-ceph-k8s/src/templates/cinder.conf.j2 +++ b/charms/cinder-ceph-k8s/src/templates/cinder.conf.j2 @@ -25,11 +25,7 @@ cinder_internal_tenant_project_id = {{ identity_credentials.project_id }} cinder_internal_tenant_user_id = {{ identity_credentials.username }} {% endif -%} -[database] -{% if database.connection -%} -connection = {{ database.connection }} -{% endif -%} -connection_recycle_time = 200 +{% include "parts/section-database" %} {% include "parts/section-oslo-notifications" %} diff --git a/charms/designate-k8s/src/templates/designate.conf.j2 b/charms/designate-k8s/src/templates/designate.conf.j2 index 6d32292b..1406ac12 100644 --- a/charms/designate-k8s/src/templates/designate.conf.j2 +++ b/charms/designate-k8s/src/templates/designate.conf.j2 @@ -21,6 +21,6 @@ enabled = True [storage:sqlalchemy] {% include "parts/database-connection" %} -db_auto_create = false +{% include "parts/database-connection-settings" %} {% include "parts/section-oslo-messaging-rabbit" %} diff --git a/charms/horizon-k8s/src/templates/local_settings.py.j2 b/charms/horizon-k8s/src/templates/local_settings.py.j2 index 212c14f6..3ebd179a 100644 --- a/charms/horizon-k8s/src/templates/local_settings.py.j2 +++ b/charms/horizon-k8s/src/templates/local_settings.py.j2 @@ -161,6 +161,8 @@ DATABASES = { 'PASSWORD': '{{ database.database_password }}', 'HOST': '{{ database.database_host.split(':')[0] }}', 'PORT': '{{ database.database_host.split(':')[1] }}', + 'CONN_MAX_AGE': 20, + 'CONN_HEALTH_CHECKS': True, 'default-character-set': 'utf8' } } diff --git a/charms/nova-k8s/src/templates/nova.conf.j2 b/charms/nova-k8s/src/templates/nova.conf.j2 index ce45aa0a..50cf90ce 100644 --- a/charms/nova-k8s/src/templates/nova.conf.j2 +++ b/charms/nova-k8s/src/templates/nova.conf.j2 @@ -11,7 +11,7 @@ connection = {{ api_database.connection }} {% else -%} connection = sqlite:////var/lib/nova/nova_api.sqlite {% endif -%} -connection_recycle_time = 200 +{% include "parts/database-connection-settings" %} {% include "parts/section-database" %} diff --git a/charms/placement-k8s/src/templates/placement.conf b/charms/placement-k8s/src/templates/placement.conf index 771165cf..28f6b8bc 100644 --- a/charms/placement-k8s/src/templates/placement.conf +++ b/charms/placement-k8s/src/templates/placement.conf @@ -6,6 +6,7 @@ auth_strategy = keystone [placement_database] {% include "parts/database-connection" %} +{% include "parts/database-connection-settings" %} {% include "parts/section-identity" %} diff --git a/charms/placement-k8s/tests/unit/test_placement_charm.py b/charms/placement-k8s/tests/unit/test_placement_charm.py index 5f8863ff..52a1c259 100644 --- a/charms/placement-k8s/tests/unit/test_placement_charm.py +++ b/charms/placement-k8s/tests/unit/test_placement_charm.py @@ -115,6 +115,8 @@ class TestPlacementOperatorCharm(test_utils.CharmTestCase): [placement_database] connection = mysql+pymysql://foo:hardpassword@10.0.0.10/placement_api + connection_recycle_time = 20 + max_pool_size = 2 [keystone_authtoken] auth_url = http://keystone.internal:5000 diff --git a/common.sh b/common.sh index 2587471e..ecd7134f 100644 --- a/common.sh +++ b/common.sh @@ -190,6 +190,7 @@ EXTERNAL_TEMPEST_LIBS=( CONFIG_TEMPLATES_AODH=( "parts/section-database" "parts/database-connection" + "parts/database-connection-settings" "parts/section-identity" "parts/identity-data" "parts/section-oslo-messaging-rabbit" @@ -198,10 +199,13 @@ CONFIG_TEMPLATES_AODH=( ) CONFIG_TEMPLATES_BARBICAN=( - "parts/section-identity" + "parts/section-database" + "parts/database-connection" + "parts/database-connection-settings" + "parts/section-identity" "parts/identity-data" - "parts/section-oslo-messaging-rabbit" - "parts/section-service-user" + "parts/section-oslo-messaging-rabbit" + "parts/section-service-user" "ca-bundle.pem.j2" ) @@ -213,54 +217,61 @@ CONFIG_TEMPLATES_CEILOMETER=( ) CONFIG_TEMPLATES_CINDER=( - "parts/section-database" + "parts/section-database" "parts/database-connection" - "parts/section-identity" + "parts/database-connection-settings" + "parts/section-identity" "parts/identity-data" - "parts/section-oslo-messaging-rabbit" - "parts/section-service-user" + "parts/section-oslo-messaging-rabbit" + "parts/section-service-user" "ca-bundle.pem.j2" ) CONFIG_TEMPLATES_CINDER_CEPH=( + "parts/section-database" + "parts/database-connection" + "parts/database-connection-settings" "parts/section-oslo-messaging-rabbit" "parts/section-oslo-notifications" ) CONFIG_TEMPLATES_DESIGNATE=( "parts/database-connection" + "parts/database-connection-settings" "parts/section-identity" "parts/identity-data" "parts/section-oslo-messaging-rabbit" - "parts/section-service-user" + "parts/section-service-user" "ca-bundle.pem.j2" ) CONFIG_TEMPLATES_GLANCE=( "parts/section-database" "parts/database-connection" + "parts/database-connection-settings" "parts/section-identity" - "parts/identity-data" + "parts/identity-data" "parts/section-oslo-messaging-rabbit" - "parts/section-oslo-notifications" + "parts/section-oslo-notifications" "parts/section-service-user" "ca-bundle.pem.j2" ) CONFIG_TEMPLATES_GNOCCHI=( - "parts/database-connection" - "parts/section-identity" - "parts/identity-data" + "parts/database-connection" + "parts/section-identity" + "parts/identity-data" "ca-bundle.pem.j2" ) CONFIG_TEMPLATES_HEAT=( - "parts/section-database" - "parts/database-connection" - "parts/section-identity" - "parts/identity-data" + "parts/section-database" + "parts/database-connection" + "parts/database-connection-settings" + "parts/section-identity" + "parts/identity-data" "parts/section-trustee" - "parts/section-oslo-messaging-rabbit" + "parts/section-oslo-messaging-rabbit" "ca-bundle.pem.j2" ) @@ -271,6 +282,7 @@ CONFIG_TEMPLATES_HORIZON=( CONFIG_TEMPLATES_KEYSTONE=( "parts/section-database" "parts/database-connection" + "parts/database-connection-settings" "parts/section-federation" "parts/section-middleware" "parts/section-oslo-cache" @@ -283,8 +295,9 @@ CONFIG_TEMPLATES_KEYSTONE=( CONFIG_TEMPLATES_MAGNUM=( "parts/section-database" "parts/database-connection" + "parts/database-connection-settings" "parts/section-identity" - "parts/identity-data" + "parts/identity-data" "parts/section-oslo-messaging-rabbit" "parts/section-service-user" "parts/section-trust" @@ -292,30 +305,33 @@ CONFIG_TEMPLATES_MAGNUM=( ) CONFIG_TEMPLATES_NEUTRON=( - "parts/section-database" - "parts/database-connection" - "parts/section-identity" - "parts/identity-data" - "parts/section-oslo-messaging-rabbit" - "parts/section-service-user" + "parts/section-database" + "parts/database-connection" + "parts/database-connection-settings" + "parts/section-identity" + "parts/identity-data" + "parts/section-oslo-messaging-rabbit" + "parts/section-service-user" "ca-bundle.pem.j2" ) CONFIG_TEMPLATES_NOVA=${CONFIG_TEMPLATES_NEUTRON[@]} CONFIG_TEMPLATES_OCTAVIA=( - "parts/section-database" - "parts/database-connection" - "parts/section-identity" - "parts/identity-data" + "parts/section-database" + "parts/database-connection" + "parts/database-connection-settings" + "parts/section-identity" + "parts/identity-data" "ca-bundle.pem.j2" ) CONFIG_TEMPLATES_PLACEMENT=( - "parts/database-connection" - "parts/section-identity" - "parts/identity-data" - "parts/section-service-user" + "parts/database-connection" + "parts/database-connection-settings" + "parts/section-identity" + "parts/identity-data" + "parts/section-service-user" "ca-bundle.pem.j2" ) diff --git a/rebuild b/rebuild index 3f1be42d..14c25454 100644 --- a/rebuild +++ b/rebuild @@ -1,3 +1,3 @@ # This file is used to trigger a build. # Change uuid to trigger a new build on every charms. -4a66cd5b-4da4-433b-a38d-564df526c15d +03381028-42a3-4a2d-9231-7a2642ede8c7 diff --git a/templates/parts/database-connection-settings b/templates/parts/database-connection-settings new file mode 100644 index 00000000..f30b571c --- /dev/null +++ b/templates/parts/database-connection-settings @@ -0,0 +1,2 @@ +connection_recycle_time = 20 +max_pool_size = 2 diff --git a/templates/parts/section-database b/templates/parts/section-database index 986d9b10..c2e7265a 100644 --- a/templates/parts/section-database +++ b/templates/parts/section-database @@ -1,3 +1,3 @@ [database] {% include "parts/database-connection" %} -connection_recycle_time = 200 +{% include "parts/database-connection-settings" %}