Help with Redis cache

Help with Redis cache

by Alan CF -
Number of replies: 2

Hi,

I just installed Moodle 3.5, and the admin interface loads really slow. This is my setup:

  • Ubuntu 16.04 on an Amazon EC2 instance
  • NGINX + PHP-FPM, with OPCache enabled
  • MariaDB in a separate Amazon RDS instance
  • The moodledata directory is pointing to an Amazon EFS instance
  • Redis cluster on Amazon Elasticache
I understand that using an NFS drive for the moodledata directory can affect the performance, so I've added the following in config.php to enable Redis:

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

$CFG->session_redis_host = '<my-redis-endpoint>';

$CFG->session_redis_port = 6379;  // Optional.

$CFG->session_redis_database = 0;  // Optional, default is db 0.

$CFG->session_redis_prefix = ''; // Optional, default is don't set one.

$CFG->session_redis_acquire_lock_timeout = 120;

$CFG->session_redis_lock_expire = 7200;

The problem is that the admin interface is running very slowly. What am I missing? What else do I need to do to use Redis as a session and application cache for Moodle?


thanks!


Average of ratings: -
In reply to Alan CF

Re: Help with Redis cache

by Tony H -

Hi Alan,

Did you get this to work? We just upgraded to 3.5.1 and I've not seen a slow admin interface. We are using NGINX, but as a reverse proxy to the standard Apache/PHP setup. Our Redis server and moodledata are on the same VPS,

Here are some things to try:

  1. Site administration -> Plugins -> Cache stores -> Redis
    1. Enter the test server information, such as your Redis server in the Test server field. (mine is 127.0.0.1:6379)
  2. Site administration -> Plugins -> Caching -> Configuration
    1. Honestly, I don't know if you need this...
    2. Add a store instance to Redis
    3. It should be ready (with a green check) and have at least one store
    4. You can view the store instance information under Configured store instances 
  3. Site administration -> Plugins -> Caching -> Test performance
    1. Run a test set
    2. If Redis is working, you should see the information there.
    3. Run the largest test set. Perhaps you can't do this on your setup, but you might be able to monitor the processor status through htop on your caching instance. If so, you should see redis show up in the process list as it processes the large request set.
    4. Here are my values (for comparison)
      1. 500 requests: 0.0202 0.0162 0.0172 0.0142
      2. 10000 requests: 0.3055 0.3017 0.2946 0.3084
      3. 100000 requests: 3.2092 2.9187 3.0452 3.1045
  4. Verify Redis is properly handling the requests using redis-cli monitor 
    1. https://redis.io/commands/monitor
    2. This is from our VPS:
1531191276.803634 [0 127.0.0.1:38460] "PING"
1531191276.803894 [0 127.0.0.1:38460] "SETNX" "bm_moodlean1nng1eq5a49kqhctil830gn4.lock" "s:1:\"1\";"
1531191276.804052 [0 127.0.0.1:38460] "EXPIRE" "bm_moodlean1nng1eq5a49kqhctil830gn4.lock" "7200"
1531191276.804179 [0 127.0.0.1:38460] "GET" "bm_moodlean1nng1eq5a49kqhctil830gn4"
1531191276.804351 [0 127.0.0.1:38460] "EXPIRE" "bm_moodlean1nng1eq5a49kqhctil830gn4" "7280"
1531191276.810255 [0 127.0.0.1:38460] "SETEX" "bm_moodlean1nng1eq5a49kqhctil830gn4" "7280" "s:228:\"USER|O:8:\"stdClass\":2:{s:2:\"id\";i:0;s:10:\"mnethostid\";s:1:\"1\";}SESSION|O:8:\"stdClass\":3:{s:4:\"lang\";s:2:\"en\";s:8:\"wantsurl\";s:29:\"https://moodle.my-instance.com/\";s:7:\"fromurl\";s:44:\"https://moodle.my-instance.com/cache/admin.php\";}\";"
1531191276.810391 [0 127.0.0.1:38460] "DEL" "bm_moodlean1nng1eq5a49kqhctil830gn4.lock"

When I logged in, it set (and cached) a very code containing all of the admin user information:

"s:3485:\"USER|O:8:\"stdClass\":60:{s:2:\"id\";s:1:\"2\";s:4:\"auth\";s:6:\"manual\";s:9:\"confirmed\";s:1:\"1\";s:12:\"policyagreed\";s:1:\"0\";s:7:\"deleted\";s:1:\"0\";s:9:\"suspended\";s:1:\"0\";s:10:\"mnethostid\";s:1:\"1\";s:8:\"username\";s:11:\"bm_admin\";s:8:\"idnumber\";s:0:\"\";s:9:\"firstname\";s:11:\"bm_admin\";s:8:\"lastname\";s:5:\"Admin\";s:5:\"email\";s:21:\"admin@my-instance.com\";s:9:\"emailstop\";s:1:\"0\";s:3:\"icq\";s:0:\"\";s:5:\"skype\";s:0:\"\";s:5:\"yahoo\";s:0:\"\";s:3:\"aim\";s:0:\"\";s:3:\"msn\";s:0:
.
.
.
:16:\"contexthasrepos5\";a:3:{i:0;i:1531191348;i:1;s:1:\"2\";i:2;s:4:\"b:0;\";}}}s:21:\"load_navigation_admin\";i:1;}\";"
1531191351.701704 [0 127.0.0.1:38526] "DEL" "bm_moodledvd4lh4j0cq98qi6g18aaikmv5.lock"

Finally, here are the settings in the config.php file (mostly default):

//   Redis session handler (requires redis server and redis extension):
$CFG->session_handler_class = '\core\session\redis';
$CFG->session_redis_host = '127.0.0.1';
$CFG->session_redis_port = 6379;  // Optional.
$CFG->session_redis_database = 0;  // Optional, default is db 0.
$CFG->session_redis_auth = ''; // Optional, default is don't set one.
$CFG->session_redis_prefix = 'bm_moodle'; // Optional, default is don't set one.
$CFG->session_redis_acquire_lock_timeout = 120;
$CFG->session_redis_lock_expire = 7200;

I hope this helps!

Average of ratings: Useful (2)
In reply to Tony H

Re: Help with Redis cache

by Alan CF -

Hi Tony,

Thanks for your detailed explanation!

I solved my problem a while ago. Turns out I hadn't configured the Redis store properly in Moodle.