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

Support for split memcache/memcached stores

XMLWordPrintable

    • MOODLE_25_STABLE, MOODLE_26_STABLE
    • MOODLE_28_STABLE
    • MDL-42071_MK3
    • Hide

      This is on a Mac, but should be similar in Linux. Windows is unknown to me.

      Requirements:

      • memcached (the service)
      • memcached (PECL)
      • memcache (PECL)
      • phpunit setup

      You will need two instances of memcached running. On my mac (linux should be the same) you can start two by doing:
      Open two shells, and run one command in each:

      memcached -p 11211

      memcached -p 11210

      In another shell, run these commands, and confirm the results are all 0:

      echo stats | nc 127.0.0.1 11211 | grep cmd_

      echo stats | nc 127.0.0.1 11210 | grep cmd_

      Add this to your config.php:

      define('TEST_CACHESTORE_MEMCACHED_TESTSERVERS', '127.0.0.1:11211
      127.0.0.1:11210');
      

      Open a shell, and navigate to the dirroot of the site you a testing with.
      If you haven’t done so yet, run:

      php admin/tool/phpunit/cli/init.php

      Run the memcached test_clustered unit test:

      vendor/bin/phpunit --filter test_clustered cache/stores/memcached/tests/memcached_test.php

      Run these commands:

      echo stats | nc 127.0.0.1 11211 | grep cmd_

      echo stats | nc 127.0.0.1 11210 | grep cmd_

      We expect that get, set, and flush has moved up on both servers. My results are:

      merrill ~$ echo stats | nc 127.0.0.1 11211 | grep cmd_
      STAT cmd_get 132
      STAT cmd_set 42
      STAT cmd_flush 1
      STAT cmd_touch 0
      merrill ~$ echo stats | nc 127.0.0.1 11210 | grep cmd_
      STAT cmd_get 66
      STAT cmd_set 41
      STAT cmd_flush 1
      STAT cmd_touch 0
      

      Run the full memcached unit tests and confirm no failures:

      vendor/bin/phpunit cachestore_memcached_test cache/stores/memcached/tests/memcached_test.php

      1. Turn on Performance info under Development > Debugging
      2. Create a new Memcached caching instance
      3. Set the name to Memcached Cluster, Servers to ‘localhost:11211’, Enable clustering, and Set servers to:

        localhost:11211
        localhost:11210

      4. Save with all the remaining default settings.
      5. Add the Memcached Cluster store to the Language string cache.
      6. Reset the two memcached services (ctrl+C, then rerun the command).
      7. Navigate to Home. Once there, reload the page.
      8. We expect to see cachestore_memcachedcluster under core/string, with no misses or sets (or very few).
      9. Purge all caches.
      10. Rerun the two stats commands. We expect the server on port 11211 to have many gets and sets. The server on port 11210 should have many sets, but no gets. Both will have flushes.

      Repeat everything above for the memcache store.
      Define in config.php:

      define('TEST_CACHESTORE_MEMCACHE_TESTSERVERS', '127.0.0.1:11211
      127.0.0.1:11210');
      

      And the php unit tests are:

      vendor/bin/phpunit --filter test_clustered cache/stores/memcache/tests/memcache_test.php

      and

      vendor/bin/phpunit cachestore_memcache_test cache/stores/memcache/tests/memcache_test.php

      Show
      This is on a Mac, but should be similar in Linux. Windows is unknown to me. Requirements: memcached (the service) memcached (PECL) memcache (PECL) phpunit setup You will need two instances of memcached running. On my mac (linux should be the same) you can start two by doing: Open two shells, and run one command in each: memcached -p 11211 memcached -p 11210 In another shell, run these commands, and confirm the results are all 0: echo stats | nc 127.0.0.1 11211 | grep cmd_ echo stats | nc 127.0.0.1 11210 | grep cmd_ Add this to your config.php: define('TEST_CACHESTORE_MEMCACHED_TESTSERVERS', '127.0.0.1:11211 127.0.0.1:11210'); Open a shell, and navigate to the dirroot of the site you a testing with. If you haven’t done so yet, run: php admin/tool/phpunit/cli/init.php Run the memcached test_clustered unit test: vendor/bin/phpunit --filter test_clustered cache/stores/memcached/tests/memcached_test.php Run these commands: echo stats | nc 127.0.0.1 11211 | grep cmd_ echo stats | nc 127.0.0.1 11210 | grep cmd_ We expect that get, set, and flush has moved up on both servers. My results are: merrill ~$ echo stats | nc 127.0.0.1 11211 | grep cmd_ STAT cmd_get 132 STAT cmd_set 42 STAT cmd_flush 1 STAT cmd_touch 0 merrill ~$ echo stats | nc 127.0.0.1 11210 | grep cmd_ STAT cmd_get 66 STAT cmd_set 41 STAT cmd_flush 1 STAT cmd_touch 0 Run the full memcached unit tests and confirm no failures: vendor/bin/phpunit cachestore_memcached_test cache/stores/memcached/tests/memcached_test.php Turn on Performance info under Development > Debugging Create a new Memcached caching instance Set the name to Memcached Cluster, Servers to ‘localhost:11211’, Enable clustering, and Set servers to: localhost:11211 localhost:11210 Save with all the remaining default settings. Add the Memcached Cluster store to the Language string cache. Reset the two memcached services (ctrl+C, then rerun the command). Navigate to Home. Once there, reload the page. We expect to see cachestore_memcachedcluster under core/string, with no misses or sets (or very few). Purge all caches. Rerun the two stats commands. We expect the server on port 11211 to have many gets and sets. The server on port 11210 should have many sets, but no gets. Both will have flushes. Repeat everything above for the memcache store. Define in config.php: define('TEST_CACHESTORE_MEMCACHE_TESTSERVERS', '127.0.0.1:11211 127.0.0.1:11210'); And the php unit tests are: vendor/bin/phpunit --filter test_clustered cache/stores/memcache/tests/memcache_test.php and vendor/bin/phpunit cachestore_memcache_test cache/stores/memcache/tests/memcache_test.php

      In load balanced environments, it can be of significant benefit to have memcached servers running on each front end server, as it removes network time for all access of the cache.

      Most caches must (or at least really should be) shared, and running caches that point to localhost (ie on each front end) can/will get out of sync, as there is no modification or invalidation between machines.

      Some caches have a very low set/hit ratio, like Lang Strings and DB Schema.

      With that in mind, I propose a two cache stores (memcachecluster and memcachedcluster) that fetch from one set of servers (typically localhost) and updates a different set of servers (typically the full hostname of each front end).

      Because of low set/hit ratio, the time lost in updating multiple servers is more than made up by the gain of fetching locally.

            emerrill Eric Merrill
            emerrill Eric Merrill
            Dan Poltawski Dan Poltawski
            Sam Hemelryk Sam Hemelryk
            David Monllaó David Monllaó
            Votes:
            4 Vote for this issue
            Watchers:
            19 Start watching this issue

              Created:
              Updated:
              Resolved:

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