memcached - PHP memcache::addServer, weight -


my question related "weight" parameter in addserver function of php memcache extension.
last couple of months, have been using "weight = 1" servers. trying apply configurations below remove "10.10.10.3" rotation , minimize data loss.
new weight values in place, php client fails retrieve value keys used able fetch. if revert "weight = 1", keys can fetched without problem.

there configuration or missing in order use "weight" option correctly "memcache::addserver"?

thank help.

 $hosts = array(       array('ip' => '10.10.10.1', 'port' => 11211, 'weight' => 100),       array('ip' => '10.10.10.2', 'port' => 11211, 'weight' => 100),       array('ip' => '10.10.10.3', 'port' => 11211, 'weight' => 1),       array('ip' => '10.10.10.4', 'port' => 11211, 'weight' => 100),  );   $memcache = new memcache();  foreach($hosts $host) {     $host['port'] = isset($host['port']) ? (int) $host['port'] : 11211;     $host['weight'] = isset($host['weight']) ? (int) $host['weight'] : 1;     $memcache->addserver($host['ip'], $host['port'], false, $host['weight'], 1, 15);  } 

php version = 5.3.10

memcache php variables
- memcache support => enabled
- memcache.allow_failover => 1 => 1
- memcache.chunk_size => 32768 => 32768
- memcache.compress_threshold => 20000 => 20000
- memcache.default_port => 11211 => 11211
- memcache.hash_function => crc32 => crc32
- memcache.hash_strategy => consistent => consistent
- memcache.lock_timeout => 15 => 15
- memcache.max_failover_attempts => 20 => 20
- memcache.protocol => ascii => ascii
- memcache.redundancy => 1 => 1
- memcache.session_redundancy => 2 => 2

memcached versions
10.10.10.1 / 10.10.10.2 / 10.10.10.3 running 1.4.5
10.10.10.4 running 1.4.4

the weight parameter effects consistent hashing used determine server read/write keys from. changing weight of 1 server in pool result in cache misses. number of servers in pool , how change weight factor in on how many misses may experience.

what need understand memcached distributed means since have 4 servers, keys distributed amongst each of servers (as close evenly possible [weight effect distribution]). if 1 server goes down, data stored on server no longer accessible , have fetched database not available on other servers. *note php extensions memcache , memcached clients access memcached cluster (memcached newer of 2 , supported more features, both talk servers in memcached cluster).

when want store or retrieve value cache, hash computed determines in cluster data should put or read from. common way illustrate 360 degree circle seen below. calculate hash, , use node lands "closest" in circle. adding or removing servers, or changing weight of 1 server effect outcome of hashing , result in miss.

enter image description here
source: http://alpha.mixi.co.jp/blog/?p=158

if want phase server out of cluster slowly, recommend gradually decreasing weight until 0 , can remove server list completely. keep in mind, small change in weight can/will result in cache misses, how weight changes (and how many servers have) influences how many misses experience.

here snippet memcached tutorial story may explain of well.

the preface 2 sysadmins set memcached cluster 3 servers, , told memcached use 1gb on each server...

so again, takes keys programmer uses , looks them on memcached servers. 'get this_key' 'get that_key' each time this, finds each key on 1 memcached! why this, thinks? , puzzles night. that's silly! don't want keys on memcacheds?

"but wait", thinks "i gave each memcached 1 gigabyte of memory, , means, in total, can cache 3 gigabytes of database, instead of one! oh man, great," thinks. "this'll save me ton of cash. brad fitzpatrick, love ass!"

"but hmm, next problem, , one's puzzler, webserver right here, 1 runing memcached it's old, it's sick , needs upgraded. in order have take offline! happen poor memcache cluster? eh, let's find out," says, , shuts down box. looks @ graphs. "oh noes, db load, it's gone in stride! load isn't one, it's two. hmm, still tolerable. of other memcacheds still getting traffic. ain't bad. few cache misses, , i'm done work. turns machine on, , puts memcached work. after few minutes, db load drops again down 1, should be.

"the cache restored itself! now. if it's not available means few of requests missed. it's not enough kill me. that's pretty sweet."

the moral values stored in memcached stored on 1 server (that keys distributed amongst servers) , if 1 of servers becomes unavailable, data not available cache , has fetched source.

in order store , retrieve data correct nodes in cluster, keys must consistently hashed client knows server correct 1 in pool particular key.

as may guess, different clients use different hashing techniques using perl client , php client store/retrieve values not work intended since hash differently. exception client uses libmemcached since using same hashing algorithm. php's memcached extension uses libmemcached, memcache not , uses own hashing algorithm (as far know).

further reading:
- memcached wiki , adventure in learning memcached
- consistent hashing
- distributed hash tables


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -