Memcache and load balanced web servers

Memcache and load balanced web servers

by jonny fireblade -
Number of replies: 9

Hi

 

I have just read somewhere that one should use memcache when load balancing requests between multiple web servers from Moodle 2.5 and beyond

Is this really necessary? or is it mainly related to performance

 

Cheers 

Average of ratings: -
In reply to jonny fireblade

Re: Memcache and load balanced web servers

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

It is related to performance and it's almost certainly necessary.

The issue is that if you have load balanced web servers you must be using a shared directory for Moodle's data area. This is what - NFS or even worse? These directories tend to have very slow access times which isn't too bad for ordinary files but is a disaster for caching - which is written to disk in the shared data area by default.

As the caching has to be shared (it's more complicated than that but this assertion will do for the purposes of this discussion) you really want to be using a fast cache solution. A good choice is memcached (as opposed to memcache which is different).

The difference can be quite dramatic. Your site will work without it but could well be miserably slow. 

Average of ratings: Useful (3)
In reply to Howard Miller

Re: Memcache and load balanced web servers

by Anna Jonna Ármannsdóttir -

I have a successful setup of Moodle 2.6 with Memcached (MemcacheD). Each cache store, is configured with two lines of IPv4 numbers (I want to limit the testing to IPv4 for the moment). Does that automatically give me redundancy, meaning that all cache data will be written simultaneously to both servers (like identical twins), or will it just use both Memcahced servers as individual caches (as in siblings)?

I have not yet managed to find this in the documentation.

Also I can not get the same setup to work on Moodle 2.4. I have been looking everywhere for some documentation regarding Memcached and Moodle 2.4 but I have not yet managed to find helpful documentation on the subject. Could You point me to the right direction? Best regards, Anna.

In reply to Anna Jonna Ármannsdóttir

Re: Memcache and load balanced web servers

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

As far as I know - that's not the way memcached works. If you have multiple servers the memcached will load-balance across them. It, presumably, hashes the data to be cached and does a 'modulo n' to decide which one to use. What it doesn't do is to duplicate the data. 

The point here is that if one server fails, you only have half a cache (e.g. if you have 2 servers). Half of your cache hits will fail. This requires manual intervention to either fix it, or reduce the number of servers in the client setup.

I've had it working on 2.4 although the MUC features in 2.4 are quite limited. 

In reply to Howard Miller

Re: Memcache and load balanced web servers

by Anna Jonna Ármannsdóttir -

Many thanks for Your reply. I am considering not using MUC in Moodle 2.4 and just config memcached through the config.php file. I guess that the config for multiple Memcached servers, the config would be a comma separated list but I not yet found rules for the syntax. I guess it would be like this:

$CFG->memcachedhosts= '1.2.3.4,5.6.7.8:11212,9.0.1.2';

At least this is the syntax I have seen in libmemcached.

Best regards, Anna.

In reply to Anna Jonna Ármannsdóttir

Re: Memcache and load balanced web servers

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Are you aware that the MUC is configured by a special config file that lives in your moodledata area. The path is...

$CFG->dataroot . '/muc/config.php'

I don't have any particular insight into the contents but it looks (at a glance) reasonably intuitive. 

By the way, if you mess up the MUC configuration, you can just delete this file and it will be recreated with default settings smile

Average of ratings: Useful (3)
In reply to Anna Jonna Ármannsdóttir

Re: Memcache and load balanced web servers

by Ryan-Neal Mes -

Hi there,

Did you ever manage to figure out how to have multiple memcachedhosts?

We would like to leverage two of our servers as memcached servers, but are unsure how to keep them in sync or specify two memcachedhosts like you have in the reply above. We tried this with no luck.

Is there a way to do it?

Thanks.

In reply to Howard Miller

Re: Memcache and load balanced web servers

by jonny fireblade -

Well we have shared disk on a SANs using OCFS2 clustered file system so much faster than NFS

Might test to see if there are any performance differences but with regards to the slowness I dont think I will be affected.

Cheers

In reply to jonny fireblade

Re: Memcache and load balanced web servers

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

As long as you are *sure* but SAN is still likely to be a good deal slower than local disks. On a busy system (which presumably it is) you may see a difference.

Obviously, it's up to you but if you get big page load times then you'll know where to look first wink

In reply to jonny fireblade

Re: Memcache and load balanced web servers

by Anna Jonna Ármannsdóttir -

Thanks for this interesting discussion. smile I just recently put one of my production servers under a huge NFS load an it showed an impressive performance. The peak performance in total was about 1800 OPS/second. =o) Of that there were 203 OPS/s read and 83 OPS/s write. And the underlying disks  one the NFS server are fiber connected SCSI disks, in a RAID5. I think the explanation is that NFS reads and writes can use the host RAM as cache. 

My experience tells me, that it is very expensive (at least 4 or 5 spindle RAID5 or RAID6 locally) to get a disk performance in the vicinity of 400 OPS/s but memcached gets you a performance that is way beyond that at a fraction of the cost. 

Best regards, Anna.

Average of ratings: Useful (3)