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

Sessions: Add support for Redis as a session_class_handler (take 2)

    XMLWordPrintable

    Details

    • Testing Instructions:
      Hide

      You are required to have a Redis server running and configured to work with your web server in order to perform this test.

      For Ubuntu that is simply,

      apt-get install php5-redis redis-server
      service apache2 restart

      Ensure that lib/classes/session/redis.php exists.

      Edit config.php and add the following:

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

      Navigate to admin/phpinfo.php then scroll down to the session block and check the following local values,

      session.save_handler = user
      session.save_path = no value

      With Performance information displayed on the default theme, at the bottom of the screen you will see

      Session (core\session\redis): 

      To see if Redis is being used, in a prompt on the server type the following command

      redis-cli monitor

      Navigate around the site keeping an eye on the open terminal.
      You should now see session objects being accessed via Redis.

      There is an attachment php file that can run additional tests. 'redis_test.php'
      Please place it in the root directory of your Moodle install.

      This script uses the built in generators to create a list of accounts in Moodle.
      It then logs the users in to create individual session objects that are stored in Redis.
      Navigates to the user dashboard to retreive the session object and update it.
      When it navigates to this page it compares some of the session data with the generated data for a match.

      The default Moodle $CFG->sessiontimeout is two hours.

      This script has the following defaults.
      Max users created: 200.
      Number of users to connect at once: 25.

      To see some runtime options try php redis_test.php --help

      The steps for testing the Redis cache store with redis_test.php,

      Generate initial test users.

      php redis_test.php --generate
       
      # Expected output.
      Created 25/200 users.
      Created 50/200 users.
      Created 75/200 users.
      Created 100/200 users.
      Created 125/200 users.
      Created 150/200 users.
      Created 175/200 users.
      Created 200/200 users.
      Created 200/200 users.

      Log the users in.

      php redis_test.php --login
       
      # Expected output. If $CFG->sessiontimeout = 7200 (120mins)
      Current session timeout: 120 minutes
      Logged in 25/200 users.
      Logged in 50/200 users.
      Logged in 75/200 users.
      Logged in 100/200 users.
      Logged in 125/200 users.
      Logged in 150/200 users.
      Logged in 175/200 users.
      Logged in 200/200 users.

      Test after some time, 0 mins, 5 mins, 1 hour, or less than $CFG->sessiontimeout

      php redis_test.php --testall
       
      # Expected output.
      Updating sessions of 25/200 users.
      Updating sessions of 50/200 users.
      Updating sessions of 75/200 users.
      Updating sessions of 100/200 users.
      Updating sessions of 125/200 users.
      Updating sessions of 150/200 users.
      Updating sessions of 175/200 users.
      Updating sessions of 200/200 users.

      Cleanup accounts and temp files generated.

      php redis_test.php --delete
       
      # Expected output.
      Deleted 25/200 users.
      Deleted 50/200 users.
      Deleted 75/200 users.
      Deleted 100/200 users.
      Deleted 125/200 users.
      Deleted 150/200 users.
      Deleted 175/200 users.
      Deleted 200/200 users.

      Run Brendan Heywood's session breaker to ensure that we cover the session locking issue. Can we share that code?

      Show
      You are required to have a Redis server running and configured to work with your web server in order to perform this test. For Ubuntu that is simply, apt-get install php5-redis redis-server service apache2 restart Ensure that lib/classes/session/redis.php exists. Edit config.php and add the following: $CFG->session_handler_class = '\core\session\redis'; $CFG->session_redis_host = '127.0.0.1'; Navigate to admin/phpinfo.php then scroll down to the session block and check the following local values, session.save_handler = user session.save_path = no value With Performance information displayed on the default theme, at the bottom of the screen you will see Session (core\session\redis): To see if Redis is being used, in a prompt on the server type the following command redis-cli monitor Navigate around the site keeping an eye on the open terminal. You should now see session objects being accessed via Redis. There is an attachment php file that can run additional tests. 'redis_test.php' Please place it in the root directory of your Moodle install. This script uses the built in generators to create a list of accounts in Moodle. It then logs the users in to create individual session objects that are stored in Redis. Navigates to the user dashboard to retreive the session object and update it. When it navigates to this page it compares some of the session data with the generated data for a match. The default Moodle $CFG->sessiontimeout is two hours. This script has the following defaults. Max users created: 200. Number of users to connect at once: 25. To see some runtime options try php redis_test.php --help The steps for testing the Redis cache store with redis_test.php, Generate initial test users. php redis_test.php --generate   # Expected output. Created 25/200 users. Created 50/200 users. Created 75/200 users. Created 100/200 users. Created 125/200 users. Created 150/200 users. Created 175/200 users. Created 200/200 users. Created 200/200 users. Log the users in. php redis_test.php --login   # Expected output. If $CFG->sessiontimeout = 7200 (120mins) Current session timeout: 120 minutes Logged in 25/200 users. Logged in 50/200 users. Logged in 75/200 users. Logged in 100/200 users. Logged in 125/200 users. Logged in 150/200 users. Logged in 175/200 users. Logged in 200/200 users. Test after some time, 0 mins, 5 mins, 1 hour, or less than $CFG->sessiontimeout php redis_test.php --testall   # Expected output. Updating sessions of 25/200 users. Updating sessions of 50/200 users. Updating sessions of 75/200 users. Updating sessions of 100/200 users. Updating sessions of 125/200 users. Updating sessions of 150/200 users. Updating sessions of 175/200 users. Updating sessions of 200/200 users. Cleanup accounts and temp files generated. php redis_test.php --delete   # Expected output. Deleted 25/200 users. Deleted 50/200 users. Deleted 75/200 users. Deleted 100/200 users. Deleted 125/200 users. Deleted 150/200 users. Deleted 175/200 users. Deleted 200/200 users. Run Brendan Heywood's session breaker to ensure that we cover the session locking issue. Can we share that code?
    • Affected Branches:
      MOODLE_32_STABLE
    • Fixed Branches:
      MOODLE_32_STABLE
    • Pull Master Branch:

      Description

      This was previously done in MDL-53599 - but the underlying lib didn't support session locking which was a critical issue and so it was rolled back (see MDL-54057). This issue is to redo it and add locking support.

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                1 Vote for this issue
                Watchers:
                14 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  5/Dec/16