How to maintain cache update on different memcached servers?

howard chen howachen at gmail.com
Tue Oct 31 16:03:15 UTC 2006


On 10/31/06, cremes.devlist at mac.com <cremes.devlist at mac.com> wrote:
>
> On Oct 31, 2006, at 9:33 AM, howard chen wrote:
>
> > On 10/31/06, Daniel Beckham <dbeckham-memcached at dealnews.com> wrote:
> >> Hi,
> >>
> >> I don't think you will find much information in this area as it
> >> tends to
> >> fall outside of the normal usage of memcached.  Although, it has been
> >> discussed before in this list and some people are working towards a
> >> solution for this.
> >>
> >> These links and others in this thread might be of use to you.
> >>
> >> http://lists.danga.com/pipermail/memcached/2006-October/002856.html
> >> http://lists.danga.com/pipermail/memcached/2006-October/002891.html
> >>
> >> May I ask, why are you wanting to synchronize a group of memcached
> >> servers?
> >
> > consider this suitation:
> >
> > Machine A
> > MySQL Master A
> > Memcached A
> >
> > Machine B
> > MySQL Slave B
> > Memcached B
> >
> >
> > Support a user query a object thru complex SQL join statement from
> > MySQL slave B, this object is cached using Memcached B, in order to
> > offload the MySQL slave B
> >
> > Now, a row is being updated to MySQL master A, MySQL slave B get the
> > update thru MySQL replication, but memcached B is still holding the
> > old data
> >
> > How would you do in this suitation?
>
> Howard,
>
> you misunderstand how memcached works. It doesn't front-end the
> database servers like you think it does. It works like this:
>
> Memcache1   Memcache2
>      \           /
>       \         /
>        \       /
>         \     /
>          \   /
>           \ /
>        MySQL Master
>        MySQL Slave
>
> There is NO replication between Memcache1 and Memcache2 because they
> do not cache the same data. Memcache1 caches 50% of the data and
> Memcache2 caches the other 50% of the data. There is no data overlap
> so no synchronization is necessary.
>
> If either memcached server fails, the application requesting the data
> should "fall through" and hit the database server(s) directly.
>
> Do you understand now?
>

seems better now...

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


More information about the memcached mailing list