Skip to main content

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_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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_vb_connection_pool-0.1.0.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_vb_connection_pool-0.1.0-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file django_vb_connection_pool-0.1.0.tar.gz.

File metadata

File hashes

Hashes for django_vb_connection_pool-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1d0e8cc332db5df2ee7d1e8e63b4a929066d47f24e54142a55cb3b9301f5c99e
MD5 bb741ca74d2ae6d15e6fe8a54623b7fe
BLAKE2b-256 e002db020118df299dd52b7c016ef6917f80a774204b9a02c3f4794caee20257

See more details on using hashes here.

File details

Details for the file django_vb_connection_pool-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_vb_connection_pool-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7c6ab0029b57a14d28d12929e2db798b297899b73031c841a503ab9f5b69f6b4
MD5 89f5a79237d40ef69e9e2f35fe09f29d
BLAKE2b-256 26a455567efc73e74f407ac4e8a22e423deace51f6296bea9e01dc97e6397413

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page