#23462: Django 1.7 openning one database connection for each request
-------------------------------------+-------------------------------------
Reporter: upmauro | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.7
(models, ORM) | Resolution:
Severity: Normal | Triage Stage:
Keywords: mysql | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by aaugustin):
There are two reasons why you shouldn't see a difference between 1.5 and
1.6+:
- If I understand correctly, you've set CONN_MAX_AGE to 0 -- the default;
that's supposed to preserve the 1.5 behavior of opening and closing a
database connection for each request.
- Even if you've set CONN_MAX_AGE to something >0, since every request
hits the database on your site, that shouldn't change much, unless you had
many idle Apache/mod_wsgi workers.
Unless I missed something, your application was already opening one
connection for each request, and it still does; there's no change.
I don't know what Apache's defaults are and they may depend on your
hardware — I assume Apache is able to scale its processes depending on how
many CPUs you have.
The sequence you've posted (1, 3, 4, 6, 7) looks correct. The connection
is terminated properly.
I would suggest that you:
- Review how many database connections you expect to need. That's the
number of Apache/mod_wsgi processes x the number of threads per process,
plus anything else that may connect to the database.
- Configure the database to allow this number of connections, plus a small
safety margin.
- (if possible) Measure how many connections the database actually gets
and figure out if it's consistent your Apache setp.
- (optional) If you wish, enable persistent connections by setting
CONN_MAX_AGE to something like 60, which should make your website faster.
--
Ticket URL: <https://code.djangoproject.com/ticket/23462#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/065.6a41f309d4760adca382feb11392d95e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.