Forum: Ruby on Rails Memcached 1.6.5 (Rails 2.3) 10x slower

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
whatcould (Guest)
on 2009-04-13 12:37
(Received via mailing list)
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...
Conrad T. (Guest)
on 2009-04-13 12:56
(Received via mailing list)
On Sun, Apr 12, 2009 at 7:10 PM, whatcould 
<removed_email_address@domain.invalid> wrote:

> Cached fragment hit: views/sightings/1558/row (2.2ms)
>
> 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
David R. (Guest)
on 2009-04-13 19:01
(Received via mailing list)
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.

=========
and switching memcache_client versions:
=========

memcache_client version: 1.5.0
  0.040000   0.020000   0.060000 (  0.138320)
.
Finished in 0.15171 seconds.

=============

There must be something I'm doing wrong -- I'm sure someone would have
seen this if it were really this much slower??
David R. (Guest)
on 2009-04-13 19:26
(Received via mailing list)
By the way -- I should clarify that the _actual memcache-client
library_ is significantly faster, as the benchmarks included in the
new (Mike P.'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.
David R. (Guest)
on 2009-04-13 20:18
(Received via mailing list)
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)

===

That would be something like this in your production.rb:

config.cache_store = :mem_cache_store, '127.0.0.1:11211', { :timeout
=> nil }

===

But there's still something fishy here -- in the mcache-client
benchmarks, 1.6.5 is significantly faster even without turning off the
timeouts. Doing some more research.
Mike P. (Guest)
on 2009-04-14 10:19
(Received via mailing list)
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/d5a...

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
David R. (Guest)
on 2009-04-14 17:55
(Received via mailing list)
> 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
This topic is locked and can not be replied to.