Package: django-db-connection-pool
django-db-connection-pool:star: Leave a star if django-db-connection-pool is helpful to you, or you like it, Thank you:smile:MySQL & Oracle & PostgreSQL & JDBC (Oracle, OceanBase) connection pool backends of Django,
Be based onSQLAlchemy.
Work fine in multiprocessing and multithreading django project.中文版QuickstartInstallationInstall withpipwith all engines:$pipinstalldjango-db-connection-pool[all]or select specific engines:$pipinstalldjango-db-connection-pool[mysql,oracle,postgresql,jdbc]or one of mysql,oracle,postgresql,jdbc$pipinstalldjango-db-connection-pool[oracle]Update settings.DATABASESMySQLchangedjango.db.backends.mysqltodj_db_conn_pool.backends.mysql:DATABASES={'default':{'ENGINE':'dj_db_conn_pool.backends.mysql'}}Oraclechangedjango.db.backends.oracletodj_db_conn_pool.backends.oracle:DATABASES={'default':{'ENGINE':'dj_db_conn_pool.backends.oracle'}}PostgreSQLchangedjango.db.backends.postgresqltodj_db_conn_pool.backends.postgresql:DATABASES={'default':{'ENGINE':'dj_db_conn_pool.backends.postgresql'}}Pool options(optional)you can provide additional options to pass to SQLAlchemy's pool creation, key's name isPOOL_OPTIONS:DATABASES={'default':{'POOL_OPTIONS':{'POOL_SIZE':10,'MAX_OVERFLOW':10,'RECYCLE':24*60*60}}}django-db-connection-poolhas more configuration options here:PoolContainer.pool_default_paramsHere's an explanation of these options(from SQLAlchemy's Doc):pool_size: The size of the pool to be maintained,
defaults to 5. This is the largest number of connections that
will be kept persistently in the pool. Note that the pool
begins with no connections; once this number of connections
is requested, that number of connections will remain.pool_sizecan be set to 0 to indicate no size limit; to
disable pooling, use a :class:~sqlalchemy.pool.NullPoolinstead.max_overflow: The maximum overflow size of the
pool. When the number of checked-out connections reaches the
size set in pool_size, additional connections will be
returned up to this limit. When those additional connections
are returned to the pool, they are disconnected and
discarded. It follows then that the total number of
simultaneous connections the pool will allow is pool_size +max_overflow, and the total number of "sleeping"
connections the pool will allow is pool_size.max_overflowcan be set to -1 to indicate no overflow limit; no limit
will be placed on the total number of concurrent
connections. Defaults to 10.recycle: If set to a value other than -1, number of seconds
between connection recycling, which means upon checkout,
if this timeout is surpassed the connection will be closed
and replaced with a newly opened connection.
Defaults to -1.Or, you can use dj_db_conn_pool.setup to change default arguments(for each pool's creation), before using database pool:importdj_db_conn_pooldj_db_conn_pool.setup(pool_size=100,max_overflow=50)multiprocessing environmentIn a multiprocessing environment, such as uWSGI, each process will have its owndj_db_conn_pool.core:pool_containerobject,
It means that each process has an independent connection pool, for example:
ThePOOL_OPTIONSconfiguration of databasedb1is{ 'POOL_SIZE': 10, 'MAX_OVERFLOW': 20 },
If uWSGI starts 8 worker processes, then the total connection pool size ofdb1is8 * 10,
The maximum number of connections will not exceed8 * 10 + 8 * 20JDBC (experimental, NOT PRODUCTION READY)Thanks toJPype,
django-db-connection-pool can connect to database in jdbc wayUsageSet Java runtime environmentexportJAVA_HOME=$PATH_TO_JRE;exportCLASSPATH=$PATH_RO_JDBC_DRIVER_JARUpdate settings.DATABASESOraclechangedjango.db.backends.oracletodj_db_conn_pool.backends.jdbc.oracle:DATABASES={'default':{'ENGINE':'dj_db_conn_pool.backends.jdbc.oracle'}}OceanBaseusedj_db_conn_pool.backends.jdbc.oceanbase:DATABASES={'default':{'ENGINE':'dj_db_conn_pool.backends.jdbc.oceanbase'}}