I set up Moodle on AWS, here is the spec:
- Auto Scaling Web Server group with Application Load Balancer running two EC2 Ubuntu instances that host identical Moodle app clones.
- Multi AZ RDS MySQL database.
- Two Multi AZ ElastiCache Memcached clusters, each having two nodes
- EFS for shared file system
- All of the above use free tier instance types (t2.micro) for now
As a disclaimer, I am by no means experienced in AWS or deploying whole web apps such as Moodle, I built this infrastructure based on few weeks of self-learning how AWS works and doing research on what Moodle requires to operate well.
Currently I've got Moodle with just one very simple test course added and few test users created.
In the documentation I've read about two main cache types for which Memcached can be used, that is "Application" cache and "session" cache. I am not sure if I am correct but MUC appears to be system that controls all these caches...
Now, I managed to set one of the ElastiCache clusters as cache store mapped with application cache. Using ElastiCache for application cache improved performance drastically.
The problem is, I cannot get the session cache to use the second ElastiCache cluster. Each time I try to use ElastiCache for it I keep getting logged out of my account randomly with a message stating my session has timed out. Here's what I attempted:
In config.php file of both Moodle instances I added this code:
$CFG->session_handler_class = '\core\session\memcached';
$CFG->session_memcached_save_path = 'xxx-xxx-xxx-xxx:11211';
$CFG->session_memcached_prefix = 'memc.x.sess.key.';
$CFG->session_memcached_acquire_lock_timeout = 120;
$CFG->session_memcached_lock_expire = 7200; // Ignored if memcached extension <= 2.1.0
At first I have done all of the above without adding session cache store in Site administration -> Plugins -> Caching -> Configuration. However, when that didn't work out, I went into the caching configuration menu on Moodle and added another "Memcached" cache store with the endpoint and port same as specified in the config.php. This didn't do anything, but then I thought that maybe I need to edit mappings to make this new cache store as default for "Session" cache, just like I did with other one for "Application" cache. The problem here is that "Memcached" cache stores have only "Application" as a mode, so I cannot map this store with "Session" cache.
In the screenshot below you can see two store instances, one for "Application" cache called "muc-cache". Other one for "Session" cache called "session-cache" which I cannot actually map.
Any ideas why I have this random log out issue with session cache? Can you let me know if I've been doing anything wrong, or suggest anything based on what I've already done? One more thing I thought about is that both my ElastiCache instances use 11211 port, even though they have different endpoints. Could that cause an issue? If so what other ports can I use for Memcached?