Ejemplo n.º 1
0
 def testLeafIdx(self):
     x = MerkleTree()
     for ii in xrange(10000):
         key = random_3letters()
         leafidx = x._findleaf(key)
         if not x.nodes[0][leafidx]._inrange(key):
             raise KeyError("Key %s hashes to value outside range for this leaf" % key)
Ejemplo n.º 2
0
 def setUp(self):
     self.c1 = SimpleConsistentHashTable(('A', 'B', 'C'))
     num_nodes = 50
     self.nodeset = set()
     while len(self.nodeset) < num_nodes:
         node = random_3letters()
         self.nodeset.add(node)
     self.c2 = SimpleConsistentHashTable(self.nodeset)
Ejemplo n.º 3
0
 def testLeafIdx(self):
     x = MerkleTree()
     for ii in xrange(10000):
         key = random_3letters()
         leafidx = x._findleaf(key)
         if not x.nodes[0][leafidx]._inrange(key):
             raise KeyError(
                 "Key %s hashes to value outside range for this leaf" % key)
Ejemplo n.º 4
0
 def setUp(self):
     self.c1 = ConsistentHashTable(('A', 'B', 'C'), 2)
     num_nodes = 50
     self.nodeset = set()
     while len(self.nodeset) < num_nodes:
         node = random_3letters()
         self.nodeset.add(node)
     self.c2 = ConsistentHashTable(self.nodeset, NODE_REPEAT)
Ejemplo n.º 5
0
 def setUp(self):
     self.c1 = SimpleConsistentHashTable(('A', 'B', 'C'))
     num_nodes = 50
     self.nodeset = set()
     while len(self.nodeset) < num_nodes:
         node = random_3letters()
         self.nodeset.add(node)
     self.c2 = SimpleConsistentHashTable(self.nodeset)
Ejemplo n.º 6
0
 def setUp(self):
     self.c1 = ConsistentHashTable(('A', 'B', 'C'), 2)
     num_nodes = 50
     self.nodeset = set()
     while len(self.nodeset) < num_nodes:
         node = random_3letters()
         self.nodeset.add(node)
     self.c2 = ConsistentHashTable(self.nodeset, NODE_REPEAT)
Ejemplo n.º 7
0
 def setUp(self):
     self.keystore = dict((random_3letters(), random.randint(0, 99)) for ii in xrange(50))
     self.keya = long(hashlib.md5('A').hexdigest(), 16)
     self.keyb = long(hashlib.md5('B').hexdigest(), 16)
     if self.keya < self.keyb:
         self.min_key = self.keya
         self.max_key = self.keyb
     else:
         self.min_key = self.keyb
         self.max_key = self.keya
Ejemplo n.º 8
0
 def setUp(self):
     self.keystore = dict(
         (random_3letters(), random.randint(0, 99)) for ii in xrange(50))
     self.keya = long(hashlib.md5('A').hexdigest(), 16)
     self.keyb = long(hashlib.md5('B').hexdigest(), 16)
     if self.keya < self.keyb:
         self.min_key = self.keya
         self.max_key = self.keyb
     else:
         self.min_key = self.keyb
         self.max_key = self.keya
Ejemplo n.º 9
0
 def testDistribution(self):
     """Generate a lot of hash values and see how even the distribution is"""
     nodecount = dict([(node, 0) for node in self.nodeset])
     numkeys = 10000
     for _ in range(numkeys):
         node = self.c2.find_nodes(random_3letters(), 1)[0][0]
         nodecount[node] = nodecount[node] + 1
     stats = Stats()
     for node, count in nodecount.items():
         stats.add(count)
     print ("%d random hash keys assigned to %d nodes "
            "are distributed across the nodes "
            "with a standard deviation of %0.2f (compared to a mean of %d)." %
            (numkeys, len(self.nodeset), stats.stddev(), numkeys / len(self.nodeset)))
