How is it possible to locate server based on key hash code

2012-10-27 Thread Ravi
I have 3 Memcached balanced Servers running for the Application .

I googled and found out that , using hashkey , its possible to locate a key 
from any of the server 

I am using KetamaMemcachedSessionLocator set up with my code .


I tried this way , but i am not sure if its correct or not .

int mod = MemcachedClient.getAvailableServers().size(); // This value is 3 

int keyid = key.hashCode();


COuld anybody please tell me how can i locate first , Second Server  with 
this approach ??



Re: How is it possible to locate server based on key hash code

2012-10-27 Thread David Walter
I think that you want to read how consistent hashing works, in brief,
it's not a simple modulo arithmetic mapping.

http://www.paperplanes.de/2011/12/9/the-magic-of-consistent-hashing.html

libmemcached has an option:

memcached_server_instance_st memcached_server_by_key(const memcached_st *ptr,
 const char *key,
 size_t key_length,
 memcached_return_t *error)

Your language probably has a similar method server for key or by key.


On Sat, Oct 27, 2012 at 11:47 AM, Ravi ravikiranva...@gmail.com wrote:
 I have 3 Memcached balanced Servers running for the Application .

 I googled and found out that , using hashkey , its possible to locate a key
 from any of the server

 I am using KetamaMemcachedSessionLocator set up with my code .


 I tried this way , but i am not sure if its correct or not .

 int mod = MemcachedClient.getAvailableServers().size(); // This value is 3

 int keyid = key.hashCode();


 COuld anybody please tell me how can i locate first , Second Server  with
 this approach ??