Difference between revisions of "Memcached on 1and1 with MediaWiki"

From ThePlaz.com

Jump to: navigation, search
(Inital draft (10 min))
 
(Thanks for your documentation! Contributing where possible :-))
 
(2 intermediate revisions by one user not shown)
Line 1: Line 1:
 
A few months ago I figured out by piecing together info form around the web how to install [http://www.danga.com/memcached/ Memcached] on to a server (in this case I am using a [http://www.1and1.com/?k_id=10309718 1and1] shared server) and configure [http://www.mediawiki.org/wiki/MediaWiki MediaWiki] to use it.  (MediaWiki is the software which runs this site and Wikipedia)
 
A few months ago I figured out by piecing together info form around the web how to install [http://www.danga.com/memcached/ Memcached] on to a server (in this case I am using a [http://www.1and1.com/?k_id=10309718 1and1] shared server) and configure [http://www.mediawiki.org/wiki/MediaWiki 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)
+
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- 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.  
+
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==
 
==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 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).
  
 
{{Red Message|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 <pre>$ pwd</pre>}}
 
{{Red Message|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 <pre>$ pwd</pre>}}
Line 13: Line 13:
  
 
<pre>
 
<pre>
$ wget http://www.monkey.org/~provos/libevent-1.1a.tar.gz
+
$ wget http://www.monkey.org/~provos/libevent-1.4.5-stable.tar.gz
$ tar -zvxf libevent-1.1a.tar.gz
+
$ tar -zvxf libevent-*gz
$ cd libevent-1.1a
+
$ cd libevent-*
$ ./configure --prefix=/kunden/homepages/13/d155370874/htdocs/libevent
+
$ ./configure --prefix=$HOME/libevent
 
$ make
 
$ make
 
$ make install
 
$ make install
Line 22: Line 22:
 
</pre>
 
</pre>
  
Then get [http://www.danga.com/memcached/ Memcached] and install giving it the directory where you installed libevent
+
Then get [http://www.danga.com/memcached/ 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) --[[User:Merles|Merles]] 18:59, 29 June 2008 (EDT)
 
<pre>
 
<pre>
$ wget http://www.danga.com/memcached/dist/memcached-1.1.12.tar.gz
+
$ wget http://www.danga.com/memcached/dist/memcached-1.2.5
$ tar -zvxf memcached-1.1.12.tar.gz
+
$ tar -zvxf memcached-*
$ cd memcached-1.1.12
+
$ cd memcached-*
$ ./configure --prefix=/kunden/homepages/13/d155370874/htdocs/memcached --with-libevent=/kunden/homepages/13/d155370874/htdocs/libevent
+
$ ./configure --prefix=$HOME/memcached --with-libevent=$HOME/libevent
 
$ make
 
$ make
 
$ make install
 
$ make install
Line 35: Line 36:
 
If your server gets restarted, you might have to redo these steps.
 
If your server gets restarted, you might have to redo these steps.
 
<pre>
 
<pre>
$ cd memcached (the directory where you installed memcached)
+
$ cd memcached #(the directory where you installed memcached)
 
$ cd bin
 
$ cd bin
 
$ ldd memcached
 
$ ldd memcached
Line 45: Line 46:
 
         /lib/ld-linux.so.2 (0x00a3c000)
 
         /lib/ld-linux.so.2 (0x00a3c000)
 
</pre>
 
</pre>
Now type (substuting where you installed libevent):
+
Now type (substuting where you installed libevent if needed):
 
<pre>
 
<pre>
$ export LD_LIBRARY_PATH=/kunden/homepages/13/d155370874/htdocs/libevent/lib:
+
$ export LD_LIBRARY_PATH=$HOME/libevent/lib:$LD_LIBRARY_PATH
 
$ ldd memcached
 
$ ldd memcached
 
</pre>
 
</pre>
Line 64: Line 65:
 
$ top
 
$ top
 
</pre>
 
</pre>
Output should be:  
+
Output should be:
 +
<pre>
 
24190 u3988386  18  2 24056  22M  248 S N  0.0  0.0  0:00 memcached
 
24190 u3988386  18  2 24056  22M  248 S N  0.0  0.0  0:00 memcached
 +
</pre>
 
==Configure MediaWiki==
 
==Configure MediaWiki==
  
Line 74: Line 77:
 
</pre>
 
</pre>
  
 
+
For more information on using MediaWiki with Memcached see: http://meta.wikimedia.org/wiki/Memcached
  
 
[[Category:Tech]]
 
[[Category:Tech]]
 +
[[Category:1&1]]

Latest revision as of 22:59, 29 June 2008

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