Which session handler minimizes latency for concurrent AJAX requests in Moodle?
0 reputation · 30 Apr 2022, 07:33 UTC
Moodle relies on PHP session management to maintain user state. By default, file-based session handlers lock the session file for the duration of a request. This behavior can cause subsequent concurrent requests from the same user session—such as multiple simultaneous AJAX calls for dashboard blocks—to queue sequentially, increasing perceived latency.
While Moodle supports alternative handlers via $CFG->session_handler_class, including database-backed storage or external caches like Redis, the choice involves trade-offs between locking efficiency, database overhead, and infrastructure complexity.
Technical Constraints
- The need to prevent request blocking without compromising session data integrity.
- Compatibility with clustered environments where shared session state is required.
- Potential impact on third-party plugins that may rely on specific session behaviors.
What are the performance implications of using the \core\session\database handler compared to Redis when mitigating session lock contention? Does Moodle provide a native way to implement session_write_close() across all standard AJAX endpoints to release locks early?