Memcached on 1and1 with MediaWiki

From ThePlaz.com

Jump to: navigation, search

A few months ago I figured out by piecing together info form around the web how to install Memcached on to a server (in this case I am using a 1and1 shared server) and configure MediaWiki to use it. (MediaWiki is the software which runs this site and Wikipedia)

Memcached will dramatically speed up MediaWiki. Some pages on my site, like the Main Page took 40 seconds to load before Memcached, but only 7 after installing Memcached. "Memcached is a high-performance, distributed memory object caching system". Memcached is essentially a database caching system which is object orientated, and works even if the database is updated. (MySQL caching discards the entire cache when a table is changed)

In MediaWiki, as with other common web apps, some items are called from the database for every page load, such as interface elements, commonly accessed text, and settings. Why should the database be hit each time you want to print the English version that means "edit"? Memcached keeps such commonly requested rows seperate from the database. The database still servers less commonly requested information when needed.

Installing Memcached and Libevent

I am going to demonstrate using my shared server on 1and1. This will work on any Linux server which you have shell access to (can be via SSH).

I will use '/kunden/homepages/13/d155370874/htdocs/' as my root directory, because that's the root of what I have access to on my shared server To find your working directory, use
$ pwd


First get via (wget) the latest version of libevent available. Then unzip it and install it. I use prefix to install it in my shared directory, because I don't have write access in the usual location for such stuff.

$ wget http://www.monkey.org/~provos/libevent-1.4.5-stable.tar.gz
$ tar -zvxf libevent-*gz
$ cd libevent-*
$ ./configure --prefix=$HOME/libevent
$ make
$ make install
$ cd

Then get Memcached and install giving it the directory where you installed libevent. (Note: on 1and1 I could only get version 1.1.12 to work; not the latest version; I don't know why)

I didn't have any problem using memcached-1.2.5 (latest at time of this writing) --Merles 18:59, 29 June 2008 (EDT)
$ wget http://www.danga.com/memcached/dist/memcached-1.2.5
$ tar -zvxf memcached-*
$ cd memcached-*
$ ./configure --prefix=$HOME/memcached --with-libevent=$HOME/libevent
$ make
$ make install

Start Memcached

If your server gets restarted, you might have to redo these steps.

$ cd memcached #(the directory where you installed memcached)
$ cd bin
$ ldd memcached

That will output:

        libevent-1.3b.so.1 => not found
        libc.so.6 => /lib/tls/libc.so.6 (0x00a55000)
        /lib/ld-linux.so.2 (0x00a3c000)

Now type (substuting where you installed libevent if needed):

$ export LD_LIBRARY_PATH=$HOME/libevent/lib:$LD_LIBRARY_PATH
$ ldd memcached

That will output: (Notice the path to libevent is now there)

        libevent-1.3b.so.1 => /kunden/homepages/13/d155370874/htdocs/libevent-1.3b/lib/libevent-1.3b.so.1 (0x0061f000)
        libc.so.6 => /lib/libc.so.6 (0x00a55000)
        /lib/ld-linux.so.2 (0x00a3c000)

Start it up: This will start it up as a daemon (it will run in the background) on IP 127.0.0.1 on port 11000 using no more then 64 MB of RAM.

$  memcached -d -l 127.0.0.1 -p 11000 -m 64

Confirm that it it is working with

$ top

Output should be:

	24190 u3988386  18   2 24056  22M   248 S N   0.0  0.0   0:00 memcached

Configure MediaWiki

Add this to your LocalSettings.php. For other web apps, check with there documentation to see how to enable Memcached. Notice how I set the IP and port where Memcached is running:

$wgMainCacheType = CACHE_MEMCACHED;
$wgMemCachedServers = array( "127.0.0.1:11000" );

For more information on using MediaWiki with Memcached see: http://meta.wikimedia.org/wiki/Memcached