From ee5bd41a372d32fb0fa53a394ad7343123aec382 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20T=C3=B6lle?= Date: Sat, 11 Jun 2022 18:47:04 +0200 Subject: [PATCH] feat(api): configurable max pool connections This should help with failing health checks while the crawler is running. Quick math: 10 users, 30 songs each, each song requires at least 3 queries => 900 db queries every minute. With the default of 10 pool connections, this blocks all available db bandwidth for some time and causes slow UI and failing healthchecks. --- README.md | 1 + charts/listory/templates/deployment.yaml | 2 ++ charts/listory/values.yaml | 3 +++ src/config/config.module.ts | 1 + src/database/database.module.ts | 5 +++++ 5 files changed, 12 insertions(+) diff --git a/README.md b/README.md index 8e6ec6d..334ef14 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ All configuration must be set as environment variables. Default values are added - `DB_USERNAME`: _Required_, Database username - `DB_PASSWORD`: _Required_, Database password - `DB_DATABASE`: _Required_, Database database +- `DB_POOL_MAX`: **50**, max concurrent database connections #### Sentry diff --git a/charts/listory/templates/deployment.yaml b/charts/listory/templates/deployment.yaml index 695ceae..9835b33 100644 --- a/charts/listory/templates/deployment.yaml +++ b/charts/listory/templates/deployment.yaml @@ -37,6 +37,8 @@ spec: key: postgres-password - name: DB_DATABASE value: {{ .Values.externalDatabase.database }} + - name: DB_POOL_MAX + value: "{{ .Values.database.poolMax }}" - name: JWT_SECRET valueFrom: secretKeyRef: diff --git a/charts/listory/values.yaml b/charts/listory/values.yaml index fe16650..89c05e1 100644 --- a/charts/listory/values.yaml +++ b/charts/listory/values.yaml @@ -75,6 +75,9 @@ externalDatabase: password: database: +database: + poolMax: 50 + spotify: clientId: clientSecret: diff --git a/src/config/config.module.ts b/src/config/config.module.ts index 69a9b40..20cb1d6 100644 --- a/src/config/config.module.ts +++ b/src/config/config.module.ts @@ -36,6 +36,7 @@ import { ConfigModule as NestConfigModule } from "@nestjs/config"; DB_USERNAME: Joi.string().required(), DB_PASSWORD: Joi.string().required(), DB_DATABASE: Joi.string().required(), + DB_POOL_MAX: Joi.number().default(50), // Sentry (Optional) SENTRY_ENABLED: Joi.boolean().default(false), diff --git a/src/database/database.module.ts b/src/database/database.module.ts index 0ed79a6..06ac587 100644 --- a/src/database/database.module.ts +++ b/src/database/database.module.ts @@ -20,6 +20,11 @@ export const DatabaseModule = TypeOrmModule.forRootAsync({ migrationsRun: true, migrations: [join(__dirname, "migrations", "*.{ts,js}")], + // PG Driver Options + extra: { + max: config.get("DB_POOL_MAX"), + }, + // Debug/Development Options // // logging: true,