{ "info": { "author": "Patrick Zhao", "author_email": "", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", "Natural Language :: English", "Programming Language :: Python", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: Implementation :: CPython" ], "description": "Gevent-Friendly Database Connection Pooling in Django\n=====================================================\n\nThanks to SQLAlchemy, we can pool the database connections while using the Gevent's monkey patching.\n\nIt supports MySQL and has been tested under Python 2.7, Django 1.11, Gevent 1.2, and SQLAlchemy 1.2.\n\nBesides, ``DjangoQueuePool`` is a new queue pool extending the SQLAlchemy's ``QueuePool``:\n\n- Reuse the database connections overflowed by burst traffic;\n- Retire the unused database connections gradually over time.\n\nPlease remember to close the unusable or obsolete database connections:\n\n- The closed connections are returned to the pool;\n- It is recommended to close them once a task is done.\n- It is recommended to set ``CONN_MAX_AGE`` as ``0`` if possible;\n- The connections would always be obsolete if ``CONN_MAX_AGE`` is ``0``.\n\n.. code-block:: python\n\n from django.db import connections\n\n for conn in connections.all():\n conn.close_if_unusable_or_obsolete()\n\n\nGetting Started\n---------------\n\n- Install the database connection pool\n\n.. code-block::\n\n pip install django-db-conn-pool\n\n- Add the pool to the Django database backend\n\n.. code-block:: python\n\n DATABASES = {\n 'default': {\n 'ENGINE': 'django_db_conn_pool.mysqlalchemy',\n 'CONN_MAX_AGE': 0,\n 'POOL': db_conn_pool,\n ...\n }\n }\n\n- Select and tune the connection pool parameters\n\n.. code-block:: python\n\n from sqlalchemy.pool import QueuePool\n from django_db_conn_pool.mysqlalchemy.pool import DjangoQueuePool\n\n\n db_conn_pool = slow_and_safe = {\n\n 'django_pool_class': QueuePool, # sqlalchemy's builtin queue pool class\n 'django_pre_ping': True, # pre ping by django if dialect is None\n 'django_reset_on_return': False, # use sqlalchemy's reset on conn return\n\n 'pool_size': 5, # daily traffic: reuse long connections\n 'max_overflow': 0, # burst traffic: do not overload the db\n 'timeout': 30, # burst traffic: > external api timeout\n 'recycle': 120, # should be smaller than mysql timeout\n 'dialect': None, # sqlalchemy's mysql dialect instance\n 'pre_ping': False, # sqlalchemy pre ping requires dialect\n 'use_threadlocal': True, # every thread always get its same conn\n 'reset_on_return': 'rollback', # reset on every conn return by rollback\n }\n\n db_conn_pool = fast_and_sane = {\n\n 'django_pool_class': QueuePool, # sqlalchemy's builtin queue pool class\n 'django_pre_ping': False, # no pre ping due to long mysql timeout\n 'django_reset_on_return': True, # reset by rollback only when necessary\n\n 'pool_size': 5, # daily traffic: reuse long connections\n 'max_overflow': 10, # burst traffic: do not overload the db\n 'timeout': 30, # burst traffic: > external api timeout\n 'recycle': 3600, # to be much smaller than mysql timeout\n 'dialect': None, # sqlalchemy's mysql dialect instance\n 'pre_ping': False, # sqlalchemy pre ping requires dialect\n 'use_threadlocal': False, # diff threads share the db connections\n 'reset_on_return': None, # do not use sqlalchemy reset on return\n }\n\n db_conn_pool = fast_and_wild = {\n\n 'django_pool_class': DjangoQueuePool, # customized from sqlalchemy queue pool\n 'django_pre_ping': False, # no pre ping due to long mysql timeout\n 'django_reset_on_return': True, # reset by rollback only when necessary\n 'django_core_pool_size': 5, # retire no conn if achieving core size\n 'django_unload_timeout': 2, # wait some random time before overload\n 'django_retire_interval': 5, # retire few non-core conn per interval\n 'django_retire_quantity': 1, # retire few non-core conn per interval\n\n 'pool_size': 30, # daily traffic: recycle or retire conn\n 'max_overflow': 0, # burst traffic: put overflow into pool\n 'timeout': 30, # burst traffic: > external api timeout\n 'recycle': 3600, # to be much smaller than mysql timeout\n 'dialect': None, # sqlalchemy's mysql dialect instance\n 'pre_ping': False, # sqlalchemy pre ping requires dialect\n 'use_threadlocal': False, # diff threads share the db connections\n 'reset_on_return': None, # do not use sqlalchemy reset on return\n }\n\n\n.. :changelog:\n\nRelease History\n---------------\n\n1.0.0 (2019-05-04)\n++++++++++++++++++\n\n- Birthday\n\n\n", "description_content_type": "text/x-rst", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/shzhao17/django-db-conn-pool", "keywords": "", "license": "Apache 2.0", "maintainer": "", "maintainer_email": "", "name": "django-db-conn-pool", "package_url": "https://pypi.org/project/django-db-conn-pool/", "platform": "", "project_url": "https://pypi.org/project/django-db-conn-pool/", "project_urls": { "Homepage": "https://github.com/shzhao17/django-db-conn-pool" }, "release_url": "https://pypi.org/project/django-db-conn-pool/1.0.0/", "requires_dist": [ "six", "typing", "django", "sqlalchemy" ], "requires_python": ">=2.7,<3", "summary": "Gevent-Friendly Database Connection Pooling in Django", "version": "1.0.0" }, "last_serial": 5224552, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "db9adbb8e7c7211b55694ae1a4a57155", "sha256": "0ddc5233531eb8639f413e150f8e80931d7aad1a99bcd11ad98bc45274bc2df2" }, "downloads": -1, "filename": "django_db_conn_pool-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "db9adbb8e7c7211b55694ae1a4a57155", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=2.7,<3", "size": 11439, "upload_time": "2019-05-04T03:44:35", "url": "https://files.pythonhosted.org/packages/37/04/58a2a6ce9d3410643e1f719cfef60bd93a988009c856b0cd2f5d085aa420/django_db_conn_pool-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "b77c6b6c1248f605c20a356173ad7a1c", "sha256": "8bc872847e1c1a74ec6b49203247bed798e8c0ed2864caf7a28b5760feca81e3" }, "downloads": -1, "filename": "django-db-conn-pool-1.0.0.tar.gz", "has_sig": false, "md5_digest": "b77c6b6c1248f605c20a356173ad7a1c", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.7,<3", "size": 10639, "upload_time": "2019-05-04T03:44:38", "url": "https://files.pythonhosted.org/packages/d0/54/dbc861ad54e3600c8a9881e5c34dd26d54ea72c7171e5c5e48e170dab5b4/django-db-conn-pool-1.0.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "db9adbb8e7c7211b55694ae1a4a57155", "sha256": "0ddc5233531eb8639f413e150f8e80931d7aad1a99bcd11ad98bc45274bc2df2" }, "downloads": -1, "filename": "django_db_conn_pool-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "db9adbb8e7c7211b55694ae1a4a57155", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=2.7,<3", "size": 11439, "upload_time": "2019-05-04T03:44:35", "url": "https://files.pythonhosted.org/packages/37/04/58a2a6ce9d3410643e1f719cfef60bd93a988009c856b0cd2f5d085aa420/django_db_conn_pool-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "b77c6b6c1248f605c20a356173ad7a1c", "sha256": "8bc872847e1c1a74ec6b49203247bed798e8c0ed2864caf7a28b5760feca81e3" }, "downloads": -1, "filename": "django-db-conn-pool-1.0.0.tar.gz", "has_sig": false, "md5_digest": "b77c6b6c1248f605c20a356173ad7a1c", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.7,<3", "size": 10639, "upload_time": "2019-05-04T03:44:38", "url": "https://files.pythonhosted.org/packages/d0/54/dbc861ad54e3600c8a9881e5c34dd26d54ea72c7171e5c5e48e170dab5b4/django-db-conn-pool-1.0.0.tar.gz" } ] }