logo       
Google Custom Search
    AddThis Social Bookmark Button
-->

Re: Memcache::addServer(): msg#00047

Subject: Re: Memcache::addServer()
Hi,

1) Per Apache process, given that persistent connections are used,
otherwise its only per request. Each server has a connection struct that
has a flag and timestamp which indicates the server status, when using
persistent connections this struct is stored and re-used in the next
request served by that Apache process.

2) When a key hashes to a failed server it adds an increment to the key
and rehashes so that another server is tried in a deterministic fashion.
This is repeated until a valid server is found (or the max number of
retries is reached)

3) Yes, this is the problem with using failover. Servers that go up and
down (within the key expiry time) can cause outdated values to be read
from the servers that handled the failover.

If you have a larger number of memcache servers; one failing does not
really affect the performance much since only a relatively small
percentage of keys lives on that server. In this case common practice is
to disable failover through the "memcache.allow_failover" INI setting.

4) With the current balancing algorithm you must take care to keep your
servers in the pool (and add them in the same order) even though they
are marked failed/down, otherwise some or even all keys might hash to a
different server.

This is what the $status, $retry_interval and $failure_callback
parameters to Memcache::addServer() are for, they allow you to add a
server in offline mode so that it will be skipped when selecting servers
but still keep the hashing order intact. Remember to set $retry_interval
to -1 to disable automatic reconnect when keeping track of server
up/down state externally.

//Mikael

Joe Stump wrote:
> I have a few questions about the lead balancing features in Memcache.
> Anyone want to interject on the following:
> 
> 1.) Where exactly does this code keep track of failed servers? Per
> request? Per thread/process? Or per server?
> 
> 2.) How does it redistribute keys once a server has failed?
> 
> 3.) If server A fails and its keys are distributed to the other servers,
> is brought back in (at which point its keys are sent back to server A),
> and immediately fails does this mean the other servers still have A's
> old keys on it?
> 
> 4.) I was thinking of using a memory table in mysql to keep track of
> which servers are working and which ones are not (via the failure
> callback). So request A could run addServer for servers 1, 2, 3 while
> request B might only addServer for 1, 3. Does the connection pooling
> notice that I've decided to not use 2 and drop it from the pool? What
> happens when I add it back?
> 
> Thanks!
> 
> --Joe
> 

--PECL development discussion Mailing List (http://pecl.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



<Prev in Thread] Current Thread [Next in Thread>