2
votes

I have a Django App with a pretty standard server stack

  • DB Backend : MySQL
  • WSGI Server : Gunicorn
  • Async worker class : Gevent

I want Django to pool MySQL connections rather than creating connections on every request.

Starting 1.6, Django has introduced persistent connections but there are issues with async workers.

Hence, either a different MySQL backend is required or app level connection pooling. I've read several of them. Some of them are very old articles. Following are some:

Django MySQL backends

  1. django-mysqlpool

App level Connection pool

  1. with SQL Alchemy
  2. another with SQL Alchemy

Some Patches are also available

  1. Django Patch

Some other approaches

  1. MySQL DB Connector

I'm really confused as to which approach among these is the best way to pool connections? Any Help is highly appreciated.

2

2 Answers

1
votes

This project still works on Django 1.9, and worked well for us.

https://github.com/djangonauts/djorm-ext-pool

0
votes

your demand

want pool MySQL connections rather than creating connections on every request.

my suggest

  1. in db level

Indicating that your application is IO-intensive, so the proposal is to use mysql conn pool.
may be u can use thirdpart mysql pool

  1. in app level

in app level no use connection pooling. But mostly use the cache ,may be redis cache etc,this can minus the connection number.

  1. in webserver level

in your server socalled WSGI Server . It is ligntweight so not pooling implement,u can refact to use queue to enhance the connection reused. or base Gevent to refact event_queue.

Hope this may can give you some help.