How to maintain cache update on different memcached servers?

howard chen howachen at gmail.com
Tue Oct 31 17:04:53 UTC 2006


On 11/1/06, Bash Coder <bashcoder+memcached at gmail.com> wrote:
> When B goes down you have no failover memcache.  That's OK, because you
> don't *need* it anyway - it's just a helper to take load off your database.
> If B fails your app goes directly to the database for its data until the
> cache server B is back up.  When the server comes back up, it starts to
> build it's cache again from scratch.
>
> This is not high availability stuff here -- there's no redundancy or
> failover.  But that's OK, because it's just an optimization layer - it isn't
> the database.  As to the hashing, I think it just takes a checksum of the
> query and does a mod(memcache_server_count).  That way the same query is
> cached on the same memcached every time.
>
> - Bash
>
> --
> http://bashcoder.com
>
>
> On 10/31/06, howard chen <howachen at gmail.com > wrote:
> > On 11/1/06, Andrew Pile < andrew at connectedventures.com> wrote:
> > > That is NOT how it works. The data is not stored evenly on all
> > > servers, it is hashed and sent to one server.
> > >
> > > On Oct 31, 2006, at 11:26 AM, Jehiah Czebotar wrote:
> > >
> > > >> so, correct me if i am wrong...
> > > >>
> > > >> 1. on each memcached server, i start the memcached deamon as they are
> > > >> separetely server, they don't know each other, e.g.
> > > >> ./memcached -d -m 2048 -l 10.0.0.40 -p 11211
> > > >>
> > > >> 2. during connection from client, add all the servers...
> > > >> e.g.
> > > >>
> > > >> $memcache = new Memcache;
> > > >> $memcache->addServer('memcache_host', 11211);
> > > >> $memcache->addServer('memcache_host2', 11211);
> > > >>
> > > >> 3. the memcached objects will be stored evenly on all these server,
> > > >> and i can get it using Memcache::get , without specifying the server
> > > >> host
> > > >>
> > > >
> > > > correct: that is exactly it.
> > > >
> > > > (just make sure the memory you are configuring memcached to use (2048)
> > > > is not larger than the actuall free RAM on your machines)
> > > >
> > > > --
> > > > Jehiah
> > >
> > >
> >
> > yes, this is the point, how does hashing work?
> >
> > e.g.
> >
> > originally three servers, A, B, C
> >
> > an object is hashed to server B
> >
> > but server B was downed, and it will hashed to server C when receive
> > another request ? what will happen if server B up again?
> >
>

so given this

1. we can't add servers to an existing running pool? since hashing
won't work when you add addional server(s), you need to reset all

2. if script A is using server A, B, C, and script B is using server
B, C, D, there will be duplicate items on servers, maybe an item exist
on B & C ?

thanks.


More information about the memcached mailing list