Memcached on 1and1 with MediaWiki

From ThePlaz.com

Revision as of 16:50, 13 August 2007 by ThePlaz (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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 out the entire cache when a table is changed)

In MediaWiki, as with other common web apps- there are some things which are called from the database each time, such as interface elements, commonly accessed text, and settings. Why should the database be hit each time you want to print the English version of "edit"? Memcached keeps such commonly requested items seperate from the database which is more archival oriented and still servers less common information.

Installing Memcached and Libevent

I am going to demonstrate using my shared server on 1and1. This will work on any Linux server where 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.1a.tar.gz
$ tar -zvxf libevent-1.1a.tar.gz
$ cd libevent-1.1a
$ ./configure --prefix=/kunden/homepages/13/d155370874/htdocs/libevent
$ make
$ make install
$ cd

Then get Memcached and install giving it the directory where you installed libevent

$ wget http://www.danga.com/memcached/dist/memcached-1.1.12.tar.gz
$ tar -zvxf memcached-1.1.12.tar.gz
$ cd memcached-1.1.12
$ ./configure --prefix=/kunden/homepages/13/d155370874/htdocs/memcached --with-libevent=/kunden/homepages/13/d155370874/htdocs/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):

$ export LD_LIBRARY_PATH=/kunden/homepages/13/d155370874/htdocs/libevent/lib:
$ 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" );