Enhance database connection pool configuration with timeout settings#383
Open
Ahmedscreativeverse wants to merge 1 commit intoEarnQuestOne:mainfrom
Open
Enhance database connection pool configuration with timeout settings#383Ahmedscreativeverse wants to merge 1 commit intoEarnQuestOne:mainfrom
Ahmedscreativeverse wants to merge 1 commit intoEarnQuestOne:mainfrom
Conversation
|
@Ahmedscreativeverse Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Contributor
|
Kindly resolve conflict |
Author
|
Conflict resolved |
Contributor
|
Not yet resolved. kindly recheck |
Contributor
|
Kindly resolve conflict. If you do, you can still earn your points. Before the 7days review period. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #343
What changed?
src/database/data-source.ts— addedextrapool config block (previously absent entirely); pool values now read from env vars with safe defaultssrc/config/ormconfig.ts— replaced hardcodedmax: 10and fixed timeout values with the same env-driven patternsrc/modules/health/services/database-pool-monitor.service.ts— fixedgetPoolConfig()to resolve values from env vars so/health/poolreports the actual configured values instead of falling back to hardcoded literals.env.example— addedDB_POOL_MAX,DB_POOL_MIN,DB_POOL_CONNECTION_TIMEOUT,DB_POOL_IDLE_TIMEOUTwith documented defaultsWhy was it changed?
The pool size and timeouts were hardcoded, making it impossible to tune for production without a code change. More critically,
data-source.ts— the config actually used byapp.module.tsat runtime — had no pool configuration at all, meaning TypeORM was running with pg's default pool (max 10, no idle timeout tuning). This is the root cause of the performance issue described in #40.How was it implemented?
All four pool settings are now read via
parseInt(process.env.VAR ?? 'default', 10)in bothdata-source.tsandormconfig.ts. TheDatabasePoolMonitorService.getPoolConfig()method was updated to use??with the same env var fallbacks so the monitoring endpoint stays accurate. No new dependencies were introduced.Type of Change
Test Evidence
Unit Tests
npm run test)npm run test:cov)Test output / screenshot:
E2E / Integration Tests
npm run test:e2e)Endpoints tested:
GET/health/poolmaxGET/health/metricsdb_pool_utilization_percentreflects correct maxGET/healthSwagger / API Documentation
Error Handling Checklist
HTTP Exceptions
Input Validation (DTOs)
Guards & Authorization
Logging
Stellar / Soroban Contract Interactions
Database / Migration
Final Pre-Merge Checklist
main/masternpm run lint)npm run format)console.log/ debug statements left in production code.env.exampleupdated with the four new pool environment variablesReadMe Backend.mdalready references/health/poolandDATABASE_POOL_MONITORING.md— no further update neededScreenshots / Recordings (if applicable)
GET /health/poolresponse withDB_POOL_MAX=20set in env:{ "stats": { "totalConnections": 4, "activeConnections": 2, "idleConnections": 2, "waitingRequests": 0 }, "config": { "max": 20, "min": 2, "connectionTimeoutMillis": 10000, "idleTimeoutMillis": 30000 }, "utilization": 20.0, "averageAcquisitionTime": 11.3 }Additional Notes for Reviewer
DB_POOL_MAX=10,DB_POOL_MIN=2) preserve existing behaviour for anyone who does not set the new vars, so this is a non-breaking change.GET /health/poolunder load, then adjustDB_POOL_MAX(and optionallyDB_POOL_MIN) in the deployment env and restart — no redeploy of code needed.DB_POOL_MIN=2keeps two warm connections alive at idle, reducing cold-start latency on the first requests after a quiet period.DATABASE_POOL_MONITORING.mdunder Scaling Recommendations).