# Fragment caching with Memcached slow?

**URL:** <https://www.ruby-forum.com/t/fragment-caching-with-memcached-slow/63795>\
**Category:** Rails\
**Created:** [January 21, 2006, 6:47pm UTC](https://www.ruby-forum.com/t/fragment-caching-with-memcached-slow/63795 "2006-01-21T18:47:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![big\_mac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f4b2a3/32.png) [@big\_mac](https://www.ruby-forum.com/u/big_mac)\
**Post date:** [January 21, 2006, 6:47pm UTC](https://www.ruby-forum.com/t/fragment-caching-with-memcached-slow/63795/1 "2006-01-21T18:47:35Z")

</div>

Hi,

I am trying to do fragment caching using :mem\_cache\_store. However,  
when I  
compare it to fragment caching using :file\_store, it seems to be a lot  
slower.

Here are the results:

uncache  
Completed in 2.20246 (0 reqs/sec) | Rendering: 2.19891 (99%) | DB:  
0.00017(0%) | 200 OK [  
[http://127.0.0.1/](http://127.0.0.1/)]

using file\_store  
Completed in 0.00952 (105 reqs/sec) | Rendering: 0.00702 (73%) | DB:  
0.00000(0%) | 200 OK [  
[http://127.0.0.1/](http://127.0.0.1/)]

using memcache  
Completed in 0.03558 (28 reqs/sec) | Rendering: 0.02561 (71%) | DB:  
0.00000(0%) | 200 OK [  
[http://127.0.0.1/](http://127.0.0.1/)]

Other Notes:

- I’ve tried using both Ruby-MemCached0.4 and memcache-client libraries  
and  
the results are about the same.
- I am sure there is no paging.

Memcached execution parameters:  
memcached -m 256 -l 127.0.0.1 -p 11211 -vv

ldd /usr/local/bin/memcached results:  
linux-gate.so.1 =\> (0x0036a000)  
libc.so.6 =\> /lib/libc.so.6 (0x0088e000)  
/lib/ld-linux.so.2 (0x00870000)

My environment: uname -a  
Linux 2.6.14-1.1656\_FC4 #1 Thu Jan 5 22:13:22 EST 2006 i686 athlon i386  
GNU/Linux

I’m stumped. Isn’t it memcache store should be faster than file store  
since  
there is no disk access? Would somebody be able to explain?

Thanks,  
Mac

---

<div class="post-metadata">

**Author:** ![big\_mac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f4b2a3/32.png) [@big\_mac](https://www.ruby-forum.com/u/big_mac)\
**Post date:** [January 21, 2006, 7:45pm UTC](https://www.ruby-forum.com/t/fragment-caching-with-memcached-slow/63795/2 "2006-01-21T19:45:44Z")

</div>

On 1/21/06, big mac [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m stumped. Isn’t it memcache store should be faster than file store  
> since there is no disk access? Would somebody be able to explain?

I’m just starting to work with memcache too, but this is what I think  
is going on…

Your file\_cache number is running out of RAM the same as memcache.  
That’s because the OS has cached the file.

memcache is running out of RAM but it is using a communication  
protocol with a lot more overhead. That’s why it’s slower.

But, memcache is only a win when multiple machines are involved.  
memcache let’s you share a single cache between all of the machines  
where each object is only stored once in the cache. So if you have 50  
machines each running a 1GB memcache you have a 50GB cache. But this  
cache is slower since you need to use the network to access the remote  
caches.

With file\_store each cache in independent. Each OS has 1GB cache so  
the same object is getting cached over and over in the various  
machines. You have 50 1GB caches, each of which is faster than  
memcache, but they are only 1GB caches.

If you are running a model where each request can end up at a randeom  
server you needs to transfer the session data to the current server.  
This is where memcache is a big win, there is one cache for all the  
servers. Just look your session up, it will be there.  
With file\_cache you would have to put the session data in the database  
and share it that way.

–  
Jon S.  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![big\_mac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f4b2a3/32.png) [@big\_mac](https://www.ruby-forum.com/u/big_mac)\
**Post date:** [January 24, 2006, 8:19am UTC](https://www.ruby-forum.com/t/fragment-caching-with-memcached-slow/63795/3 "2006-01-24T08:19:37Z")

</div>

big mac wrote:

> 0.00017(0%) | 200 OK [  
> [http://127.0.0.1/](http://127.0.0.1/)]
> 
> Other Notes:
> 
> - I’ve tried using both Ruby-MemCached0.4 and memcache-client libraries and  
> the results are about the same.

You must make sure that only one version of the file memcache.rb is in  
your load path. Otherwise you might be using Ruby-MemCached0.4. I wished  
Eric had named his file and class differently (FastMemCache e.g.). I  
have measured the speed of memcache against using DB session storage and  
was disappointed as it was 2 times slower. But after I cleared out the  
above problem it was faster than DB storage. I’ll blog exact figures  
later.

– stefan

–  
For rails performance tuning, see: [http://railsexpress.de/blog](http://railsexpress.de/blog)  
Subscription: [railsexpress.de](http://railsexpress.de/blog/xml/rss20/feed.xml)

---

<div class="post-metadata">

**Author:** ![big\_mac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f4b2a3/32.png) [@big\_mac](https://www.ruby-forum.com/u/big_mac)\
**Post date:** [June 14, 2008, 10:34pm UTC](https://www.ruby-forum.com/t/fragment-caching-with-memcached-slow/63795/4 "2008-06-14T22:34:58Z")

</div>

big mac wrote:

> Hi,
> 
> I am trying to do fragment caching using :mem\_cache\_store. However,  
> when I  
> compare it to fragment caching using :file\_store, it seems to be a lot  
> slower.
> 
> Here are the results:
> 
> uncache  
> Completed in 2.20246 (0 reqs/sec) | Rendering: 2.19891 (99%) | DB:  
> 0.00017(0%) | 200 OK [  
> [http://127.0.0.1/](http://127.0.0.1/)]
> 
> using file\_store  
> Completed in 0.00952 (105 reqs/sec) | Rendering: 0.00702 (73%) | DB:  
> 0.00000(0%) | 200 OK [  
> [http://127.0.0.1/](http://127.0.0.1/)]
> 
> using memcache  
> Completed in 0.03558 (28 reqs/sec) | Rendering: 0.02561 (71%) | DB:  
> 0.00000(0%) | 200 OK [  
> [http://127.0.0.1/](http://127.0.0.1/)]
> 
> Other Notes:
> 
> - I’ve tried using both Ruby-MemCached0.4 and memcache-client libraries  
> and  
> the results are about the same.
> - I am sure there is no paging.
> 
> Memcached execution parameters:  
> memcached -m 256 -l 127.0.0.1 -p 11211 -vv
> 
> ldd /usr/local/bin/memcached results:  
> linux-gate.so.1 =\> (0x0036a000)  
> libc.so.6 =\> /lib/libc.so.6 (0x0088e000)  
> /lib/ld-linux.so.2 (0x00870000)
> 
> My environment: uname -a  
> Linux 2.6.14-1.1656\_FC4 #1 Thu Jan 5 22:13:22 EST 2006 i686 athlon i386  
> GNU/Linux
> 
> I’m stumped. Isn’t it memcache store should be faster than file store  
> since  
> there is no disk access? Would somebody be able to explain?
> 
> Thanks,  
> Mac

Hi,

That s a bit old post, but today I got the same. I have plenty of RAM,  
use memcached gem and whatever I do, I can’t go over 185 r/s with  
mem\_cache\_store and go to 205 r/s with file\_store. Every thing is on a  
single freebsd machine, and I dont understand how file storage can be  
faster than memory. Some other tests show memory\_store is 10x faster on  
rendering.

Anyone could help me to find the light ?

thanks,

–  
Stephane
