vastbase connection pool component library for Django
Project description
django-vb-connection-pool
:star: If this project is helpful to you, please light up the star, Thank you:smile:
Vastbase connection pool components for Django, Be based on SQLAlchemy. Works fine in multiprocessing and multithreading django project.
Quickstart
Installation
Install with pip:
$ pip install django-vb-connection-pool
Update settings.DATABASES
PostgreSQL
change django.db.backends.postgresql to dj_vb_conn_pool.backends.vastbase:
DATABASES = {
'default': {
'ENGINE': 'dj_vb_conn_pool.backends.vastbase'
}
}
Pool options(optional)
you can provide additional options to pass to SQLAlchemy's pool creation, key's name is POOL_OPTIONS:
DATABASES = {
'default': {
'POOL_OPTIONS': {
'POOL_SIZE': 10,
'MAX_OVERFLOW': 10,
'RECYCLE': 24 * 60 * 60
}
}
}
django-db-connection-pool has more configuration options
here: PoolContainer.pool_default_params
Here's the 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:
import dj_vb_conn_pool
dj_vb_conn_pool.setup(pool_size=100, max_overflow=50)
multiprocessing environment
In a multiprocessing environment, such as uWSGI, each process will have its own dj_db_conn_pool.core:pool_container
object,
It means that each process has an independent connection pool, for example:
The POOL_OPTIONS configuration of database db1 is{ 'POOL_SIZE': 10, 'MAX_OVERFLOW': 20 },
If uWSGI starts 8 worker processes, then the total connection pool size of db1 is 8 * 10,
The maximum number of connections will not exceed 8 * 10 + 8 * 20
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_vb_connection_pool-0.1.0.tar.gz.
File metadata
- Download URL: django_vb_connection_pool-0.1.0.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d0e8cc332db5df2ee7d1e8e63b4a929066d47f24e54142a55cb3b9301f5c99e
|
|
| MD5 |
bb741ca74d2ae6d15e6fe8a54623b7fe
|
|
| BLAKE2b-256 |
e002db020118df299dd52b7c016ef6917f80a774204b9a02c3f4794caee20257
|
File details
Details for the file django_vb_connection_pool-0.1.0-py3-none-any.whl.
File metadata
- Download URL: django_vb_connection_pool-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c6ab0029b57a14d28d12929e2db798b297899b73031c841a503ab9f5b69f6b4
|
|
| MD5 |
89f5a79237d40ef69e9e2f35fe09f29d
|
|
| BLAKE2b-256 |
26a455567efc73e74f407ac4e8a22e423deace51f6296bea9e01dc97e6397413
|