How do I use memcache?

How do I use memcache?

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

(2.4.4) I've been looking at the spectacularly confusing cache admin screen again. 

If I want to use memcache rather than file storage for caching how do I do it? It says I have memcache installed but edit mappings doesn't let me change anything. There is no documentation (Grrrrr...) so... any takers???

I'm entirely sure (as usual) that I am even asking a sensible question wink

Average of ratings: -
In reply to Howard Miller

Re: How do I use memcache?

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

1. at the top of the page, where it says Installed cache stores -> Memcache (or Memcached depending on which PHP extension you are using), click Add instance and put in the details of you memcache server.

2. Lower down, click Known cache definitions -> Question definitions (or whatever) -> Edit mappings. Selete the newly created memcache store there.

I would very strongly recomment you run load-testing while you are experimenting with these options. The results are not always obvious. For example, if you use Memcache so much that you overload your memcache server, then performance really sufferes.

Average of ratings: Useful (1)
In reply to Tim Hunt

Re: How do I use memcache?

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

Hi Tim,

It turned out that I didn't have memcache installed properly. On a usability point, I can't help thinking that this screen should tell you that. To the uninitiated it does look like these cache methods are actually available. 

Yes - I plan to take your advice. We are upgrading our load-balanced 2.3 site to 2.4 and want to be ready for any trouble wink

 

In reply to Tim Hunt

Re: How do I use memcache?

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers

Tim, when you say "at the top of the page" which page are you referring to?

Are these cache setting in Moodle's System Administration, or are the somewhere else on the server?

Thanks.

In reply to Rick Jerz

Re: How do I use memcache?

by Andrea Bicciolo -
Hi Rick,

if you are running a 2.4.x Moodle instance, you find the cache administration pages in "Site administration > Plugins > Caching".

Average of ratings: Useful (1)
In reply to Andrea Bicciolo

Re: How do I use memcache?

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers

Thanks for the location.

Now, I just have to figure out if I can implement some of the things that Tim suggests.  I too (like Howard), see that I have an "invalid plugin" showing.  So I have to explore the Moodle docs to learn about these settings, and figure out if I can implement them on my server.

Howard (and others), was it easy to install this plugin?  Any pointers, or warnings?

In reply to Rick Jerz

Re: How do I use memcache?

by Andrea Bicciolo -
Rick,

where are you getting "Invalid plugin" ? From the "Test performance" page ? If yes that should means you did not configure that cache plugin. For example on a test server I get "Invalid plugin" for MongoDB plugin in the "Test performance" page, however I did not configure MongoDB at all (I configured memcahce) so I suppose it is pretty normal.

If you properly installed memeched daemon and php5-memcached (or php5-memcache), from the cache "Configuration" page you should be able to add a memcahed (or memcahce) instance, then edit mappings accordingly.
In reply to Andrea Bicciolo

Re: How do I use memcache?

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers

Yes, from the "test performance" page.

I am not smart enough yet to figure out how to properly install memeched, but here (below) is what part of my configuration shows.

I might try to follow Tim's directions on my experimental install.

Thanks.

 

 

Attachment cache configation.jpg
In reply to Rick Jerz

Re: How do I use memcache?

by Andrea Bicciolo -
From the screen shot provided looks like you do not have any additional plugins, only the default ones are available.

If you are running a linux box, there are very good chances your distribution already has a memcahced package, for example on a Debian 6 "Squeeze" box you can just install and start memcached with a default configuration using the following command:

# apt-get install memcached

Then you need to install php5-memcache or php5-memcached modules, and also in this case most linux distros provide their packages. Once memcached and related php module are both installed (remember to restart your web server), access again the Moodle cache configuration page, you should see a green check mark and the "Add instance" link for the corresponding memcache or memcached plugin.
In reply to Andrea Bicciolo

Re: How do I use memcache?

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

Yep - the above is exactly what I had to do on an Ubuntu box and it worked fine. 

It's one of those "obvious when you have done it" things. Unfortunately there seems to have been some insanity at large in the naming of the various memcache (and memcached) bits. 

