Why doesn't django support connection pool?
Asked Answered
K

3

5

I wonder why django doesn't support connection pool? I can't bear open/close connection every request. I try to solve it, but hasn't a good solution.

I try to use mysql_pool, but fail:

TypeError: init() takes exactly 1 argument (3 given) 
Kelvin answered 28/12, 2010 at 12:33 Comment(2)
__init__ expects only 1 argument and you're passing 3, why?Nursling
Are you running django as CGI (instead of something like as WSGI or mod_python)?Thermonuclear
T
14

EDITED: look at Django persistent database connection (feature introduced in 1.6).

Persistent connections avoid the overhead of re-establishing a connection to the database in each request. They’re controlled by the CONN_MAX_AGE parameter which defines the maximum lifetime of a connection. It can be set independently for each database.

Thermonuclear answered 28/12, 2010 at 18:21 Comment(2)
It will. Django explicitly closes connection on end of request.Wideman
@Suor: It will indeed - shame on me.Thermonuclear
H
14

Here's a discussion about why django did not add pooling to the core: https://groups.google.com/forum/#!topic/django-developers/NwY9CHM4xpU

Generally speaking it's because third party applications such as pgbouncer do it better.

Hyperventilation answered 19/10, 2014 at 12:25 Comment(1)
Awesome answer. Btw Posgres wiki tells: "Some client side software (like Java EE / JPA / Hibernate) always pools connections, so built-in pooling in PostgreSQL would then be wasteful duplication."Laughter
B
0

There is now connection pool support in Django, since version 5.1: https://docs.djangoproject.com/en/5.1/releases/5.1/#postgresql-connection-pools

Brigitte answered 19/9, 2024 at 7:42 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.