This project is read-only.

Project Description


Enterprise Consistent Hash (ECH) is a consistent hashing library written in C#. It is tested to be used at production level and supports N number of nodes (servers); while most of the hashing implement out there only support limited number of nodes to achieve the required performance speed.
ESH provide the following features:

1. High performance, it implements Fowler–Noll–Vo hash algorithm by overcoming all its weakness defined in here. This implementation might be considered as one of the fastest consistent hashing implementation written in C# as it only take 1-2 microsecond to identify a node for a given key(Run the test app and see the result output).
2. Easy to use, the library provides a manger class that hides implementation details. See the class diagram below

Below is a sample code that consume the library. The app runs two diffrent node spaces; Three deep node space and single circle node space.


class Program
{
static void Main(string[] args)
{

OneCircleNodeSpace();
// ThreeDeepNodeSpace();
Console.ReadLine();

}




public static void ThreeDeepNodeSpace()
{


SpaceMgr mgr = null;
List<Node> nodeSpace = new List<Node>();
List<Node> nodes = null;
List<Node> child = null;
for (int i = 0; i < 1000; i++)
{
nodes = new List<Node>();
for (int j = 0; j < 3; j++)
{
child = new List<Node>();
for (int k = 0; k < 2; k++)
{
child.Add(new Node("D" + k.ToString(), k.ToString()));
}
nodes.Add(new Node(i.ToString(), j.ToString(), child, 200));
}

nodeSpace.Add(new Node(i.ToString(), i.ToString(), nodes, 200));
}

//create the node manager object
mgr = new SpaceMgr(nodeSpace);

//Assign value for a key
mgr.Locate("Author").value = "Debru Aklil";

//display key
Console.WriteLine("looking for Author key....");

//locate a node and get a value for a key
Console.WriteLine(mgr.Locate("Author").value);

//number of node key to search
int search = 100000;

//Get number of nodes in the node space
NodeList<Node> sp = mgr.nodespace;
int count = 1;
while (sp.nodes.Count >= 1)
{
count = count * sp.nodes.Count;
sp = sp.nodes[0]; ;
}



Console.WriteLine("Start Processing " search " keys in " count " nodes.");
//Calculate time taken to look n number of keys
Stopwatch sw = new Stopwatch();
sw.Start();
for (int i = 0; i < search; i++)
{
mgr.Locate(i.ToString());
}
sw.Stop();
Console.WriteLine(search " Each node lookup took : " (sw.Elapsed.TotalMilliseconds / search) * 1000 + " Microseconds.");


}


public static void OneCircleNodeSpace()
{


SpaceMgr mgr = null;
List<Node> nodeSpace = new List<Node>();
for (int i = 0; i < 1000; i++)
nodeSpace.Add(new Node(i.ToString(), i.ToString()));

//create the node manager object
mgr = new SpaceMgr(nodeSpace);

//Assign value for a key
mgr.Locate("Author").value = "Debru Aklil";

//display key
Console.WriteLine("looking for Author key....");

//locate a node and get a value for a key
Console.WriteLine(mgr.Locate("Author").value);

//number of keys to search
int search = 100000;

NodeList<Node> sp = mgr.nodespace;

//Get number of nodes in the node space
int count = 1;
while (sp.nodes.Count >= 1)
{
count = count * sp.nodes.Count;
sp = sp.nodes[0]; ;
}
Console.WriteLine("Start Processing " search " keys in " nodeSpace.Count " nodes.");
//Calculate time taken to look n number of keys
Stopwatch sw = new Stopwatch();
sw.Start();
for (int i = 0; i < search; i++)
{
mgr.Locate(i.ToString());
}
sw.Stop();
Console.WriteLine(search " Each node lookup took : " (sw.Elapsed.TotalMilliseconds / search) * 1000 + " Microseconds.");


}
}

Last edited May 17, 2012 at 4:35 PM by debruyee, version 7