Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-71024

Disconnect from database while waiting for session lock

    XMLWordPrintable

Details

    • 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.

      Attachments

        Activity

          People

            Unassigned Unassigned
            naderman Nils Adermann
            Safat Shahin Safat Shahin
            David Woloszyn, Huong Nguyen, Jake Dallimore, Meirza, Michael Hawkins, Raquel Ortega, Safat Shahin, Stevani Andolo, David Woloszyn, Huong Nguyen, Jake Dallimore, Meirza, Michael Hawkins, Raquel Ortega, Safat Shahin, Stevani Andolo, Matteo Scaramuccia, David Woloszyn, Huong Nguyen, Jake Dallimore, Meirza, Michael Hawkins, Raquel Ortega, Safat Shahin, Stevani Andolo
            Votes:
            11 Vote for this issue
            Watchers:
            16 Start watching this issue

            Dates

              Created:
              Updated:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 day
                1d