Memcached 1.6.5 (Rails 2.3) 10x slower

The move to memcached_client 1.6.5 in Rails 2.3 seems to have made the Rails cache about 10x slower. Since that's the opposite effect I would expect, I was hoping somebody would explain where I'm misreading these numbers?

I noticed my fragment caching was slow -- it shouldn't take 2ms just to read a 2k string from a localhost memcached server: Cached fragment hit: views/sightings/1556/row (2.3ms) Cached fragment hit: views/sightings/1557/row (2.4ms) Cached fragment hit: views/sightings/1558/row (2.2ms)

Then i did some quick and dirty benchmarks on the console:

First, with the "1.6.5" version bundled with rails 2.3 # => cache benchmark: (182.9ms)

Then I switch memcache_client versions, to 1.5.0: # => cache benchmark: (18.6ms)

(full benchmark code -- http://gist.github.com/94196)

These numbers hold up on both OSX and Solaris. I'll submit a ticket somewhere unless it turns out I'm missing something...

Can you post a complete test case that can be ran?

-Conrad

Hmm, good idea. There's probably a better way to do this but here's a test I ran in activesupport/test:

http://gist.github.com/94481

(you still have to manually replace the memcache client in activesupport/vendor/, not sure how to easily swap out the MemCache client in code.)

results:

# ruby -Ilib:test test/memcache_client_test.rb

Loaded suite test/memcache_client_test Started memcache_client version: 1.6.4.99   0.940000 0.390000 1.330000 ( 1.354539) . Finished in 1.374947 seconds.

By the way -- I should clarify that the _actual memcache-client library_ is significantly faster, as the benchmarks included in the new (Mike Perham's) branch of memcache-client show.

http://github.com/mperham/memcache-client/tree

Time to run the whole benchmark suite, on my oldish MacBook: 1.7.1: 49 seconds 1.6.4.99: 126 seconds 1.5: 376 seconds!!

So it's not the memcache-client itself.

Ok, on a tip from mperham:

Turning off the timeouts makes memcache in Rails 2.3 almost as fast as it was in 2.2:

http://gist.github.com/94481

With timeouts: memcache_client version: 1.6.4.99   9.170000 4.200000 13.370000 ( 13.567950) . No timeouts: memcache_client version: 1.6.4.99   0.730000 0.230000 0.960000 ( 1.616430)

I've added a FAQ entry explaining what is going on. 1.6+ is much faster than 1.5.0 only when multiple servers are being used. I'm guessing your benchmark is testing just localhost:11211.

http://github.com/mperham/memcache-client/blob/d5ae15d362c379c3a6692e2d5b9beae545392cba/FAQ.rdoc

Simple answer, turn off socket timeouts in order to dramatically speed up memcache-client but realize you might be woken up at 3am when production melts down, as I was.

mike

Simple answer, turn off socket timeouts in order to dramatically speed up memcache-client but realize you might be woken up at 3am when production melts down, as I was.

Better answer -- split the difference: install mike's memcache- client-1.7.2 (from github) and the SystemTimer gem, which speeds up 1.6.5 substantially without turning off the timeouts.

My problem is that I added fragment caching thinking .03ms fetch times were normal, and now when it takes 3-4ms (with the timeouts) to get each fragment... stuff gets really slow. So until i refactor, timeouts are off.

david