当前位置: 首页>>代码示例>>Python>>正文


Python hashing.ConsistentHashRing类代码示例

本文整理汇总了Python中carbon.hashing.ConsistentHashRing的典型用法代码示例。如果您正苦于以下问题:Python ConsistentHashRing类的具体用法?Python ConsistentHashRing怎么用?Python ConsistentHashRing使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ConsistentHashRing类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_9_node_positional_itegrity

 def test_9_node_positional_itegrity(self):
     """Make a cluster, verify we don't have positional collisions"""
     ring = ConsistentHashRing([])
     for n in range(9):
         ring.add_node(("192.168.10.%s" % str(10+n),"%s" % str(10+n)))
     self.assertEqual(
             len([n[0] for n in ring.ring]),
         len(set([n[0] for n in ring.ring])))
开发者ID:Akulatraxas,项目名称:carbon,代码行数:8,代码来源:test_hashing.py

示例2: test_chr_get_node_fnv1a

 def test_chr_get_node_fnv1a(self):
     hosts = [("127.0.0.1", "ba603c36342304ed77953f84ac4d357b"),
              ("127.0.0.2", "5dd63865534f84899c6e5594dba6749a"),
              ("127.0.0.3", "866a18b81f2dc4649517a1df13e26f28")]
     hashring = ConsistentHashRing(hosts, hash_type='fnv1a_ch')
     self.assertEqual(hashring.get_node('hosts.worker1.cpu'),
                      ('127.0.0.1', 'ba603c36342304ed77953f84ac4d357b'))
     self.assertEqual(hashring.get_node('hosts.worker2.cpu'),
                      ('127.0.0.3', '866a18b81f2dc4649517a1df13e26f28'))
     self.assertEqual(hashring.get_node(
                      'stats.checkout.cluster.padamski-wro.api.v1.payment-initialize.count'),
                      ('127.0.0.3', '866a18b81f2dc4649517a1df13e26f28'))
开发者ID:drawks,项目名称:carbon,代码行数:12,代码来源:test_hashing.py

示例3: ConsistentHashingRouter

class ConsistentHashingRouter(DatapointRouter):
  def __init__(self, replication_factor=1):
    self.replication_factor = int(replication_factor)
    self.instance_ports = {} # { (server, instance) : port }
    self.ring = ConsistentHashRing([])

  def addDestination(self, destination):
    (server, port, instance) = destination
    if (server, instance) in self.instance_ports:
      raise Exception("destination instance (%s, %s) already configured" % (server, instance))
    self.instance_ports[ (server, instance) ] = port
    self.ring.add_node( (server, instance) )

  def removeDestination(self, destination):
    (server, port, instance) = destination
    if (server, instance) not in self.instance_ports:
      raise Exception("destination instance (%s, %s) not configured" % (server, instance))
    del self.instance_ports[ (server, instance) ]
    self.ring.remove_node( (server, instance) )

  def getDestinations(self, metric):
    key = self.getKey(metric)

    used_servers = set()
    for (server, instance) in self.ring.get_nodes(key):
      if server in used_servers:
        continue
      else:
        used_servers.add(server)
        port = self.instance_ports[ (server, instance) ]
        yield (server, port, instance)

      if len(used_servers) >= self.replication_factor:
        return

  def getKey(self, metric):
    return metric

  def setKeyFunction(self, func):
    self.getKey = func

  def setKeyFunctionFromModule(self, keyfunc_spec):
    module_path, func_name = keyfunc_spec.rsplit(':', 1)
    module_file = open(module_path, 'U')
    description = ('.py', 'U', imp.PY_SOURCE)
    module = imp.load_module('keyfunc_module', module_file, module_path, description)
    keyfunc = getattr(module, func_name)
    self.setKeyFunction(keyfunc)
开发者ID:3ofcoins,项目名称:graphite_stack,代码行数:48,代码来源:routers.py

示例4: ConsistentHashingRouter

class ConsistentHashingRouter(DatapointRouter):
  def __init__(self, replication_factor=1):
    self.replication_factor = int(replication_factor)
    self.instance_ports = {} # { (server, instance) : port }
    self.ring = ConsistentHashRing([])

  def addDestination(self, destination):
    (server, port, instance) = destination
    if (server, instance) in self.instance_ports:
      raise Exception("destination instance (%s, %s) already configured" % (server, instance))
    self.instance_ports[ (server, instance) ] = port
    self.ring.add_node( (server, instance) )

  def removeDestination(self, destination):
    (server, port, instance) = destination
    if (server, instance) not in self.instance_ports:
      raise Exception("destination instance (%s, %s) not configured" % (server, instance))
    del self.instance_ports[ (server, instance) ]
    self.ring.remove_node( (server, instance) )

  def getDestinations(self, metric):
    key = self.getKey(metric)

    for count,node in enumerate(self.ring.get_nodes(key)):
      if count == self.replication_factor:
        return
      (server, instance) = node
      port = self.instance_ports[ (server, instance) ]
      yield (server, port, instance)

  #def getKey(self, metric):
  #  return metric
  
  def getKey(self, metric):
    #RBA: modification done to ensure that all the metrics to be aggregated are processed by the same aggregator
    return metric.rsplit('.',1)[0]
  
  def setKeyFunction(self, func):
    self.getKey = func

  def setKeyFunctionFromModule(self, keyfunc_spec):
    module_path, func_name = keyfunc_spec.rsplit(':', 1)
    module_file = open(module_path, 'U')
    description = ('.py', 'U', imp.PY_SOURCE)
    module = imp.load_module('keyfunc_module', module_file, module_path, description)
    keyfunc = getattr(module, func_name)
    self.setKeyFunction(keyfunc)
