Skip to main content

django-vb-connection-pool

⭐ If this project is helpful to you, please light up the star, Thank you😄

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_size can be set to 0 to indicate no size limit; to disable pooling, use a :class:~sqlalchemy.pool.NullPool instead.

  • 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_overflow can 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

Metadata

Release files for django-vb-connection-pool 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-vb-connection-pool 0.1.0
File Size Uploaded
django_vb_connection_pool-0.1.0.tar.gz 4.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-vb-connection-pool 0.1.0
File Interpreter ABI Platform
django_vb_connection_pool-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 10.9 kB

Release files / django_vb_connection_pool-0.1.0.tar.gz

Download URL django_vb_connection_pool-0.1.0.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
1d0e8cc332db5df2ee7d1e8e63b4a929066d47f24e54142a55cb3b9301f5c99e
BLAKE2b-256 checksum
How to use checksums
e002db020118df299dd52b7c016ef6917f80a774204b9a02c3f4794caee20257
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.6

Release files / django_vb_connection_pool-0.1.0-py3-none-any.whl

Download URL django_vb_connection_pool-0.1.0-py3-none-any.whl
Size 6.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7c6ab0029b57a14d28d12929e2db798b297899b73031c841a503ab9f5b69f6b4
BLAKE2b-256 checksum
How to use checksums
26a455567efc73e74f407ac4e8a22e423deace51f6296bea9e01dc97e6397413
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.6

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page