« blogcentral.jpost.co... | Main | Latest Links: Friday... »

HOWTO: Configure Roller to use Memcached

In my last post, I explained the details of Roller cache configuration and I mentioned that Roller's caching system is pluggable but I didn't explain what that really buys you. Basically, what it means is that you can replace Roller's in-memory LRU caching mechanism with something else. In this blog entry, I'll explain how to do that and specifically, how to replace Roller's built-in cache with the popular Memcached caching system via the Roller Memcached plugin, which, like the rest of the Roller caching system was written by Allen Gilliland for use on blogs.sun.com.

First, what is Memcached? Here's what the Memcached web site says:

"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."

Lots of big sites use Memcached for distributed caching. In addition to LiveJournal, there's also Wikipedia, Slashdot, SourceForge and our very own blogs.sun,com. If you're wanting to use Memcached, then you're in good company.

Why would you want to use Memcached with Roller? Well, if you are running a large Roller site and you've got multiple instances of Roller running then you might run into problems with cache consistency. A blog update that hits server A will update the cache on server A, but server B will still have the old blog data for some time. Using a distributed cache will solve this problem. Another, hopefully much less common, reason for wanting to use Memcache is to avoid using the JVM heap -- some folks have experienced some weird problems with the JVM heap management and might want to use plain old C memory management instead via Memcached.


Download and install Memcached

The first thing you need to do is to get yourself a copy of Memcached. You can get downloads and docs on the Memcached web site. You can build it yourself if you're a manly man or a womanly woman, but there are some much easier options.

For example, on Ubuntu or Debian, you can install Memcached with one simple command:


   apt-get install memcached

Or, if you're on Solaris and you're a Blastwave user, then you can do this:


   pkg-get install memcached

On Mac, you can probably do something similar with Fink or MacPorts. There's also a Win32 version for those less fortunate.

And, of course, you'll have to install Memcached on each machine on which you want to act as a cache server.


Setup your Memcached caches

Now that you've got Memcached installed, you need to start it up.

For example, let's say you want to have two 2GB caches running on your two machines with IP addresses 10.0.0.40 and 10.0.0.41. One one maching you'd run this command to start the Memcached daemon with 2048M RAM and listening on port 11211.


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

And on your other machine 10.0.0.41, you'd start Memcached with this command:

$ ./memcached -d -m 2048 -l 10.0.0.41 -p 11211

And, you'll almost certainly want to set things up so that your Memcached daemons start up whenever your servers start up. On Solaris or Linux that means adding things under the /etc/init.d directory. You'll have to figure that out for yourself.


Download and install the Roller Memcached plugin

Next, you need to get yourself a copy of the Roller Memcached plugin and install it into Roller. You can get it from the Roller Support project. Go to the project's file download page and navigate to Roller Support 4.0 / Plugins, or just use the link below:

https://roller.dev.java.net/.../roller-memcached-4.0.tar.gz

Unzip that file and add the two jars within to your Roller install's WEB-INF/lib directory. Assuming that the Roller context is in the directory $ROLLER_HOME, you might do that like so:


$ tar xzvf roller-memcached-4.0.tar.gz 
$ cp roller-memcached/* $ROLLER_HOME/WEB-INF/lib


Configure the Memcached Plugin and Roller caching

The final step is to configure Roller to use Memcached for caching. To do that, you simply add some properties to your roller-custom.properties override file. To use Memcached for all of your caches, set the following property:

   

   cache.defaultFactory=\ 
      net.java.roller.tools.cache.memcached.MemcachedLRUCacheFactoryImpl

If you don't want to use Memcached for all of your caches, then configure it for just the caches you want. Refer to my previous post about Roller caching for details, but basically you just set the factory for the cache to use the Memcached cache factory. For example, to use Memcached for caching feeds only, you'd add this instead of the above:


   cache.weblogfeed.factory=\ 
      net.java.roller.tools.cache.memcached.MemcachedLRUCacheFactoryImpl

You also need to tell the Roller Memcached plugin how to find the Memcached servers. To continue with the example we started above with servers 10.0.0.40 and 10.0.0.41, you could add this to set the default Memcached servers for all caches:


cache.memcached.default.servers=10.0.0.40:11211, 10.0.0.41:11211 

You can also set the servers to be used for specific caches . For example, here we set the weblog feed cache to use two different Memcached servers from that used by the weblog page cache:


cache.memcached.weblogpage.servers=10.0.0.40:11211, 10.0.0.41:11211 
cache.memcached.weblogfeed.servers=10.0.0.50:11211, 10.0.0.51:11211


Fire it up!

Now you're ready to start up Roller. You might want to add some debug logging the first time around just to make sure things are working. Roller uses Log4j caching and you can add the Log4j properties directly to your roller-custom.properties file. For example, to enable debug caching for the Roller Memcached plugin you'd add this:


log4j.category.net.java.roller.tools.cache.memcached=DEBUG

And that's that. Let me know via comments if I've left something out or gotten something wrong. I'd also like to hear if you've had some success with Roller and Memcached.

Comments:

Nice post, thanks. Trond Norbye wrote an SMF bundle for running memcached on Solaris, see: http://blogs.sun.com/trond/entry/memcached_in_solaris

Posted by Dick Davies on March 07, 2008 at 09:46 AM EST #

Turns out Solaris Express now ships with memcached, and has the required SMF gubbins.

Posted by Dick Davies on August 07, 2008 at 08:26 AM EDT #

The code from the old Java.net "Roller Support" project is now part of the "Roller Extras" project on Google Code. That's where you can find the source for the Roller Memcache plugin there: http://bit.ly/WFO46q

Posted by Dave Johnson on October 23, 2012 at 02:22 AM EDT #

Hi Dave,
i'm have problem with link download plugin memcached roller, Are you have other link download ??..

Please Help,
Thanks...

Posted by Reynaldi Dwi on October 23, 2012 at 03:27 AM EDT #

Hi Dave,
Thanks for your help...

Posted by Reynaldi Dwi on October 23, 2012 at 08:20 AM EDT #

Post a Comment:
  • HTML Syntax: Allowed

« blogcentral.jpost.co... | Main | Latest Links: Friday... »

Welcome

This is just one entry in the weblog Blogging Roller. You may want to visit the main page of the weblog

Related entries

Below are the most recent entries in the category Roller, some may be related to this entry.