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

Disconnect from database while waiting for session lock

    XMLWordPrintable

    Details

      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

            Assignee:
            Unassigned Unassigned
            Reporter:
            naderman Nils Adermann
            Participants:
            Component watchers:
            Adrian Greeve, Jake Dallimore, Mathew May, Mihail Geshoski, Peter Dias, Sujith Haridasan, Andrew Nicols, Dongsheng Cai, Huong Nguyen, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze, Matteo Scaramuccia, Andrew Nicols, Dongsheng Cai, Huong Nguyen, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze
            Votes:
            8 Vote for this issue
            Watchers:
            11 Start watching this issue

              Dates

              Created:
              Updated: