How to setup memcached with Moodle?

How to setup memcached with Moodle?

oleh Pál Csányi -
Jumlah balasan: 6

Hi,

on my Raspberry Pi 2 Model ( with installed Gentoo linux operating system ) I have set up a running Moodle site.

I'm trying to set up here Moodle to use memcached.

I think this way I can speed up my little Moodle site: http://www.cspl.hu/moodle .

My setup is not working yet so I commanted out these lines in nginx.conf:

#           location / {
#               set            $memcached_key "$uri?$args";
#               memcached_pass unix:/var/run/memcached/memcached.sock;
#           }

Simptoms are, when these line are uncommented:

http://www.cspl.hu has no light green background,

http://www.cspl.hu/moodle site does not work at all.

What I did sofar are..

Installing packages:

emerge -aj dev-libs/libevent
emerge -aj net-misc/memcached

edit /etc/conf.d/memcached
LISTENON=""
SOCKET="/var/run/memcached/memcached.sock"

/etc/init.d/memcached start

edit /etc/nginx/nginx.conf
server {
                listen 80;
                                server_name www.cspl.hu;
                etc.

               location / {
                   set            $memcached_key "$uri?$args";
                   memcached_pass unix:/var/run/memcached/memcached.sock;
               }

      }

edit /etc/shorewall/rules
# memcached                                                                                                     
ACCEPT          $FW             net     tcp     11211
ACCEPT          $FW             net     udp     11211

In my Moodle site administration try to see whether memcached works, but do not understand what should I do here in the Moodle Administration?


What should I do more to get my Moodle site running with memcached?

Best, Pali

Rata-rata penilaian: -
Sebagai balasan Pál Csányi

Re: How to setup memcached with Moodle?

oleh Matteo Scaramuccia -
Gambar dari Core developers Gambar dari Peer reviewers Gambar dari Plugin developers

Hi Pál,
you need to install the memcached daemon and keep it closed to localhost (i.e. no need to open the access to others than localhost by means of the local firewall).
Check what could be the amount of RAM to be granted to the memcached daemon: you should try using 64MB but it could be better to increase the size to 96-128MB.

Then you need to install the PHP extension, typically Memcached, to access the memcached daemon from PHP.

That being said, Moodle could benefit from the memcached daemon for:

If you want to use it for both the Moodle internal systems above, you need to use two separate instances of the memcached daemon.

Please, remember that the first method to improve performances is to double check that your Moodle instance is using a PHP accelerator like OPcache. Then you should evaluate the right amount of memory to be reserved for the database server.

HTH,
Matteo

Rata-rata penilaian:Useful (2)
Sebagai balasan Pál Csányi

Re: How to setup memcached with Moodle?

oleh Paul Verrall -

Hi Pál,

I think you are going about this the wrong way. I don't think Nginx memcached module is suitable for Moodle. Moodle has it's own integration with memcached in the backend, and to quote from the docs for the nginx module docs...

"The ngx_http_memcached_module module is used to obtain responses from a memcached server ... A response should be put in memcached in advance by means external to nginx."

*means external to nginx* i.e. nginx does not manage the contents of memcached; only serves it.


TBH I stopped using memcached for moodle on my raspberypi deployment at moopi.uk (although this is not documented) and instead use a tmpfs with the default 'filesystem' cache for MUC.

As Matteo says your big and quick wins are in Opcache. In addition to that PHP7 gives a ~30% speed boost too if you can use it (I really have no clue when it comes to Gentoo!).

Rata-rata penilaian:Useful (2)
Sebagai balasan Paul Verrall

Tárgy: Re: How to setup memcached with Moodle?

oleh Pál Csányi -

Hi Matteo and Paul,

OK, then I will uninstall memcached and continue using just the PHP installed with opcache USE flag.

Here, on Gentoo linux the PHP version 7 is not yet the stable package, but is in the test branch.

# eix dev-lang/php
[I] dev-lang/php
     Available versions: 
     (5.4)  [M]5.4.45
     (5.5)  5.5.33 5.5.34
     (5.6)  5.6.19 5.6.20

     (7.0)  ~7.0.5

Installed versions:  5.6.20(5.6)(10.54.17 2016-05-02)(berkdb bzip2 cli crypt ctype curl fileinfo filter fpm gd gdbm hash iconv intl ipv6 json nls opcache phar posix postgres readline session simplexml soap ssl tokenizer truetype unicode xml xmlrpc xpm zip zlib -apache2 -bcmath -calendar -cdb -cgi -cjk -debug -embed -enchant -exif -firebird -flatfile -frontbase -ftp -gmp -imap -inifile -iodbc -kerberos -ldap -ldap-sasl -libedit -libmysqlclient -libressl -mhash -mssql -mysql -mysqli -oci8-instant-client -odbc -pcntl -pdo -qdbm -recode -selinux -sharedmem -snmp -sockets -spell -sqlite -sybase-ct -systemd -sysvipc -threads -tidy -vpx -wddx -xmlreader -xmlwriter -xslt)

I think is will be soon in the stable branch.


Thanks!

Sebagai balasan Pál Csányi

Re: Tárgy: Re: How to setup memcached with Moodle?

oleh Matteo Scaramuccia -
Gambar dari Core developers Gambar dari Peer reviewers Gambar dari Plugin developers

Hi Pál,
that's good setuju Ya.
It's quite strange that PHP 7.0.6 is not considered stable yet.

BTW, please adopt Paul advice to let the default caching file store run as fast as possible by using tmpfs. See also https://docs.moodle.org/30/en/MUC_FAQ#What_is_wrong_with_the_default_file-system_MUC.3F and https://docs.moodle.org/30/en/MUC_FAQ#How_can_I_make_MUC_faster.3F.

HTH,
Matteo

Rata-rata penilaian:Useful (1)
Sebagai balasan Matteo Scaramuccia

Tárgy: Re: Tárgy: Re: How to setup memcached with Moodle?

oleh Pál Csányi -

Hi Matteo,

I just complete my Moodle site's setup by following

https://docs.moodle.org/30/en/MUC_FAQ#What_is_wrong_with_the_default_file-system_MUC.3F and https://docs.moodle.org/30/en/MUC_FAQ#How_can_I_make_MUC_faster.3F.

Steps I performed for this are on my Gentoo system:

  • emerge -aj net-misc/memcached dev-php/pecl-memcached
  • nano /etc/conf.d/memcached
    MEMUSAGE="128"
    PORT="11211"
    SOCKET="/var/run/memcached/memcached.sock"
  • /etc/init.d/memcached start
    rc-update add memcached default
  •  In Moodle
      * 'Site administration > Plugins > Caching > Configuration'
      * Under Installed cache stores look for Memcached and click the Add instance action.
      * Give the store a name, like 'Memcached_MUC'
      * In server, assuming the basic config above, type 'localhost'. Save Changes.
        This step I did leave out, because I don't understand where to do it?
      * Scroll to the bottom of the Cache administration page.
      * Under Stores used when no mapping is present click Edit Mappings.
      * In the Application drop down select the caches name. Save Changes.

What I don't know is that that how can I use tempfs for the default caching file store?


Best, Pál

Rata-rata penilaian:Useful (1)
Sebagai balasan Pál Csányi

Tárgy: Re: Tárgy: Re: How to setup memcached with Moodle?

oleh Pál Csányi -

OK,

what I did to set up tempfs for the default caching file store are followings:

added in to  /etc/fstab:
tmpfs                   /tmp            tmpfs           nodev,nosuid,size=128M  0 0
reboot the system

In Moodle
Dashboard > Site Administration > Plugins > Caching > Configuration / File cache / Add Instance:
Store name: add some name
Cache path: /tmp
Save Changes.

Is this the right setup?

Best, Pál