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.
This commit is contained in:
Julian Tölle 2022-06-11 18:47:04 +02:00
parent 7de5e14d4e
commit ee5bd41a37
5 changed files with 12 additions and 0 deletions

View file

@ -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

View file

@ -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:

View file

@ -75,6 +75,9 @@ externalDatabase:
password:
database:
database:
poolMax: 50
spotify:
clientId:
clientSecret:

View file

@ -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),

View file

@ -20,6 +20,11 @@ export const DatabaseModule = TypeOrmModule.forRootAsync({
migrationsRun: true,
migrations: [join(__dirname, "migrations", "*.{ts,js}")],
// PG Driver Options
extra: {
max: config.get<number>("DB_POOL_MAX"),
},
// Debug/Development Options
//
// logging: true,