I'm getting a bit worried about all this. Like Tim, I'm running a load balanced server and my options seem to be caching on a NFS share or on memcache a memcache(d ?) server over the network. Neither sound like the world's greatest idea if I'm honest. 

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

Re: How do I use memcache?

by Andrea Bicciolo -
Hi Howard,

you are worried by naming of the pluigns "memcahce" and "memcahced" ? For sure the naming of the two different php modules are confusing, they refer to the corresponding php5 module you installed on your server. In many situations either php5-memcache and php5-memcached will work both just fine (provided you installed memcached daemon), however php5-memcahced supports more features than php5-memcahce, and more features are available when adding php5-memcahced store instance in Moodle instead of php5-memcahce.

About a load balanced cluster of web server, well yes you can use a networked memcached server shared among all balanced web servers, however I was just wondering if we could configure a memcached daemon locally for each balanced web server instead. That way it would not possible to take advantage of cache sharing options available in Moodle 2.5, however in the counterpart there is a reduction of number of servers involved, reduction of a SPOF if memcahced server is not redundant, and elimination of network latency. Could be interesting to give it a try.
Average of ratings: Useful (1)
In reply to Andrea Bicciolo

Re: How do I use memcache?

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers

How does one know if they are running the memcached deamon?  Should this show if I run the "TOP" command?  Or is there a better way to know this?

Thanks for your insight.

In reply to Rick Jerz

Re: How do I use memcache?

by Andrea Bicciolo -
Rick,

on a linux box you could check if you are running memcached deamon using a command like the following:

# ps aux | grep memcached

If memcached is running, you should get two output lines, with one similar to the following:

..... 474 0.0 0.7 101112 15684 ? Sl Apr29 1:07 /usr/bin/memcached -m 196 -p 11211 -u ....
In reply to Andrea Bicciolo

Re: How do I use memcache?

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers

Andrea, thanks much.  I get the following, which suggests that I do not have memchached running.  Hmmm, now let me learn what it takes to turn memchached on.  I am now going to have to try to turn it on following your advice from above.  As a novice UNIX admin, how safe is this procedure?  Can I do harm to my VPS?

Output = "rjerzcom 26224  0.0  0.0   6372   696 pts/0    S+   08:33   0:00 grep memcached"

In reply to Rick Jerz

Re: How do I use memcache?

by Andrea Bicciolo -
Rick,

yep, looks like you do not have memcached running .About installing it, I think it is much better if you try installing memcached on a test server, so you can play around with it without affecting you production environment.
In reply to Andrea Bicciolo

Re: How do I use memcache?

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers

That's exactly what I was thinking!

Memcached appears to be a "server" based change, as opposed to a domain based change.  So I think that I will want to do this on a completely different server than where I have my production Moodle installation.  Right?

In reply to Rick Jerz

Re: How do I use memcache?

by Andrea Bicciolo -
Hi Rick,

yes, generally speaking installing memcahced implies a server side change, although such an installation should not harm, it is another process running on the system and asking for resources. Always better testing on a separate server.
In reply to Andrea Bicciolo

Re: How do I use memcache?

by srikanth raju -

Hi Andrea, 

     I have also similar problem which is related to memcache. I installed php5-memcache, php5-memcached, memcached. But in moodle, i am not getting green tick mark as memcached plugin which is shown in image

memcached-enabling



When i try to check php5-memcache, memcached and php5-memcached in command line then i am getting as newest version is available. 


memcached

memcache

php memcached

Please tell me, how can i enable these memcached ? Am i doing anything wrong ?




In reply to srikanth raju

Re: How do I use memcache?

by Luis de Vasconcelos -

Run PHPInfo() and check the output. Does it show a Memcache or Memcached section (or both)?

In reply to srikanth raju

Re: How do I use memcache?

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

Did you restart apache?

sudo service apache2 restart

??

Failing that it's worth restarting memcached which should tell you if something is wrong with that...

sudo service memcached restart