How to be in. Implementation of consistent loop hash algorithm in net

Source: Internet
Author: User
Tags hash

Consistency Ring hash algorithm has a big use is to solve the problem of Memcache server down machine. The goal is to increase or remove the Memcache server, minimizing the impact.

The theory is not introduced, there is too much information on the Internet, please search your own search.

A consistencyring class is written here to implement the algorithm.

The test classes are as follows:

 public static void Test () {{consistencyring CR = new consistencyring ();
                Console.WriteLine ("=============addserver test============="); Cr.
                Addserver ("1"); Cr.
                Addserver ("5"); Cr.
                Addserver ("9"); Cr.
                Addserver ("11"); Cr.
    
                Addserver ("3");
                Console.WriteLine ("=============removeserver test============="); Cr.
                Removeserver ("5"); Cr.
                Removeserver ("3"); Cr.
                Removeserver ("1"); Cr.
            Removeserver ("9");
    
                {consistencyring CR = new consistencyring (); Cr.
                Addserver ("1"); Cr.
                Addserver ("5"); Cr.
                Addserver ("9"); Cr.
                Addserver ("11"); Cr.
    
                Addserver ("3");
                Console.WriteLine ("=============getserverip test============="); String keY
    
                String ServerIP;
                Key = "A1";
                ServerIP = Cr[key];
    
                Console.WriteLine ("A1 IP:" + serverip); Cr.
                Removeserver ("9");
                ServerIP = Cr[key];
            Console.WriteLine ("A1 IP:" + serverip); }
        }

The parameters in the addserver/removeserver above are changed to a concise numeric string for demonstration purposes and can be transmitted using string such as 192.168.1.1.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.