Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

Add a MySQL connection pool for django using gevent

Project description

https://circleci.com/gh/laurentL/django-mysql-geventpool/tree/master.svg?style=svg

Mysql Connection Pooling backend for Django < 2.0 using gevent, only supports Python 2.7 It works with gunicorn async worker via gevent. It implement an loadbalancing simple algo.

Fork from : https://github.com/shunsukeaihara/django-mysql-geventpool

This implimentation is based on django-db-geventpool(https://github.com/jneight/django-db-geventpool).

Installation

pip install django-mysql-geventpool-27

Settings

Add the ‘django_mysql_geventpool_27’ modules to the INSTALLED_APPS like this:

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django_mysql_geventpool-27',
    # ...other installed applications...

Add MAX_CONNS to OPTIONS to set the maximun number of connections allowed to database (default=4)

DATABASES = {
    'default': {
        'ENGINE': 'django_mysql_geventpool_27.backends.mysql',
        'NAME': 'dbname',
        'USER': 'dbuser',
        'PASSWORD': 'dbpassword',
        'HOST': 'dbhost',
        'PORT': 'dbport',
        'OPTIONS': {
            'MAX_CONNS': 20
        }
    }
}

Load balancing Galera multi master

For each connection, a random choice is operated on the HOST key of the DATABASE setting. For easy provisioning by an orchetrator like puppet/salt/ansible.., you can use this type of setting:

Note

All server must listen on the same tcp port.

DATABASES = {
    'default': {
        'ENGINE': 'django_mysql_geventpool_27.backends.mysql',
        'NAME': 'dbname',
        'USER': 'dbuser',
        'PASSWORD': 'dbpassword',
        'HOST': 'server1,server2,serve3',
        'PORT': 'dbport',
        'OPTIONS': {
            'MAX_CONNS': 20
        }
    }
}

Project details


Download files

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

Files for django-mysql-geventpool-27, version 0.3.2
Filename, size File type Python version Upload date Hashes
Filename, size django-mysql-geventpool-27-0.3.2.tar.gz (4.5 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page