예제 #1
0
        public static void Test()
        {
            HashAlgorithmTest test = new HashAlgorithmTest();

            /** Records the times of locating node*/
            Dictionary <string, int> nodeRecord = new Dictionary <string, int>();

            List <string>     allNodes = test.getNodes(NODE_COUNT);
            KetamaNodeLocator locator  = new KetamaNodeLocator(allNodes, VIRTUAL_NODE_COUNT);

            List <String> allKeys = test.getAllStrings();

            foreach (string key in allKeys)
            {
                string node = locator.GetPrimary(key);
                if (!nodeRecord.ContainsKey(node))
                {
                    nodeRecord[node] = 1;
                }
                else
                {
                    nodeRecord[node] = nodeRecord[node] + 1;
                }
            }

            Console.WriteLine("Nodes count : " + NODE_COUNT + ", Keys count : " + EXE_TIMES + ", Normal percent : " + (float)100 / NODE_COUNT + "%");
            Console.WriteLine("-------------------- boundary  ----------------------");
            foreach (string key in nodeRecord.Keys)
            {
                Console.WriteLine("Node name :" + key + " - Times : " + nodeRecord[key] + " - Percent : " + (float)nodeRecord[key] / EXE_TIMES * 100 + "%");
            }
            Console.ReadLine();
        }
예제 #2
0
        public static void TestDb()
        {
            HashAlgorithmTest test = new HashAlgorithmTest();

            /** Records the times of locating node*/
            Dictionary <string, int> nodeRecord = new Dictionary <string, int>();

            List <string>     allNodes = test.getNodes(NODE_COUNT);
            KetamaNodeLocator locator  = new KetamaNodeLocator(allNodes, VIRTUAL_NODE_COUNT);

            List <string> allKeys = new List <string> {
                "10", "11", "12", "13", "14"
            };

            foreach (string key in allKeys)
            {
                string node = locator.GetPrimary(key);
                Console.WriteLine("Node name :" + node + " - key : " + key);
            }
            Console.ReadLine();
        }