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

memcached session driver does not support multiple servers

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.6.3, 2.7.1, 2.8
    • 2.6.5, 2.7.2
    • Libraries
    • MOODLE_26_STABLE, MOODLE_27_STABLE, MOODLE_28_STABLE
    • MOODLE_26_STABLE, MOODLE_27_STABLE
    • wip_MDL-46552_m28_memcached
    • Hide

      Note: hacker attitude required, do not ask me for detailed test instructions.

      1/ regression testing - set up memcached session driver with 1 server only

      • try logging in and logging out
      • create a small CLI script that lists sessions in memcached and db

        <?php
        define('CLI_SCRIPT', 1);
        require('config.php');
        $servers = array();
        $servers[] = array("127.0.0.1", "11211");
        $prefix = 'memc.sess.key.';
        $memcached = new \Memcached();
        $memcached->addServers($servers);
        var_dump($memcached->getAllKeys());
        var_dump($DB->get_records('sessions'));
        

      • and try following commands in separate script -

        \core\session\manager::kill_session('somesessionid');
        \core\session\manager::kill_all_sessions();
        \core\session\manager::gc(); // you may need to set some very low $CFG->sessiontimeout = 20;
        

      2/ repeat with two or more servers and verify the session data is deleted from both servers

      Show
      Note: hacker attitude required, do not ask me for detailed test instructions. 1/ regression testing - set up memcached session driver with 1 server only try logging in and logging out create a small CLI script that lists sessions in memcached and db <?php define('CLI_SCRIPT', 1); require('config.php'); $servers = array(); $servers[] = array("127.0.0.1", "11211"); $prefix = 'memc.sess.key.'; $memcached = new \Memcached(); $memcached->addServers($servers); var_dump($memcached->getAllKeys()); var_dump($DB->get_records('sessions')); and try following commands in separate script - \core\session\manager::kill_session('somesessionid'); \core\session\manager::kill_all_sessions(); \core\session\manager::gc(); // you may need to set some very low $CFG->sessiontimeout = 20; 2/ repeat with two or more servers and verify the session data is deleted from both servers

    Description

      In Moodle 2.5 and previous, Moodlerooms had a custom patch to support memcached sessions. Session storage capped out at a few hundred megabytes per memcache node. In Moodle 2.6 (and later), we are using the default Core behavior. We are now seeing a dramatic increase of our session storage - roughly 10-20x that usage.

      Moodle has the following snippet of code around session timeouts:

              // Moodle does normal session timeouts, this is for leftovers only.
              ini_set('session.gc_probability', 1);
              ini_set('session.gc_divisor', 1000);
              ini_set('session.gc_maxlifetime', 60*60*24*4);
      

      This requires your session backend to be dozens of times larger than it needs to be for memcached, based on $CFG->sessiontimeout. For example, if sessiontimeout is set to the default of 2 hours and a user happens to login consistently just after 2 hours, the user will be timed out correctly but there will be orphaned sessions collecting for 4 days, requiring about 48x more session storage than we actually need. This likely explains the huge increase in session storage.

      In MR's previous memcache patch, gc_maxlifetime was actually set to $CFG->sessiontimeout. This makes sense as garbage collection for the session should happen automatically on the memcache server based on the key's TTL, which is set to the same as gc_maxlifetime. However it may not make sense for other session drivers (file, database). It would probably make sense for gc_maxlifetime to be set based on the session driver.

      Attachments

        Issue Links

          Activity

            People

              skodak Petr Skoda
              kstokking Kris Stokking
              Frédéric Massart Frédéric Massart
              Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
              Rajesh Taneja Rajesh Taneja
              David Woloszyn, Huong Nguyen, Jake Dallimore, Michael Hawkins, Stevani Andolo
              Votes:
              1 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                8/Sep/14