File tree Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,10 @@ Environment variables
24
24
| ` TENANT_HEADER ` | ` <empty> ` | The name of the HTTP header which contains the tenant name for multi-tenant setups. |
25
25
| ` TENANT_PATH_PREFIX ` | ` @service_prefix@/@tenant@ ` | URL path prefix for all QWC services for multi-tenant setups. |
26
26
| ` TENANT_ACCESS_COOKIE_PATH ` | ` <tenant_path_prefix> ` | Path for which the access cookie is valid for multi-tenant setups. |
27
+ | ` POOL_SIZE ` | ` 5 ` | Maximum number of possible data base connections. |
28
+ | ` MAX_OVERFLOW ` | ` 10 ` | Additional connections beyond pool_size during peak load. |
29
+ | ` POOL_TIMEOUT ` | ` 30 ` | Time (in seconds) to wait for a connection to become available. |
30
+ | ` POOL_RECYCLE ` | ` -1 ` | Time (in seconds) after idle connections will be resetted. |
27
31
28
32
Development
29
33
===========
Original file line number Diff line number Diff line change 1
1
import os
2
2
3
3
from sqlalchemy import create_engine
4
-
4
+ from sqlalchemy . pool import QueuePool
5
5
6
6
class DatabaseEngine ():
7
7
"""Helper for database connections using SQLAlchemy engines"""
@@ -15,12 +15,24 @@ def db_engine(self, conn_str):
15
15
16
16
:param str conn_str: DB connection string for SQLAlchemy engine
17
17
18
- see http ://docs.sqlalchemy.org/en/latest/core/engines.html#postgresql
18
+ see https ://docs.sqlalchemy.org/en/latest/core/engines.html#postgresql
19
19
"""
20
+
21
+ db_pool_size = os .environ .get ('POOL_SIZE' , 5 )
22
+ db_max_overflow = os .environ .get ('MAX_OVERFLOW' , 10 )
23
+ db_pool_timeout = os .environ .get ('POOL_TIMEOUT' , 30 )
24
+ db_pool_recycle = os .environ .get ('POOL_RECYCLE' , - 1 )
25
+
20
26
engine = self .engines .get (conn_str )
21
27
if not engine :
22
28
engine = create_engine (
23
- conn_str , pool_pre_ping = True , echo = False )
29
+ conn_str ,
30
+ poolclass = QueuePool ,
31
+ pool_size = db_pool_size ,
32
+ max_overflow = db_max_overflow ,
33
+ pool_timeout = db_pool_timeout ,
34
+ pool_recycle = db_pool_recycle ,
35
+ pool_pre_ping = True , echo = False )
24
36
self .engines [conn_str ] = engine
25
37
return engine
26
38
You can’t perform that action at this time.
0 commit comments