4

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) 
Alex M
  • 2,756
  • 7
  • 29
  • 35
Jiaji Li
  • 1,331
  • 2
  • 9
  • 5

2 Answers2

13

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.

Community
  • 1
  • 1
Paulo Scardine
  • 73,447
  • 11
  • 124
  • 153
12

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.

the_drow
  • 18,571
  • 25
  • 126
  • 193
  • 2
    Awesome answer. Btw [Posgres wiki](https://wiki.postgresql.org/wiki/Number_Of_Database_Connections) tells: "Some client side software (like Java EE / JPA / Hibernate) always pools connections, so built-in pooling in PostgreSQL would then be wasteful duplication." – Abdur-Rahmaan Janhangeer Jan 07 '21 at 19:20