# Memcache client very slow?

**URL:** <https://www.ruby-forum.com/t/memcache-client-very-slow/114689>\
**Category:** Rails\
**Created:** [September 17, 2007, 1:24pm UTC](https://www.ruby-forum.com/t/memcache-client-very-slow/114689 "2007-09-17T13:24:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcbey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d9b06d/32.png) [@marcbey](https://www.ruby-forum.com/u/marcbey)\
**Post date:** [September 17, 2007, 1:24pm UTC](https://www.ruby-forum.com/t/memcache-client-very-slow/114689/1 "2007-09-17T13:24:13Z")

</div>

Case 1: Ruby + Ruby-MemCache + onboard memcache (the cache) - 10.5  
seconds

Case 2: Python + REMOTE memcache (the same cache as the other) -  
0.2seconds

Please please tell me I’m doing something very wrong… - and examples  
of  
the right way would be great.

## m

here’s my code:

require ‘memcache’

mem = MemCache.new ‘10.253.9.158’  
#mem = MemCache.new ‘127.0.0.1’

t1=Time.new  
list1 = mem[‘red’]  
list2 = mem[‘car’]  
t2=Time.new  
puts (t2.to\_f - t1.to\_f).to\_s

list3 = list1.split(’:’) & list2.split(’:’)  
t3 = Time.new  
puts (t3.to\_f - t2.to\_f).to\_s  
puts list3  
t4 = Time.new  
puts (t4.to\_f - t3.to\_f).to\_s

---

<div class="post-metadata">

**Author:** ![marcbey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d9b06d/32.png) [@marcbey](https://www.ruby-forum.com/u/marcbey)\
**Post date:** [September 17, 2007, 1:25pm UTC](https://www.ruby-forum.com/t/memcache-client-very-slow/114689/2 "2007-09-17T13:25:25Z")

</div>

On Fri, 14 Sep 2007, Marc B. wrote:

> Case 1: Ruby + Ruby-MemCache + onboard memcache (the cache) - 10.5 seconds
> 
> Case 2: Python + REMOTE memcache (the same cache as the other) - 0.2seconds
> 
> Please please tell me I’m doing something very wrong… - and examples of  
> the right way would be great.

Try memcache-client instead…

[http://dev.robotcoop.com/Libraries/memcache-client/index.html](http://dev.robotcoop.com/Libraries/memcache-client/index.html)

It’s supposed to be a lot faster…

Also, if this is on a mac and you’re using memcache 1.2.0 recompile it  
and  
tweak the following:

# edit memcached.h and add ‘#undef NO\_TCPPUSH’ to the top

Can’t remember where exactly I read that, but it makes a huge  
difference.

---

<div class="post-metadata">

**Author:** ![marcbey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d9b06d/32.png) [@marcbey](https://www.ruby-forum.com/u/marcbey)\
**Post date:** [September 25, 2007, 11:07pm UTC](https://www.ruby-forum.com/t/memcache-client-very-slow/114689/3 "2007-09-25T23:07:19Z")

</div>

Well, the python-memcache was 50x faster, got it down to only 4x faster  
w/  
memcache-client as suggested.

Two other things I’ve noticed:

1. Python is much more stable - I very rarely get any kind of  
corruption  
or unexpected behavior - I’ve had to start over 5 times w/ ruby’s  
memcache.

2. Ruby seems to care much more about marshaling, etc. Python seems  
quite happy to let you leave things as strings and do your own parsing.

Am I insane to consider trying to figure out how to use a python library  
in  
ruby? Is there such a thing? Or perhaps I should use a ReST API hosted  
by  
python, available from ruby - [http://localhost:11212/search?key=‘red’](http://localhost:11212/search?key='red')  
(and  
in fact I’m only going to be GETing from ruby - doing all the bulk cache  
loading on the python side thanks very much).

Any other suggestions?

m
