Spymemcached hashing algorithm for multiple membase server

1.9k views Asked by At

Platform: spymemcached-2.7.3.jar, 64 bit Windows 7 OS

We have two membase servers (Non Clustered Environment) and we are using spymemcached java client for setting and getting data from memcache. We are not using any replication between two membase servers.

We are using following code to set data in memcache. Looks like MemcachedClient always first try to put/get data in server1 if its available. If server1 is down, then MemcachedClient put/get from server2. Does spymemcached uses any hashing algoritham to decide from which server it needs to set/get data? Any documentation available which explains how it works?

code

public class Main {

    public static void main(String[] args) throws IOException, URISyntaxException {

        MemcachedClient client;

        URI server1 = new URI("http://192.168.100.111:8091/pools");
        URI server2 = new URI("http://127.0.0.1:8091/pools");
        ArrayList<URI> serverList = new ArrayList<URI>();
        serverList.add(server1);
        serverList.add(server2);
        client = new MemcachedClient(serverList, "default", "");

        client.set("spoon", 50, "Hello World!");
        client.shutdown(10, TimeUnit.SECONDS);

        System.exit(0);
    }
}
1

There are 1 answers

0
mikewied On

The constructor MemcachedClient(List, String, String) will connect to the first URI in the list to obtain information about the entire cluster. This means that if you had 10 servers in you cluster you can specify one ip address to connect to all of them. The reason a list of URI's is allowed is so that if the server you are getting cluster information from goes down you can try to get cluster information from another server in the cluster.

The hashing algorithm used by Spymemcached in this case is determined by Membase when the cluster configuration begins. If you look through some json that is sent to Spymemcached during the configuration phase you will see the hash algorithm is CRC. Look in the DefaultHashAlgorithm class for more information on CRC.

Also, I'm curious why your using Membase as described.