django-db-pool

Basic database persistence / connection pooling for Django + Postgres
Download

django-db-pool Ranking & Summary

Advertisement

  • Rating:
  • License:
  • BSD License
  • Price:
  • FREE
  • Publisher Name:
  • Greg McGuire
  • Publisher web site:
  • https://github.com/gmcguire/

django-db-pool Tags


django-db-pool Description

Yes, alas. Django punts on the problem of pooled / persistant connections, generally telling folks to use a dedicated application like PGBouncer (for Postgres.) However that's not always workable on app-centric platforms like Heroku, where each application runs in isolation. Thus the django-db-pool app. There are others, but this one attempts to provide connection persistance / pooling with as few dependencies as possible.Currently only the Django postgres_psycopg2 driver is supported. Connection pooling is implemented by thinly wrapping a psycopg2 connection object with a pool-aware class. The actual pool implementation is psycop2g's built-in ThreadedConnectionPool, which handles thread safety for the pool instance, as well as simple dead connection testing when connections are returned.Because this implementation sits inside the python interpreter, in a multi-process app server environment the pool will never be larger than one connection. However, you can still benefit from connection persistance (no connection creation overhead, query plan caching, etc.) so the (minimal) additional overhead of the pool should be outweighed by these benefits.Installation pip install django-db-poolUsageChange your `DATABASES` -> `ENGINE` from `'django.db.backends.postgresql_psycopg2'` to`'dbpool.db.backends.postgresql_psycopg2'`.If you are in a multithreaded environment, also set `MAX_CONNS` and optionally `MIN_CONNS` in the `OPTIONS`, like this: 'default': { 'ENGINE': 'dbpool.db.backends.postgresql_psycopg2', 'OPTIONS': {'MAX_CONNS': 1}, # These options will be used to generate the connection pool instance # on first use and should remain unchanged from your previous entries 'NAME': 'test', 'USER': 'test', 'PASSWORD': 'test123', 'HOST': 'localhost', 'PORT': '', }See the for more information on settings `MAX_CONNS` and `MIN_CONNS`.Product's homepage


django-db-pool Related Software