# About memcached

**URL:** <https://www.ruby-forum.com/t/about-memcached/148912>\
**Category:** Rails\
**Created:** [September 18, 2008, 10:19am UTC](https://www.ruby-forum.com/t/about-memcached/148912 "2008-09-18T10:19:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![difei](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a4c791/32.png) [@difei](https://www.ruby-forum.com/u/difei)\
**Post date:** [September 18, 2008, 10:19am UTC](https://www.ruby-forum.com/t/about-memcached/148912/1 "2008-09-18T10:19:47Z")

</div>

Hi all,

There is a new plugin for memcached query cache, I was hoping it will  
bring some performance boost for my application, so I write a simple  
ruby program to benchmark normal memcached performance, the result is  
very frustrating:

```auto
require 'memcache'

CACHE = MemCache.new('localhost:11211')

def mem_write
  File.open("./dbmrec.txt", "r") do |f|
    while line = f.gets
      str, num = line.split(' ')
      CACHE[str] = num
    end
  end
end
```

dbmrec.txt contains 31196 lines of record like:

lwatch 38535  
netwox-doc 70502  
octave-audio 92312  
octave-informationtheory 92004  
pyrenamer 5049  
ruby1.9-examples 13590  
safecat 74989

It needs around 25s to successfully terminate compare to 0.5s forthe  
same program using tokyocabinet.

So, my question is, am I missing something? This will be even slower  
than normal sql insert/select I guess.

Thanks for any comment.

Difei

---

<div class="post-metadata">

**Author:** ![difei](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a4c791/32.png) [@difei](https://www.ruby-forum.com/u/difei)\
**Post date:** [September 18, 2008, 8:20pm UTC](https://www.ruby-forum.com/t/about-memcached/148912/2 "2008-09-18T20:20:15Z")

</div>

On Sep 18, 1:19 am, Difei Z. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> There is a new plugin for memcached query cache, I was hoping it will  
> bring some performance boost for my application, so I write a simple  
> ruby program to benchmark normal memcached performance, the result is  
> very frustrating:  
> …  
> while line = f.gets  
> str, num = line.split(’ ')  
> CACHE[str] = num  
> end  
> …  
> So, my question is, am I missing something? This will be even slower  
> than normal sql insert/select I guess.

I don’t think repeated writes with no reads is a very good performance  
test for memcached. Test reading instead. I’d test by populating the  
cache to something that would look like steady state (i.e. you don’t  
want all your data in cache, because that’s unrealistic, but you don’t  
want to start empty), then starting the clock and doing lots of reads,  
some of which will be cache misses and have to go to DB.

Kevin

---

<div class="post-metadata">

**Author:** ![difei](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a4c791/32.png) [@difei](https://www.ruby-forum.com/u/difei)\
**Post date:** [September 19, 2008, 5:19am UTC](https://www.ruby-forum.com/t/about-memcached/148912/3 "2008-09-19T05:19:16Z")

</div>

Kevin Peterson wrote:

> On Sep 18, 1:19ï¿½am, Difei Z. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > ï¿½ There is a new plugin for memcached query cache, I was hoping it will  
> > bring some performance boost for my application, so I write a simple  
> > ruby program to benchmark normal memcached performance, the result is  
> > very frustrating:  
> > …  
> > ï¿½ ï¿½ while line = f.gets  
> > ï¿½ ï¿½ ï¿½ str, num = line.split(’ ')  
> > ï¿½ ï¿½ ï¿½ CACHE[str] = num  
> > ï¿½ ï¿½ end  
> > …  
> > ï¿½ So, my question is, am I missing something? This will be even slower  
> > than normal sql insert/select I guess.
> 
> I don’t think repeated writes with no reads is a very good performance  
> test for memcached. Test reading instead. I’d test by populating the  
> cache to something that would look like steady state (i.e. you don’t  
> want all your data in cache, because that’s unrealistic, but you don’t  
> want to start empty), then starting the clock and doing lots of reads,  
> some of which will be cache misses and have to go to DB.
> 
> Kevin

Hi, I was using Ruby-Memcached, after changing it to memcached-client,  
the speed is now much faster (3s), but it still can not beat  
tokyocabinet.
