Example #1
0
 def __init__(self):
     self.storage_ring = hash_ring.HashRing(storage_servers)
     self.max_sessions = 300
     self.sessions = [[None, threading.Condition()]
                      for i in range(self.max_sessions)]
     self.id = 0
     self.sessions_lock = threading.Lock()
Example #2
0
def organize(requests, out_trace, numclients, client_threads, port, wait,
             round_robin, push_rand):
    organized = []

    if round_robin is False:
        ring = hash_ring.HashRing(range(numclients))
    with open(out_trace, 'r') as f:
        blob = json.load(f)

    for i in range(numclients):
        organized.append([{
            'port': port,
            'id': random.getrandbits(32),
            'threads': client_threads,
            'wait': wait,
            'random': push_rand,
            'registry_repo': config('REGISTRY_REPO'),
            'registry_username': config('REGISTRY_USERNAME'),
            'registry_url': config('REGISTRY_URL'),
            'registry_password': config('REGISTRY_PASSWORD')
        }])
        print organized[-1][0]['id']
    i = 0

    for r in requests:
        request = {
            'delay': r['delay'],
            'duration': r['duration'],
            'document_type': r['document_type'],
            'method': r['method']
        }
        if r['uri'] in blob and r['method'] != 'PUT':
            b = blob[r['uri']]
            if b != 'bad':
                request['blob'] = b
                if round_robin is True:
                    organized[i % numclients].append(request)
                    i += 1
                else:
                    organized[ring.get_node(r['client'])].append(request)
        else:
            request['size'] = r['size']
            if round_robin is True:
                organized[i % numclients].append(request)
                i += 1
            else:
                organized[ring.get_node(r['client'])].append[(request)]

    return organized
Example #3
0
def organize(requests, out_trace, numclients, client_threads, port, wait,
             registries, round_robin, push_rand):
    organized = []

    if round_robin is False:
        ring = hash_ring.HashRing(range(numclients))
    with open(out_trace, 'r') as f:
        blob = json.load(f)

    for i in range(numclients):
        organized.append([{
            'port': port,
            'id': random.getrandbits(32),
            'threads': client_threads,
            'wait': wait,
            'registry': registries,
            'random': push_rand
        }])
        print organized[-1][0]['id']
    i = 0

    for r in requests:
        request = {
            'delay': r['delay'],
            'duration': r['duration'],
        }
        if r['uri'] in blob:
            b = blob[r['uri']]
            if b != 'bad':
                request['blob'] = b
                request['method'] = 'GET'
                if round_robin is True:
                    organized[i % numclients].append(request)
                    i += 1
                else:
                    organized[ring.get_node(r['client'])].append(request)
        else:
            request['size'] = r['size']
            request['method'] = 'PUT'
            if round_robin is True:
                organized[i % numclients].append(request)
                i += 1
            else:
                organized[ring.get_node(r['client'])].append(request)

    return organized
Example #4
0
    def create_nodes(self, location, **options):
        """ Create connections to redis nodes.

        @param str location: host:port indicating redis node location.
        @param dict options: redis options
        """
        nodes = []
        for i, node in enumerate(location):
            host, port = node.rsplit(':', 1)
            redis_pool = redis.ConnectionPool(host=host,
                                              port=port,
                                              db=self.db,
                                              **options)
            nodes.append(
                ConstRedis(connection_pool=redis_pool, hash_key=i, **options))
        self.nodes = nodes
        self.nodes_ring = hash_ring.HashRing(nodes)
    def __init__(self):

        self.ring_size = cfg.CONF.ml2_aci.tenant_ring_size
        self.tenant_prefix =cfg.CONF.ml2_aci.tenant_prefix

        items =cfg.CONF.ml2_aci.tenant_items_managed.split(":")

        if len(items) != 2:
           LOG.error("Managed items is incorrectly configured, should be in format n:m, where n is the starting tenant key and m is the last tenant key managed")
           raise

        start = int(items[0])
        stop = int(items[1])

        if start < 1 or stop > self.ring_size:
           LOG.error("Managed items is incorrectly configured, should be in format n:m, where n is the starting tenant key and m is the last tenant key managed")
           raise



        self._managed_range = range(start,stop+1)

        self.ring = hash_ring.HashRing(range(self.ring_size))
Example #6
0
#coding=utf-8
#Create on 2019/01/27
#author: zhzcsp

import hash_ring as hr
import redis

memcache_servers = ['127.0.0.1:6379', '127.0.0.1:6380']
ring = hr.HashRing(memcache_servers)
#server = ring.get_node('my_key')
"""
server = ring.get_node('my_key2234')
print server
r = redis.Redis(host=server.split(":")[0], port=int(server.split(":")[1]), db=0)
r.set("my_key223", "1231231")

server = ring.get_node('my_key')
print server
r = redis.Redis(host=server.split(":")[0], port=int(server.split(":")[1]), db=0)
r.set("my_key", "123")
"""

server = ring.delete_node("my_key")
r = redis.Redis(host=server.split(":")[0],
                port=int(server.split(":")[1]),
                db=0)
print "get content:"
print r.get("my_key")
Example #7
0
 def __init__(self, server_list):
     self.server_list = server_list
     self.ring = hash_ring.HashRing(self.server_list)
Example #8
0
#!/usr/bin/env python
# -*- coding: utf8 -*-

import uuid
import json

import hash_ring

from setting import conn
from setting import ring

_RING = hash_ring.HashRing(range(len(ring)))


def _pack(data): return json.dumps(data, ensure_ascii=False)
def _unpack(data): return json.loads(data or "{}")
def _key(data): return data

def _new_key():
    return uuid.uuid4().hex
    #return uuid.uuid3(uuid.NAMESPACE_DNS, "yourdomain.com").hex
    #return uuid.uuid5(uuid.NAMESPACE_DNS, "yourdomain.com").hex

def _number(key): return _RING.get_node(key)

def _node(key): return ring[_RING.get_node(key)]

def _get_entity_by_id(entity_id):
    entity = _node(entity_id).get("SELECT body FROM entities WHERE id = %s", _key(entity_id))
    return _unpack(entity["body"]) if entity else None
Example #9
0
import hash_ring

__all__ = ('phrase_ring', )

phrases = (
    '%(batter)s homers off of %(pitcher)s',
    '%(batter)s destroys a pitch from %(pitcher)s',
    '%(batter)s puts one out off of %(pitcher)s',
    '%(batter)s makes a souvenir out of one from %(pitcher)s',
    '%(batter)s takes %(pitcher)s deep',
    '%(batter)s goes deep off %(pitcher)s',
    '%(batter)s crushes one from %(pitcher)s',
    '%(batter)s hits a dinger off of %(pitcher)s',
    "%(batter)s touches 'em all against %(pitcher)s",
    '%(batter)s hits a gopher ball off of %(pitcher)s',
    '%(batter)s goes yard off of %(pitcher)s',
)

phrases = map(lambda v: v + ' #mlb #%(batter_team)s #%(pitcher_team)s',
              phrases)

phrase_ring = hash_ring.HashRing(phrases)
Example #10
0
#!/usr/bin/env python
# coding:utf-8


import hash_ring

print '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'
nodes = range(10)
print nodes

ring = hash_ring.HashRing(nodes)
# print ring

ns = []
for key in range(10):
    ns.append(ring.get_node(str(key)))
print ns
print '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'
nodes = range(15)
print nodes

ring = hash_ring.HashRing(nodes)
# print ring

ns = []
for key in range(10):
    ns.append(ring.get_node(str(key)))
print ns
print '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'

# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>