Tags

, , ,

Memchached is a memory based cache you can use to speed up reads that normally take a long time e.g db reads.  Lots of sites use this process to scale out their database infrastructure with something like this:

Check if a result already exists in memory cache, if it does read it, use it, move on the the next task.

If not read it from the database, store it in the cache for next time, use the data and move on.

Memcache is not designed to be fault tolerant.  If a server goes down so does the cache that was on it. It’s designed primarily for a front end read cache for something slower and perminant behind it.

The architecture is very simple.  Memcache servers are stand alone and don’t need to know about each other.  The client reading and writing to the cache knows about all the memcache servers and writes to a particular cache server based on the unique key it gives a chuck of data.

Getting it going on Ubuntu is simple:

sudo apt-get install memcached

You can manualy fire up memchached with this:

./memcached -d -m 2048 -l 10.0.0.40 -p 11211

-d starts it in deamon mode
-m dictakes how much memory the cache can use
-l what ip to listen on
-p what port to listen on

The program sits in /usr/bin

Kill it off with

 sudo killall memchached

A useful check to see how it’s running is to telnet to the port it’s running on, 11211 by default, and issue the command

stats

Which will dump out a load of data about what’s going on on that memcache instance.

More info: http://www.danga.com/memcached/

Advertisements