worldbank / DECAT_Space2Stats

https://worldbank.github.io/DECAT_Space2Stats/
Other
1 stars 2 forks source link

Improve Database Connection Management with Connection Pooling #26

Closed zacharyDez closed 2 months ago

zacharyDez commented 2 months ago

Currently, our application establishes a new database connection for each query, which can lead to performance bottlenecks and increased latency under heavy load. To address this, I propose implementing a connection pool using psycopg’s ConnectionPool in the db_utils.py module. This change will centralize connection management, allowing the application to reuse database connections across queries, thereby reducing the overhead of establishing connections repeatedly. The connection pool will be initialized once during application startup and shared across all database interactions. This design aims to enhance performance, reliability, and scalability while simplifying the codebase by maintaining connection logic in one place.

@alukach, does this match the design discussed yesterday?