Ejemplo n.º 10
0
 def testDistribution(self):
     """Generate a lot of hash values and see how even the distribution is"""
     nodecount = dict([(node, 0) for node in self.nodeset])
     numkeys = 10000
     for _ in range(numkeys):
         node = self.c2.find_nodes(random_3letters(), 1)[0][0]
         nodecount[node] = nodecount[node] + 1
     stats = Stats()
     for node, count in nodecount.items():
         stats.add(count)
     print ("%d random hash keys assigned to %d nodes "
            "are distributed across the nodes "
            "with a standard deviation of %0.2f (compared to a mean of %d)." %
            (numkeys, len(self.nodeset), stats.stddev(), numkeys / len(self.nodeset)))
Ejemplo n.º 11
0
    def testFailover(self):
        """For a given unavailable node, see what other nodes get new traffic"""
        test_node = None
        transfer_count = dict([(node, 0) for node in self.nodeset])
        total_transfers = 0
        for _ in range(1000):
            key = random_3letters()
            node_pair = self.c2.find_nodes(key, 2)[0]
            if test_node is None:
                test_node = node_pair[0]
            if node_pair[0] == test_node:
                next_node = node_pair[1]
                transfer_count[next_node] = transfer_count[next_node] + 1
                total_transfers = total_transfers + 1

        for node in self.nodeset:
            if transfer_count[node] > 0:
                print ("Node %s gets %d of %d (%0.0f%%) transfers" %
                       (node, transfer_count[node], total_transfers,
                        100 * transfer_count[node] / total_transfers))
Ejemplo n.º 12
0
    def testFailover(self):
        """For a given unavailable node, see what other nodes get new traffic"""
        test_node = None
        transfer_count = dict([(node, 0) for node in self.nodeset])
        total_transfers = 0
        for _ in range(1000):
            key = random_3letters()
            node_pair = self.c2.find_nodes(key, 2)[0]
            if test_node is None:
                test_node = node_pair[0]
            if node_pair[0] == test_node:
                next_node = node_pair[1]
                transfer_count[next_node] = transfer_count[next_node] + 1
                total_transfers = total_transfers + 1

        for node in self.nodeset:
            if transfer_count[node] > 0:
                print ("Node %s gets %d of %d (%0.0f%%) transfers" %
                       (node, transfer_count[node], total_transfers,
                        100 * transfer_count[node] / total_transfers))
Ejemplo n.º 13
0
 def testFailover(self):
     """For a given unavailable node, see what other nodes get new traffic"""
     transfer = {}
     for from_node in self.nodeset:
         transfer[from_node] = {}
         for to_node in self.nodeset:
             transfer[from_node][to_node] = 0
     numkeys = 10000
     for _ in range(numkeys):
         key = random_3letters()
         node_pair = self.c2.find_nodes(key, 2)[0]
         transfer[node_pair[0]][
             node_pair[1]] = transfer[node_pair[0]][node_pair[1]] + 1
     stats = Stats()
     for from_node in self.nodeset:
         num_dest_nodes = 0
         for to_node in self.nodeset:
             if transfer[from_node][to_node] > 0:
                 num_dest_nodes = num_dest_nodes + 1
         stats.add(num_dest_nodes)
     print("On failure of a single node, %.1f other nodes (on average) "
           "handle the transferred traffic from that node." % stats.mean())
Ejemplo n.º 14
0
 def testFailover(self):
     """For a given unavailable node, see what other nodes get new traffic"""
     transfer = {}
     for from_node in self.nodeset:
         transfer[from_node] = {}
         for to_node in self.nodeset:
             transfer[from_node][to_node] = 0
     numkeys = 10000
     for _ in range(numkeys):
         key = random_3letters()
         node_pair = self.c2.find_nodes(key, 2)[0]
         transfer[node_pair[0]][node_pair[1]] = transfer[node_pair[0]][node_pair[1]] + 1
     stats = Stats()
     for from_node in self.nodeset:
         num_dest_nodes = 0
         for to_node in self.nodeset:
             if transfer[from_node][to_node] > 0:
                 num_dest_nodes = num_dest_nodes + 1
         stats.add(num_dest_nodes)
     print ("On failure of a single node, %.1f other nodes (on average) "
            "handle the transferred traffic from that node." %
            stats.mean())