Details
-
Improvement
-
Status: Development in progress
-
Major
-
Resolution: Unresolved
-
3.9.4, 3.11.10, 4.0.4, 4.1
-
None
-
MOODLE_311_STABLE, MOODLE_39_STABLE, MOODLE_400_STABLE, MOODLE_401_STABLE
-
db-disconnect-during-session-wait
-
10
Description
On installations with a large number of concurrent users a common problem is lock contention for the session write lock. As a consequence a lot of requests may end up waiting on a session write lock. While doing so they keep the database connection open which is opened at the beginning of handling a request. As waiting for a session lock can take several seconds or depending on config even minutes (think that's the default), this can lead to database problems due to the large number of open connections.
Installing tools like ProxySQL or PgBouncer on the webservers can help alleviate some of this problem, but to avoid a tipping point this patch proposes to disconnect from the database entirely if the wait for the session lock has gone on for 2 seconds, and reconnects to the database once the session lock has been acquired.
The current patch only implements this behavior for the redis session handler and mysqli_native. So if there is interest one could add support for the same behavior to other session handlers and database systems, although the code works as-is on all systems and simply does not do the reconnect if it is not supported by the underlying database system.