[Django] #35702: Clarify mysqlclient does not provide connection pooling

21 views
Skip to first unread message

Django

unread,
Aug 22, 2024, 11:09:49 AM8/22/24
to django-...@googlegroups.com
#35702: Clarify mysqlclient does not provide connection pooling
-------------------------------------+-------------------------------------
Reporter: Hisham Mahmood | Type:
| Cleanup/optimization
Status: new | Component:
| Documentation
Version: dev | Severity: Normal
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
The mysqlclient driver
[https://github.com/PyMySQL/mysqlclient/discussions/707#discussioncomment-8621288
does not provide connection pooling], we also [https://groups.google.com/g
/django-developers/c/NwY9CHM4xpU don't ship it]. I think we should clarify
this [https://docs.djangoproject.com/en/5.1/ref/databases/#mysql-db-api-
drivers here].
--
Ticket URL: <https://code.djangoproject.com/ticket/35702>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Aug 22, 2024, 1:40:23 PM8/22/24
to django-...@googlegroups.com
#35702: Clarify mysqlclient does not provide connection pooling
--------------------------------------+------------------------------------
Reporter: Hisham Mahmood | Owner: (none)
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Simon Charette):

* stage: Unreviewed => Accepted

Comment:

The note about `mysqlclient` being thread safe and implementing connection
pooling was inherited in #23446
(7f089ac2e3e6a7f4b2b41085a37d35e074fad805). The thread safety and
connection pooling claims were added for `MySQLDB`
[https://github.com/django/django/pull/1906/files originally] but they are
certainly not true for either `pymysql` or `mysqlclient`.

As pointed out in [https://mysqlclient.readthedocs.io/user_guide.html
their docs]

> The MySQL protocol can not handle multiple threads using the same
connection at once. Some earlier versions of MySQLdb utilized locking to
achieve a threadsafety of 2. While this is not terribly hard to accomplish
using the standard Cursor class (which uses mysql_store_result()), it is
complicated by SSCursor (which uses mysql_use_result(); with the latter
you must ensure all the rows have been read before another query can be
executed. It is further complicated by the addition of transactions, since
transactions start when a cursor executes a query, but end when COMMIT or
ROLLBACK is executed by the Connection object. Two threads simply cannot
share a connection while a transaction is in progress, in addition to not
being able to share it during query execution. This excessively
complicated the code to the point where it just isn’t worth it.
>
> The general upshot of this is: Don’t share connections between threads.
It’s really not worth your effort or mine, and in the end, will probably
hurt performance, since the MySQL server runs a separate thread for each
connection. You can certainly do things like cache connections in a pool,
and give those connections to one thread at a time. **If you let two
threads use a connection simultaneously, the MySQL client library will
probably upchuck and die. You have been warned**.

I would remove the thread safety claims as well.
--
Ticket URL: <https://code.djangoproject.com/ticket/35702#comment:1>

Django

unread,
Aug 22, 2024, 7:50:01 PM8/22/24
to django-...@googlegroups.com
#35702: Clarify mysqlclient does not provide connection pooling
-------------------------------------+-------------------------------------
Reporter: Hisham Mahmood | Owner: Hisham
Type: | Mahmood
Cleanup/optimization | Status: assigned
Component: Documentation | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Hisham Mahmood):

* owner: (none) => Hisham Mahmood
* status: new => assigned

Comment:

The `mysqlclient` driver is a fork of `MySQLdb`. It included a reference
to a
[https://web.archive.org/web/20071011050738/http://dustman.net/andy/python/Pool
pool module], that was [https://github.com/PyMySQL/mysqlclient/issues/75
removed]. Besides this mention, I don’t think `MySQLdb` has had pool
support either.
--
Ticket URL: <https://code.djangoproject.com/ticket/35702#comment:2>

Django

unread,
Aug 23, 2024, 10:35:37 AM8/23/24
to django-...@googlegroups.com
#35702: Clarify mysqlclient does not provide connection pooling
-------------------------------------+-------------------------------------
Reporter: Hisham Mahmood | Owner: Hisham
Type: | Mahmood
Cleanup/optimization | Status: assigned
Component: Documentation | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Hisham Mahmood):

* has_patch: 0 => 1

Comment:

[https://github.com/django/django/pull/18512 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/35702#comment:3>

Django

unread,
Aug 30, 2024, 3:07:38 AM8/30/24
to django-...@googlegroups.com
#35702: Clarify mysqlclient does not provide connection pooling
-------------------------------------+-------------------------------------
Reporter: Hisham Mahmood | Owner: Hisham
Type: | Mahmood
Cleanup/optimization | Status: assigned
Component: Documentation | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* stage: Accepted => Ready for checkin

--
Ticket URL: <https://code.djangoproject.com/ticket/35702#comment:4>

Django

unread,
Aug 30, 2024, 3:08:42 AM8/30/24
to django-...@googlegroups.com
#35702: Clarify mysqlclient does not provide connection pooling
-------------------------------------+-------------------------------------
Reporter: Hisham Mahmood | Owner: Hisham
Type: | Mahmood
Cleanup/optimization | Status: closed
Component: Documentation | Version: dev
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce <42296566+sarahboyce@…>):

* resolution: => fixed
* status: assigned => closed

Comment:

In [changeset:"2b2a2c0e26e9e01792a0e9fee790aac48ff474bc" 2b2a2c0e]:
{{{#!CommitTicketReference repository=""
revision="2b2a2c0e26e9e01792a0e9fee790aac48ff474bc"
Fixed #35702 -- Removed connection pooling note for mysql drivers.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35702#comment:5>
Reply all
Reply to author
Forward
0 new messages