ketama memcached java client
Hanson Char
hanson.char at gmail.com
Mon Jul 30 00:11:26 UTC 2007
Hi,
I refer to the ketama SockIOPool
(http://static.last.fm/ketama/ketama-0.1.1.tar.bz2) implementation for
the use of consistent hashing in the memcached java client. In the
initialize method, if the weight of each server is 1, the "factor"
would be 40 and therefore resulting in each server being added to the
TreeMap 160 times (with code extracted below.)
Curious, why 40 ? Is it optimal ? Why not configurable ?
Hanson Char
double factor =
Math.floor(((double)(40*this.servers.length*thisWeight))/(double)this.totalWeight);
for(long j = 0; j < factor; j++) {
byte[] d = md5.digest((servers[i]+"-"+j).getBytes());
for(int h=0;h<4;h++) {
Long k =
((long)(d[3+h*4]&0xFF) << 24)
| ((long)(d[2+h*4]&0xFF) << 16)
| ((long)(d[1+h*4]&0xFF) << 8)
| ((long)(d[0+h*4]&0xFF));
buckets.put(k, servers[i]);
log.debug( "++++ added " + servers[i] + " to server bucket" );
}
}
More information about the memcached
mailing list