-
Improvement
-
Resolution: Fixed
-
Major
-
3.3
-
MOODLE_33_STABLE
-
MOODLE_39_STABLE
-
MDL-58018_master-arraycomparison -
Background
Many parts of Moodle now result in the browser making parallel requests to the Moodle server.
For example, a home page load on a fresh Moodle installation makes no less than 3 AJAX requests in parallel. Similarly, calls to /pluginfile.php that return HTML, often result in multiple parallel requests for further resources such as JS, CSS, images etc.
Problem Statement
Currently when a request is processed by Moodle, a session is always started, and in order to start that session an exclusive lock is acquired on that session, which, in general, is not released until the server completes processing the request, where it is released by calling write_close() in the shutdown handler (although some pages explicitly release this early).
The result is that even though the browser sends requests in parallel, once the requests hit the server they are in contention with each other, and effectively serialised by the session locking mechanism, resulting in busy spin locks and tying up server resources far longer than actually required. This is particularly apparent when the session lock code is buggy! (see MDL-57477, and PHP memcached issue: https://github.com/php-memcached-dev/php-memcached/issues/310)
Observation
In general, there is often no reason that a session lock is actually needed for cases where the processing of the request does not need any data to be persisted back to the session.
For example, while retrieving the session is nearly always necessary (to check the user is authenticated and authorized to access the selected resource), for serving actual content, such as information about navigation items, where the context is fully specified in the request, or perhaps for serving static content, there is no need to acquire a session lock, where the underlying handler guarantees atomic operations (such as memcached, where a get / set is atomic).
Proposed Solution
We propose a patch that allows:
1. Printing debug information on how long it takes to acquire a session.
2. Ability for a page to declare that it needs only a READ_ONLY_SESSION, where, if supported by the session handler, sessions are acquired without waiting for a lock, sessions are not locked, and calls to write_close() are ignored.
3. Opt-in of some key sources of contention to use this flag.
Looking for feedback
We would appreciate feedback on the validity of this approach, and the linked proposed patch.
- has a non-specific relationship to
-
MDL-70819 course/rest.php defined READ_ONLY_SESSION but changed: $SESSION->navcache
- Closed
-
MDL-79350 setup_lang_from_browser should not write to session when readonly sessions is declared
- Closed
-
MDL-64449 Add debug feature to expose code issues with session locks
- Closed
-
MDL-65452 Have two session lock timeouts, one for update (POST) vs read (some GET) requests
- Closed
-
MDL-74874 Mark readonly sessions as no longer experimental
- Closed
- has been marked as being related by
-
MDL-53875 Problems when MUC is configured to store session cache in other store and not in default user session - bloating, abscence of prefix, etc
- Open
-
MDL-55953 Redis session handler needs to register a shutdown function
- Closed
-
MDL-68611 SESSION->wanturls set during a read-only session
- Closed
-
MDL-68696 Read only sessions option throw exception with tool_mobile_get_public_config mobile when using redis sessions
- Closed
-
MDL-70688 Pluginfile only reads the session to e.g. check auth, no need to lock
- Closed
-
MDL-65718 Handle 206 range requests for audio / video more efficiently
- Open
-
MDL-71768 More tuning of the redis session handler to reduce blocking wait time
- Open
-
MDL-74503 Swap readonly sessions from opt in to opt out
- Open
- Testing discovered
-
MDL-69920 Assignment grader pollutes $SESSION->mod_assign_useridlist
- Waiting for peer review
-
MDL-68983 recentsessionlocks debugging clashes with readonly sessions
- Closed
-
MDL-68522 Enable read only sessions for the file handler class
- Closed
-
MDL-68523 Add detection to determine what sessions can be read only
- Closed
-
MDL-68608 Improve the readonly session debugging message
- Closed
- will be (partly) resolved by
-
MDL-73427 $SESSION->fromurl is attempted to be changed during READ_ONLY_SESSION sessions
- Closed
- will help resolve
-
MDL-66805 Search index.php should not lock the session during a search
- Closed
-
MDL-68577 Tune the redis session handler to reduce blocking wait time
- Closed