开发者ID:dmichau,项目名称:carbon,代码行数:47,代码来源:routers.py

示例5: __init__

  def __init__(self, settings):
    replication_factor = settings.REPLICATION_FACTOR
    diverse_replicas = settings.DIVERSE_REPLICAS

    self.replication_factor = int(replication_factor)
    self.diverse_replicas = diverse_replicas
    self.instance_ports = {}  # { (server, instance) : port }
    self.ring = ConsistentHashRing([])
开发者ID:criteo-forks,项目名称:carbon,代码行数:8,代码来源:routers.py

示例6: __init__

  def __init__(self, settings):
    replication_factor = settings.REPLICATION_FACTOR
    diverse_replicas = settings.DIVERSE_REPLICAS

    self.replication_factor = int(replication_factor)
    self.diverse_replicas = diverse_replicas
    self.instance_ports = {}  # { (server, instance) : port }
    hash_type = settings.ROUTER_HASH_TYPE or 'carbon_ch'
    self.ring = ConsistentHashRing([], hash_type=hash_type)
开发者ID:NixM0nk3y,项目名称:carbon,代码行数:9,代码来源:routers.py

示例7: test_chr_compute_ring_position_fnv1a

 def test_chr_compute_ring_position_fnv1a(self):
     hosts = [("127.0.0.1", "ba603c36342304ed77953f84ac4d357b"),
              ("127.0.0.2", "5dd63865534f84899c6e5594dba6749a"),
              ("127.0.0.3", "866a18b81f2dc4649517a1df13e26f28")]
     hashring = ConsistentHashRing(hosts, hash_type='fnv1a_ch')
     self.assertEqual(hashring.compute_ring_position('hosts.worker1.cpu'),
                      59573)
     self.assertEqual(hashring.compute_ring_position('hosts.worker1.load'),
                      57163)
     self.assertEqual(hashring.compute_ring_position('hosts.worker2.cpu'),
                      35749)
     self.assertEqual(hashring.compute_ring_position('hosts.worker2.network'),
                      43584)
     self.assertEqual(hashring.compute_ring_position('hosts.worker3.cpu'),
                      12600)
     self.assertEqual(hashring.compute_ring_position('hosts.worker3.irq'),
                      10052)
开发者ID:drawks,项目名称:carbon,代码行数:17,代码来源:test_hashing.py

示例8: __init__

 def __init__(self, replication_factor=1):
   self.replication_factor = int(replication_factor)
   self.instance_ports = {} # { (server, instance) : port }
   self.ring = ConsistentHashRing([])
开发者ID:phufool,项目名称:carbon,代码行数:4,代码来源:routers.py

示例9: ConsistentHashingRouter

class ConsistentHashingRouter(DatapointRouter):
  plugin_name = 'consistent-hashing'

  def __init__(self, settings):
    replication_factor = settings.REPLICATION_FACTOR
    diverse_replicas = settings.DIVERSE_REPLICAS

    self.replication_factor = int(replication_factor)
    self.diverse_replicas = diverse_replicas
    self.instance_ports = {}  # { (server, instance) : port }
    hash_type = settings.ROUTER_HASH_TYPE or 'carbon_ch'
    self.ring = ConsistentHashRing([], hash_type=hash_type)

  def addDestination(self, destination):
    (server, port, instance) = destination
    if self.hasDestination(destination):
      raise Exception("destination instance (%s, %s) already configured" % (server, instance))
    self.instance_ports[(server, instance)] = port
    self.ring.add_node((server, instance))

  def removeDestination(self, destination):
    (server, port, instance) = destination
    if not self.hasDestination(destination):
      raise Exception("destination instance (%s, %s) not configured" % (server, instance))
    del self.instance_ports[(server, instance)]
    self.ring.remove_node((server, instance))

  def hasDestination(self, destination):
    (server, _, instance) = destination
    return (server, instance) in self.instance_ports

  def countDestinations(self):
    return len(self.instance_ports)

  def getDestinations(self, metric):
    key = self.getKey(metric)
    if self.diverse_replicas:
      used_servers = set()
      for (server, instance) in self.ring.get_nodes(key):
        if server in used_servers:
          continue
        else:
          used_servers.add(server)
          port = self.instance_ports[(server, instance)]
          yield (server, port, instance)
        if len(used_servers) >= self.replication_factor:
          return
    else:
      for (count, node) in enumerate(self.ring.get_nodes(key)):
        if count == self.replication_factor:
          return
        (server, instance) = node
        port = self.instance_ports[(server, instance)]
        yield (server, port, instance)

  def getKey(self, metric):
    return metric

  def setKeyFunction(self, func):
    self.getKey = func

  def setKeyFunctionFromModule(self, keyfunc_spec):
    module_path, func_name = keyfunc_spec.rsplit(':', 1)
    module_file = open(module_path, 'U')
    description = ('.py', 'U', imp.PY_SOURCE)
    module = imp.load_module('keyfunc_module', module_file, module_path, description)
    keyfunc = getattr(module, func_name)
    self.setKeyFunction(keyfunc)
开发者ID:NixM0nk3y,项目名称:carbon,代码行数:68,代码来源:routers.py

示例10: test_11_get_nodes

 def test_11_get_nodes(self):
     """Trigger bisect on identical first key, see: issues/766"""
     ring = ConsistentHashRing([], replica_count=1)
     ring.add_node(("1", "1"))
     n = ring.get_nodes("('1', '1'):0")
     self.assertEqual([('1', '1')], list(n))
开发者ID:NixM0nk3y,项目名称:carbon,代码行数:6,代码来源:test_hashing.py


注:本文中的carbon.hashing.ConsistentHashRing类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。