Email: Zip:

Libmemcached Vs. Memcached on Ruby

By Ryan Kopf - Sep. 20, 2009

For a while I was so confused with libmemcached, cached_model, memcached, etc, that I had no idea what was what. I mean, after I couldn't do something as simple as sudo apt-get install libmemcached I was definitely unhappy. What is libmemcached? It's apparently the memcached interface used by twitter - thus I want to use it if I want to hope to render over 100 requests per second with one cluster. I think I'm going to have to build the libmemcached from source (uggh, just because there's always something missing), and figure out how to make it + ruby play nicely. Let's see what happens, but here's what should work:

I already have memcached (I think it was simply 'sudo apt-get install memcached'). Install libmemcached. You have to download the tar.gz, then extract it. From there it's something like 'sudo ./configure', 'sudo make', then 'sudo make install'. Then, from the main libmemcached website, go find the memcached gem. I think all you need is 'sudo gem install memcached --no-rdoc' or something very similar. I then had to 'ln -s /usr/local/lib/libmemcached.so.2 /usr/lib/' in order to make the libmemcached functions work. Start memcached with 'memcached -p 11211 &'. After that you can probably use it.

Stick this in production.rb or wherever:
MEMCACHE_OPTIONS = {
:compression => true,
:debug => false,
:namespace => "mem-#{RAILS_ENV}",
:readonly => false,
:urlencode => false
}

MEMCACHE_SERVERS = [ '127.0.0.1:11211' ]

CACHE = MemCache.new(MEMCACHE_OPTIONS)
CACHE.servers = MEMCACHE_SERVERS
ActionController::Base.session_options[:cache] = CACHE

Back To: Ryan Kopf

To post, please login or register an account.
Sign Up