It only needs to be configured in your config.php file and Moodle will then properly override your PHP session save handlers.
It only needs to be configured in your config.php file and Moodle will then properly override your PHP session save handlers.
When you configure inside Moodle admin, this is only for the Moodle MUC Session cache (different to PHP sessions).
To enable Redis for PHP sessions (log in persistence), this needs to be configured in the config.php file using the settings I listed above.
In the example you sent, it shows session settings in databse and file, I'm putting it as I found it in config-dist
I'm configuring with the data below:
// $CFG->session_handler_class = '\core\session\redis';
// $CFG->session_redis_host = 'redis.server.com';
// $CFG->session_redis_port = 25061; // 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 = ''; // Optional, default is don't set one.
// $CFG->session_redis_acquire_lock_timeout = 120;
// $CFG->session_redis_lock_expire = 7200;
// Use the igbinary serializer instead of the php default one. Note that phpredis must be compiled with
// igbinary support to make the setting to work. Also, if you change the serializer you have to flush the database!
// $CFG->session_redis_serializer_use_igbinary = false; // Optional, default is PHP builtin serializer.
I noticed that when the server name goes wrong it looks like this: Redis server went away
When I put the correct server, the error presented looks like this:
Read error on connection
I believe that the server data is ok, because when changing the url of the redis server it accuses the error "Redis server went away", when I put it right, I don't understand why it doesn't work and gives the error "Read error on connection"
Thank you very much for your help.
$CFG->session_handler_class = '\core\session\redis';
$CFG->session_redis_host = 'IP ADDRESS';
$CFG->session_redis_prefix = 'PREFIX PER SITE';
We are using the default port so that doesn't need to be specified, but yours would be if you're using 25061. We also have multiple sites on the same instance so we use a prefix per site.
This instance only does PHP session data, there are other Redis instances for the MUC Application and MUC Session cache.
Is it possible to use an IP over a hostname, and are you able to install the Redis CLI tools to verify that you can actually communicate with the instance before configuring Moodle?
Tested the instance of redis that we use as a service, used redis-cli and it worked.
It actually works on a specific port, until then we used the same instance for MUC that seems to have worked, but for PHP sessions it doesn't, it gives this error when active in config.php "Read error on connection", I tried to remove some of the settings keeping , host, port and prefix, however, the error persists.
We continue with the error of the Cannot find session record xxxxxxxxxxxxxxxxxxx for user xxxxx.
I believe that the redis for PHP sessions will help us, but it is somewhat difficult to configure.
If you can help me, your apache, is configured for how many connections, here I use mpm_profork like this:
I'm thinking of leaving only one server with a better configuration without having to use nfs to share the cache and session, currently we have 1,000 simultaneous connections.
Mr. V's commented on this in the first interactions and only now that I understood that a single node with greater capacity could be better, I can't do the version update right away, I think it could be a way out ?!
What does 1000 simultaneous mean to you? Is that 1000 users on the site at the same time (in the last 5 minutes), 1000 users clicking through to start an exam at the same time, or 1000 users enrolled in a course and probably not online at the same time.
We can manage around 1000 users starting a quiz at the same time using NFS so that isn't going to be your issue. BUT it's a much easier set up if you don't have to manage multiple instances.
First step, don't use Apache Prefork. You need to be looking at the Event MPM and then also set up PHP-FPM for requests to be proxied to it.
The default Event/PHP-FPM config can only do about 100 concurrent users according to anecdotal evidence seen here on the forums. I have other replies to threads where the how to on configuring these is explained. There are also numerous good guides on that.
The main point, if DB is on your single server too, you need to account for all RAM to be less than OS + DB + Apache + PHP otherwise you will start to swap memory and that is bad.
The actual configuration of Event/PHP/MySQL will depend on your DB size, memory available, disk speed (and mechanical/SSD), CPU cores, etc.
Back in regards to Redis, if you are using it on the same instance as the MUC, the MUC will do cache purges and that will then also purge your user sessions. With Redis you should be able to use a different prefix and get around that, but to make more use of Redis being single threaded, we run three different Redis instances. That way each instance has their own purpose and specific configs.
I believe that I can reach 1000 simultaneous yes, we have 6000 registrations and in the hour of class 1000 access this time on average.
Could you send me the link to the post where you talk about configuring php-fpm?
Our postgres works in digitalocean as a service, we have 4 nodes, in the first one the application (apache + php + nfs-server) and in the others (apache + php + client-nfs) and of course, connection to the postgres database as a service.
As for redis, now the issue of the prefix or separate instances has become clear, preventing sessions from being deleted if I manage to configure them. However, I can't make the connection, I'm going to create a new test instance, maybe that's one of the reasons, I have already configured it in MUC, I don't know if this could cause a connection error.
In the config.php file, you only need to specify the session class (Redis), IP/name and Port. They should be fine on a single instance but we can't see how it affects your instances. It could be a networking issue, set up issue, Digitial Ocean issue etc.
Quizzes are very resource intensive so I'm not sure if your current specs are enough without it going through some testing first. You can always try (with lots of monitoring enabled) and see what breaks first (SQL, Web, PHP, disk, etc) and work on fixing those bottlenecks.
There are lots of good guides to search for on how to properly configure Apache MPM Event and PHP-FPM for performance. As you have web only nodes, it's a bit easier as you only need to work out how much RAM a PHP process takes up, then divide that by your total RAM (minus some for the OS to run). That then defines your max PHP workers.
Apache in Event MPM doesn't take that much resources, so you may only need to raise the max clients or the specific config which relates to that (I don't remember it off the top of my head).
Does Digital Ocean give you any ability to make performance improvements to their PostregSQL as a service? I know there were changes necessary in MySQL to do this but given it's 'as a service' I don't know what they offer.
If Redis as a service with Digital Ocean isn't working you could run some small VMs with a single core to work as your Redis service as well.
Once you move to PHP-FPM, you also get the benefit of configuring PHP Opcache as allowing it to use a shared cache as that doesn't work with preform (I believe, or work as well).
Also look at confirming/fixing that you're on NFS4 to get the benefit of file locking in Moodle Data. Looking at all these things will allow you to have a higher number of concurrency. When you find that limit then you can add more resources and edit the configs to take the new resources into account.
About the MUC cache I don't know if mine is working, it shows as in this attached image, it shows that there are Cache stores installed, but further down in Instances of configured stores, all show 0 (Zero) I believe it is not working.
In the cache performance test, it shows: Storage is not ready.
My config.php for PHP session does not work, I have analyzed in more detail it did not work, and the same settings using redis-cli work, I did not understand, I will get more up.
I couldn't identify what gives the problem first, but today I started to suspect postgres, digitalocean does not allow adjustments to the database as a service.
I managed to adjust a PHP-FPM in the apahe, I used this guide, which is very similar to the calculations suggested: https://medium.com/@sbuckpesch/apache2-and-php-fpm-performance-optimization-step-by- step-guide-1bfecf161534
NFS4 was a suspicion if nfs was causing me session problems, but I don't know if it's postgres that is giving me a bottleneck problem in moodle, the question is that the error presented is: Cannot find session record, I believe it is NFS, if nfs4 handles file locking well, I believe that for the amount of my base it would be enough.
It seems to me that something crashes and the connections followed start to overload the database.
As I do not have management of the database, nor to kill the connections that may be problematic with you, to know if they really lock some table or something like that.
I also ran a benchmark and it looks good, attached too.
I've used jmeter to try to simulate the problem but I couldn't.
- install the PHP module, enable it and reload PHP
- go to phpinfo in Moodle and make sure it shows Redis as enabled
- in Moodle, Plugins -> Caching -> Cache stores -> Redis, add your server and port
- Plugins -> Caching -> Test Performance, you can now simulate requests to show Redis vs other stores (note this hasn't actually configured anything for the MUC yet)
- Plugins -> Caching -> Configuration, Add a new Redis cache store instance (same details as above)
- Either edit individual known cache definitions to map to the new Redis instance, or scroll to the bottom and select "Edit Mappings" under "Stores used when no mapping is present", select Redis for the Application drop down and leave the rest.
If for some reason it all goes wrong, delete this file in the Moodle data directory "/moodledata/muc/config.php"
It's possible that the version you're on has issues with Redis sessions, I started using them from 3.5 but also brought in lots of fixes/improvements from later releases too.
I had a quick look at that guide and it's looks pretty good. It's a good base to start at least and then you can monitor memory/cpu to make sure at peak time you don't overcommit.
With lots of concurrent connections, sessions are going to be one of your pain points, especially on NFS. I not Redis, also try memcached but we moved from memcached to Redis at 3.5. Also check these instructions or similar to make sure you're on NFSv4 in your fstab file https://help.ubuntu.com/community/NFSv4Howto
Lots of database connections when seen at periods of slow downs are normally not DB related. For example a slow process, disk issue, overloaded web servers etc all will mean there are more and more requests coming in but none getting released once they finish. This then builds up requests on the DB server and may overload that too.
I did all this process of configuring the cache by the end of the page to choose the application and session cache, however, after that I can understand that redis is working?
How could I confirm that the MUC cache worked?
I attach the image with the final part configured.
I deleted the config file and configured it again, however, I can't identify who is using redis.
If by chance you should show it at: redismuccentral Redis = 1 for storage mapping, it is zero in my printout, maybe something from the version, could you confirm how it looks in storage mapping?
I also think that it may be the sessions that end up doing this to keep connections stuck and look like the database, let's see if I manage to put the redis should minimize.
On the NFS4 attached an image I believe it is ok see with nfs4.
You could also try to turn on debugging and performance info to see if that shows you any extra information as well.
When we have mapped all the Application caches when no cache is present to Redis, it also shows as 0 mappings as that would be individual mappings. In this scenario, with 0 mappings mapped, it will default to Redis rather than file caching.
The Session cache inside MUC is not for PHP sessions / log in persistence, it's a separate Moodle MUC cache that is only used for that session.
There was a forum post not that long ago about issues with having the MUC Session and Application caches together on the same Redis instance, but I can't remember which one. In your case you most likely won't need the MUC Session cache until you get to Moodle 3.9 when Read Only Sessions becomes available.
The NFS config also looks good. If that's only used for the Moodle data dir then you should be fine.
I don't really know how to do any more testing for PHP sessions in the config.php file, unless you see if running another Redis instance works, or if running one locally also works. If you get it working, it should be a good performance improvement.
When the MUC Cache is working will the $CFG->cachedir folder no longer be used?
Because from what I understand the ideal is to let write to disk just file right?
I will try to put PHP sessions on redis again.