Dalli – memcached for Ruby

Dalli is my brand new memcached client for Ruby. I’ve maintained Ruby’s memcache-client for two years now and been dissatisfied with the codebase for a while.

Coincidentally, NorthScale approached me recently about building a pure Ruby memcached client which used the new binary protocol defined in memcached 1.4. We worked out an arrangement to sponsor the OSS project which became Dalli.

My goals for Dalli were threefold:

  1. Clean sheet codebase using the binary protocol
  2. Drop-in replacement for memcache-client in Rails for a very simple upgrade path for Rails developers
  3. Equivalent or faster performance than memcache-client

I’m happy to say that Dalli meets all those goals. For one, the Dalli core is almost half the size of the memcache-client core, 700 vs 1250 LOC! But wait, there’s more! Using Rails 3? Dalli drops right in! Using Heroku? Dalli works without any additional configuration! Take a look at the README for more details.

Please file an issue if you find a bug or have a feature you’d like to see. In the meantime, happy caching!

24 thoughts on “Dalli – memcached for Ruby”

  1. Very good to see other memcached libraries spring up with real binary protocol support for the 1.4 series. I originally wrote my remix-stash client (now maintained by Arron Quint/quirkey) for API reasons (which I still find to be my biggest issue with other libraries) but the protocol actually exposes a lot more that isn’t possible in the old text based protocol. Stats specifically have much more to pull down now.

    I’m in the process of rewriting it to support UDP and async setups, though I’ve been using CoffeeScript and node more these days so my ruby project time is scaled back… I’ll probably release it once I really need it.

    1. Brian, your remix-stash work was very helpful to me as a reference when implementing the actual binary protocol. I need to update the README to give you a shoutout. Thanks for reminding me!

  2. Just out of curiosity, was there a reason why you decided to publish this as a completely separate library rather than just releasing it as memcache-client 2.0? That would have made things a lot simpler in terms of keeping track of libraries and so forth, IMO.

    1. The Dalli API is not 100% backwards-compatible with memcache-client. Dalli only supports the binary protocol so it requires memcached 1.4.0+. Several features have been removed and the codebase is completely new. For these reasons, I elected to start a completely new gem.

  3. Hi Mike,

    Dalli looks really exciting! Do you by chance know whether it could be used instead of memcache-client with Starling?

    Thanks!
    Pierre

    1. Thanks, Evan, I just verified that memcached does install in 1.9.2. Sorry for the misinfo and thanks for including Dalli in your benchmarks!

      Odd versioning scheme though, memcached v1? What was the reasoning behind a single digit version?

  4. It didn’t quite work without any further configuration on heroku. I had to make sure to specify the specific memcached servers I was using on my production.rb:

    config.cache_store = :dalli_store, ENV['MEMCACHE_SERVERS']

    I’m not sure if this was always needed or it’s a recent development, but this info was hard to come upon for me. Heroku’s own docs page on memcached doesn’t mention it, and I couldn’t get it to work until the anonymous hero behind http://arailsdemo.com clarified it.

  5. Good to know, Mike. I haven’t seen 0.10.1 kick in for me when I do the usual gem update, and it looks like it just came out a few days ago. Is there a built in waiting period before places like rubygems.org push it out when you update your gems?

    I know I can specify a specific version too, just curious about the process for new gem updates in general.

  6. User error. Running ‘bundle update’ worked fine for me know. I was doing another ‘bundle install’, not realizing it doesn’t update automatically.

    However, with this update, dalli never read from the cache. My Heroku log was full of repeated ‘write fragment’ statements for the same fragment. On top of that, the time to write a fragment skyrocketed to 500 ms, even for a few hundreds bytes of text. The stats method output from the client was still reporting data though, so some connection must have been established.

    I rolled back to 0.10.0 and it was able to read fragments just fine again, and write time went back to a few milliseconds.

  7. Great work, always exciting to see progress on the Ruby memcaching front.

    I notice that when Dalli tries to connect to a memcached server that is less than 1.4, it seems to hang indefinitely. Any idea why this scenario doesn’t get caught by the timeout mechanism and result as an error rather than a hang?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>