Add ia DB connection pool using gevent to django
Project description
Another DB pool using gevent for PostgreSQL DB.
Need Django 1.5.x or newer (check settings for django >= 1.6)
Patch psycopg2
Before using the pool, psycopg2 must be patched with psycogreen, if you are using gunicorn webserver, a good place is the post_fork() function at the config file
from psycogreen.gevent import patch_psycopg
def post_fork(server, worker):
patch_psycopg()
worker.log_info("Made Psycopg2 Green")
Settings
Set ENGINE in your database settings to: ‘django_db_geventpool.backends.postgresql_psycopg2’
Or for postgis: ‘django_db_geventpool.backends.postgis’
Add MAX_CONNS to OPTIONS to set the maximun number of connections allowed to database (default=4)
If using django 1.6 or newer, add CONN_MAX_AGE: 0 to settings to disable default django persistent connection feature.
# for django 1.5.x
DATABASES = {
'default': {
'ENGINE': 'django_db_geventpool.backends.postgresql_psycopg2',
'NAME': 'db', # Or path to database file if using sqlite3.
'USER': 'postgres', # Not used with sqlite3.
'PASSWORD': 'postgres', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
'OPTIONS': {
'MAX_CONNS': 20
}
}
}
# for django 1.6 and newer version, CONN_MAX_AGE must be set to 0, or connections will never go back to the pool
DATABASES = {
'default': {
'ENGINE': 'django_db_geventpool.backends.postgresql_psycopg2',
'NAME': 'db',
'USER': 'postgres',
'PASSWORD': 'postgres',
'HOST': '',
'PORT': '',
'ATOMIC_REQUESTS': False,
'AUTOCOMMIT': True,
'CONN_MAX_AGE': 0,
'OPTIONS': {
'MAX_CONNS': 20
}
}
}
Other pools
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
Hashes for django-db-geventpool-0.90.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a0f7df848d4d5e797eed79e6cdcfe587825012995e847438db8457d407bb1364 |
|
MD5 | 812d4b2d882068421da0ccd575c2fd28 |
|
BLAKE2b-256 | 712d305d349f10c766e0b63fed57741173250a134531b7b9b67b7615a8551765 |