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

Performance: Allow session stores to fully manage the session

XMLWordPrintable

    • MOODLE_405_STABLE
    • MOODLE_405_STABLE
    • main_MDL-66151
    • Hide

      Overview

      Testing for this issue is very similar to MDL-63128. It requires setting up Redis (both in cluster and single node modes for full testing), to allow running of the relevant unit tests as well as testing user sessions.

      To save duplication, follow the test instructions below to test this issue. Then Complete the tests for MDL-63128 to ensure everything works in cluster mode.

      Being able to observe the values in Redis is also an advantage (but not strictly required). You can use the Redis CLI or alternatively Redis insight (which I prefer).

      Setup Requirements

      1. Install a single Redis on local machine and ensure it's running at 127.0.0.1:6379. Refer to this page on how to install Redis https://redis.io/docs/install/install-redis/.
      2. Ensure your machine has the PHP-Redis extension by checking on the Info PHP page. There are a lot of ways to check the PHP Info Page. Moodle has provided it on the Site Admin > Server > PHP info.
        If it has not been installed, you can install it by running the below command:

        pecl install redis

        Please visit https://developer.redis.com/develop/php/ for detailed information on how to do the installation.

      1. During the unit testing, if enabled, please disable the Xdebug on your PHP CLI config.

      Steps to run the PHPUnit for single Redis session

      1. Open config.php and add the below codes:

        define(
          'TEST_SESSION_REDIS_HOST',
          '127.0.0.1'
        );

      2. Make sure all the tests in lib/tests/session_redis_test.php are passed.

      Session Testing

      This will test that sessions are actually working and using the Redis session store only.

      1. Edit the config.php and add the below lines:

        $CFG->session_handler_class = '\core\session\redis';
        $CFG->session_redis_host = '127.0.0.1';

      2. From the CLI (or your favorite DB management tool). Take out an exclusive lock on the sessions table. For example:
        1. Postgres
          BEGIN; LOCK TABLE m_sessions IN ACCESS EXCLUSIVE MODE;
        2. Mysql
          LOCK TABLES m_sessions WRITE;
      3. Return to the browser.
      4. Reload the web page.
      5. Verify that you can log in, navigate pages and that no error messages are shown
      6. Remember to remove the lock on the sessions table:
        1. Postgres
          Commit;
        2. MySQL
          UNLOCK TABLES;
      Show
      Overview Testing for this issue is very similar to MDL-63128 . It requires setting up Redis (both in cluster and single node modes for full testing), to allow running of the relevant unit tests as well as testing user sessions. To save duplication, follow the test instructions below to test this issue. Then Complete the tests for MDL-63128 to ensure everything works in cluster mode. Being able to observe the values in Redis is also an advantage (but not strictly required). You can use the Redis CLI or alternatively Redis insight (which I prefer). Setup Requirements Install a single Redis on local machine and ensure it's running at 127.0.0.1:6379. Refer to this page on how to install Redis https://redis.io/docs/install/install-redis/ . Ensure your machine has the PHP-Redis extension by checking on the Info PHP page. There are a lot of ways to check the PHP Info Page. Moodle has provided it on the Site Admin > Server > PHP info. If it has not been installed, you can install it by running the below command: pecl install redis Please visit https://developer.redis.com/develop/php/ for detailed information on how to do the installation. During the unit testing, if enabled, please disable the Xdebug on your PHP CLI config. Steps to run the PHPUnit for single Redis session Open config.php and add the below codes: define(   'TEST_SESSION_REDIS_HOST' ,   '127.0.0.1' ); Make sure all the tests in lib/tests/session_redis_test.php are passed. Session Testing This will test that sessions are actually working and using the Redis session store only. Edit the config.php and add the below lines: $CFG->session_handler_class = '\core\session\redis' ; $CFG->session_redis_host = '127.0.0.1' ; From the CLI (or your favorite DB management tool). Take out an exclusive lock on the sessions table. For example: Postgres BEGIN; LOCK TABLE m_sessions IN ACCESS EXCLUSIVE MODE; Mysql LOCK TABLES m_sessions WRITE; Return to the browser. Reload the web page. Verify that you can log in, navigate pages and that no error messages are shown Remember to remove the lock on the sessions table: Postgres Commit; MySQL UNLOCK TABLES;
    • Team Hedgehog 2024 Sprint 2.1, Team Hedgehog 2024 Sprint 2.2, Team Hedgehog 2024 Sprint 2.3, Team Hedgehog 2024 Review 2, Team Hedgehog 2024 Sprint 3.1, Team Hedgehog 2024 Sprint 3.2

      THIS IS AN MUA PROJECT PROPOSAL THAT WILL BE OR HAS BEEN SUBMITTED FOR POSSIBLE MUA FUNDING.  ANY EXISTING TRACKER ITEMS THAT THIS MIGHT DUPLICATE SHOULD BE LINKED TO BELOW.  
       

      The current session store interface leaves some parts of the session managed by core in mdl_sessions. So this table gets a lot of contention even if you push it of to redis. This seems to surprise a lot of people that moodle still touches mdl_sessions and is counter intuitive.

      I believe the main historical reason for this is that some session stores are simple key / value stores and so things like 'how many sessions do I have' is hard / impossible / slow. But this isn't the case with many potential implementations, eg redis.

      Proposing:

      1) Move any functionality that touches the session table into new methods in the handler.php abstract class which do exactly the same thing.

      eg some example new methods:

      get_session_metadata($sid)

      would be called here:

      https://github.com/moodle/moodle/blob/9890e67e6d262a0a5eb938bc3b007045fe067ec9/lib/classes/session/manager.php#L428

      The naming / interface of these methods would be carefully constructed by design so that some of them could serve double duty and one of them would be a noop.

      2) Slightly improve the performance of the session/database.php so it only touches the tables once instead of twice,. eg updating the session data, and updating the session metadata would be done in the same method.

      3) For certain session stores like redis, override these methods so that mdl_session isn't touched at all. As above, it would save and read all session data and metadata in a single redis call.

       

       

       

            matt.porritt@moodle.com Matt Porritt
            brendanheywood Brendan Heywood
            Andrew Lyons Andrew Lyons
            Ilya Tregubov Ilya Tregubov
            Kim Jared Lucas Kim Jared Lucas
            Votes:
            23 Vote for this issue
            Watchers:
            36 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 week, 2 days, 3 hours, 19 minutes
                1w 2d 3h 19m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.