Running Movable Type with memcached
Memcached (pronounced mem-cash-dee) is a caching framework that allieviates database load and makes applications that utilize it faster and more reliable. From memcached’s website:
memcached is a high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.
Danga Interactive developed memcached to enhance the speed of LiveJournal.com, a site which was already doing 20 million+ dynamic page views per day for 1 million users with a bunch of webservers and a bunch of database servers. memcached dropped the database load to almost nothing, yielding faster page load times for users, better resource utilization, and faster access to the databases on a memcache miss.
Users of Red Hat Enterprise, Fedora and CentOS, depending upon the version you are using, may have success installing memcached via RPM. Do do so, execute the following command as root:
yum install memcached
Users of Debian can execute this command:
apt-get install memcached
Any missing dependencies will be resolved for you automatically.
While some RPMs and Debian packages exist for memcache, the most reliable way to get memcached up and running is to compile from source. This is typically very straight forward and quite reliable.
- Download libevent (version 1.3b).
- Untar libevent by executing
tar zxvf libevent-1.3b.tar.gz
make install as root
- Download memcached (version 1.2.2).
- Untar memcached by executing
tar zxvf memcached-1.2.2.tar.gz
make install as root
Now you can start the memcached daemon by executing the following command:
./memcached -d -m 2048 -l 127.0.0.1 -p 11211 &
This will start memcached and bind it to port 11211 on the IP address of 127.0.0.1 with 2GB of memory.
A version of memcached exists for windows as well. Download the latest Win32 Binary of memcached and follow the instructions found on its website.
To install memcached on a Mac OS X system, download and run the following script.
Once memcache has been successfully installed on your machine, or on a server that is accessible by Movable Type, edit your mt-config.cgi file and add the following configuration parameter:
Be sure to set the IP address (127.0.0.1 in the example above) and the port number (11211 in the example above) to the proper IP and Port that memcached is listening on.
To setup Movable Type to connect to a pool of memcache servers add multiple MemcachedServers directives like so:
MemcachedServers 127.0.0.1:11211 MemcachedServers 127.0.0.2:11211 MemcachedServers 127.0.0.3:11211
If you are running Movable Type under FastCGI you will need to restart your webserver.
That’s it. Movable Type will immediately begin caching data using memcached. If Movable Type experiences any problems accessing memcached then it will degrade gracefully and act as if it is not there.
- Consider launching memcached automatically when the server starts up so that you can rest assured that it will always be running.
- Monitor memcache using Nagios or other monitoring software to ensure that it is running
- Consider deploying memcache on a dedicated machine
- Do not deploy memcached and Movable Type on different networks - memcache operates most efficiently when network overhead and latency is completely minimized.