[Koha-patches] [memcached 0/2] RFC: Optional memcached Support for Koha

John Beppu john.beppu at liblime.com
Wed Feb 4 10:35:30 CET 2009


This set of patches introduces optional memcached support for koha.
To make use of this new functionality, you need to have the following
software installed:

  - Cache::Memcached::Fast
    http://search.cpan.org/dist/Cache-Memcached-Fast/
  - memcached
    http://danga.com/memcached/

You should also add the following lines to your koha-conf.xml file
inside the <config> block:

  <memcachedserver>localhost:11211</memcachedserver>
  <memcachedpreferencenamespace>preference:</memcachedpreferencenamespace>
  <memcachedmiscnamespace>misc:</memcachedmiscnamespace>

----

Keep in mind that all this is optional, and koha will continue to work
just as before if you don't have memcached support setup.

However, if you *do* have these installed, this set of patches will
speed up koha's request rate by about 10%.  This was accomplished by
using memcached to cache the data returned by the following code:

  - C4::Context->preference($var)
  - C4::Languages::getAllLanguages()

If you've ever looked through your MySQL query logs (which happen to be
located at /var/log/mysql/mysql.log on my system), you'll have noticed
that these two functions generate a large number of database queries
that get repeated over and over again for every request that's made to
the web server.  However, with memcached support in place, the number of
queries those functions generate is drastically minimized.  To
illustrate this point, take a look at the following links.

The query log for a typical request went from looking like:

  http://gist.github.com/raw/58024/1479f751caee95693ae8d6664a103e194536da0e/00-request-without-memcached.txt

to looking like:

  http://gist.github.com/raw/58024/ae28d0298ecc8e0e209a446e428dfd6f2a1a774c/01-request-with-memcached.txt

That's 218 queries per request being reduced to 28 queries per request
(for koha/mainpage.pl).


--beppu


PS:

  I added a C4::Context->memcached($namespace) method that returns a
  Cache::Memcached::Fast object when possible.

  The namespaces I've defined so far are "preferences" and "misc".

  (That's what the new lines in koha-conf.xml are for, and adding new
  namespaces is just a matter of adding another <memcached${x}namespace>
  tag to koha-conf.xml.)

  The "preferences" namespace is intended to be used exclusively by
  C4::Context->preference and "misc" is a free for all that I currently
  use for C4::Languages::getAllLanguages().


John Beppu (2):
  Use Memcached When Available
  Clearing Cached Data When System Preferences Are Changed

 C4/Context.pm              |   88 ++++++++++++++++++++++++++++++++++++++------
 C4/Languages.pm            |    8 ++++
 admin/systempreferences.pl |    4 +-
 etc/koha-conf.xml          |    5 ++
 4 files changed, 92 insertions(+), 13 deletions(-)



More information about the Koha-patches mailing list