# Question about running memcached on multiple servers

**URL:** <https://www.ruby-forum.com/t/question-about-running-memcached-on-multiple-servers/87740>\
**Category:** Rails\
**Created:** [March 5, 2007, 6:07pm UTC](https://www.ruby-forum.com/t/question-about-running-memcached-on-multiple-servers/87740 "2007-03-05T18:07:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [March 5, 2007, 6:07pm UTC](https://www.ruby-forum.com/t/question-about-running-memcached-on-multiple-servers/87740/1 "2007-03-05T18:07:18Z")

</div>

All,

I have memcached running on two boxes and memcache-client installed and  
am ready to integrate into my Rails app.

I see lots of references to running the memcached server daemon process  
on several servers. This implies that you would have completely  
different caches on each machine, correct? So you would just fire up as  
many cache processes as you need to cache different items in hopes of  
distributing the load.

There isn’t any notion of some sort of distributed cache (cache that  
lives on multiple servers), right? That would seem to imply some sort  
of replication or cache server affinity.

Thanks,  
Wes

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [March 5, 2007, 6:22pm UTC](https://www.ruby-forum.com/t/question-about-running-memcached-on-multiple-servers/87740/2 "2007-03-05T18:22:19Z")

</div>

> lives on multiple servers), right? That would seem to imply some sort  
> of replication or cache server affinity.

Right… from the memcache page…

* * *

Now, what actually happens is that the API hashes your key to a unique  
server. (You define all the available servers and their weightings when  
initializing the API) Alternatively, the APIs also let you provide your  
own hash value. A good hash value for user-related data is the user’s ID  
number. Then, the API maps that hash value onto a server (modulus number  
of server buckets, one bucket for each server IP/port, but some can be  
weighted heigher if they have more memory available).

If a host goes down, the API re-maps that dead host’s requests onto the  
servers that are available.

* * *

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [March 5, 2007, 7:27pm UTC](https://www.ruby-forum.com/t/question-about-running-memcached-on-multiple-servers/87740/3 "2007-03-05T19:27:25Z")

</div>

Very nice. So it really is a distributed cache out of the box.
