示例#1
0
def do_benchmark():
    THREAD_COUNT = 1
    ENTRY_COUNT = 10 * 1000
    VALUE_SIZE = 10000
    GET_PERCENTAGE = 40
    PUT_PERCENTAGE = 40

    logging.basicConfig(
        format='%(asctime)s%(msecs)03d [%(name)s] %(levelname)s: %(message)s',
        datefmt="%H:%M%:%S,")
    logging.getLogger().setLevel(logging.INFO)
    logger = logging.getLogger("main")

    config = hazelcast.ClientConfig()
    config.group_config.name = "dev"
    config.group_config.password = "******"

    try:
        from hzrc.client import HzRemoteController

        rc = HzRemoteController('127.0.0.1', '9701')

        if not rc.ping():
            logger.info("Remote Controller Server not running... exiting.")
            exit()
        logger.info("Remote Controller Server OK...")
        rc_cluster = rc.createCluster(None, None)
        rc_member = rc.startMember(rc_cluster.id)
        config.network_config.addresses.append('{}:{}'.format(
            rc_member.host, rc_member.port))
    except (ImportError, NameError):
        config.network_config.addresses.append('127.0.0.1')

    client = hazelcast.HazelcastClient(config)
    my_map = client.get_map("default")
    for i in xrange(0, 1000):
        key = int(random.random() * ENTRY_COUNT)
        operation = int(random.random() * 100)
        if operation < GET_PERCENTAGE:
            my_map.get(key)
        elif operation < GET_PERCENTAGE + PUT_PERCENTAGE:
            my_map.put(key, "x" * VALUE_SIZE)
        else:
            my_map.remove(key)
示例#2
0
def init():
    logging.basicConfig(
        format='%(asctime)s%(msecs)03d [%(name)s] %(levelname)s: %(message)s',
        datefmt="%H:%M%:%S,")
    logging.getLogger().setLevel(logging.INFO)
    logger = logging.getLogger("main")

    config = hazelcast.ClientConfig()
    config.group_config.name = "dev"
    config.group_config.password = "******"
    config.network_config.addresses.append("127.0.0.1")

    near_cache_config = NearCacheConfig(MAP_NAME)
    near_cache_config.in_memory_format = IN_MEMORY_FORMAT.OBJECT
    config.add_near_cache_config(near_cache_config)

    try:
        from hzrc.client import HzRemoteController

        rc = HzRemoteController('127.0.0.1', '9701')

        if not rc.ping():
            logger.info("Remote Controller Server not running... exiting.")
            exit()
        logger.info("Remote Controller Server OK...")
        rc_cluster = rc.createCluster(None, None)
        rc_member = rc.startMember(rc_cluster.id)
        config.network_config.addresses.append('{}:{}'.format(
            rc_member.host, rc_member.port))
    except (ImportError, NameError):
        config.network_config.addresses.append('127.0.0.1')

    client = hazelcast.HazelcastClient(config)

    my_map = client.get_map(MAP_NAME).blocking()

    print "START INIT"
    for key in xrange(0, ENTRY_COUNT):
        my_map.put(key, VALUE)
    for key in xrange(0, ENTRY_COUNT):
        my_map.get(key)
    print "INIT COMPLETE"
    return my_map
def do_benchmark():
    REQ_COUNT = 50000
    ENTRY_COUNT = 10 * 1000
    VALUE_SIZE = 10000
    GET_PERCENTAGE = 40
    PUT_PERCENTAGE = 40

    logging.basicConfig(
        format='%(asctime)s%(msecs)03d [%(name)s] %(levelname)s: %(message)s',
        datefmt="%H:%M%:%S,")
    logging.getLogger().setLevel(logging.INFO)
    logger = logging.getLogger("main")

    config = hazelcast.ClientConfig()
    config.group_config.name = "dev"
    config.group_config.password = "******"

    try:
        from hzrc.client import HzRemoteController

        rc = HzRemoteController('127.0.0.1', '9701')

        if not rc.ping():
            logger.info("Remote Controller Server not running... exiting.")
            exit()
        logger.info("Remote Controller Server OK...")
        rc_cluster = rc.createCluster(None, None)
        rc_member = rc.startMember(rc_cluster.id)
        config.network_config.addresses.append('{}:{}'.format(
            rc_member.host, rc_member.port))
    except (ImportError, NameError):
        config.network_config.addresses.append('127.0.0.1')

    client = hazelcast.HazelcastClient(config)

    class Test(object):
        def __init__(self):
            self.ops = 0
            self.event = threading.Event()

        def incr(self, _):
            self.ops += 1
            if self.ops == REQ_COUNT:
                self.event.set()

        def run(self):
            my_map = client.get_map("default")
            for _ in xrange(0, REQ_COUNT):
                key = int(random.random() * ENTRY_COUNT)
                operation = int(random.random() * 100)
                if operation < GET_PERCENTAGE:
                    my_map.get(key).add_done_callback(self.incr)
                elif operation < GET_PERCENTAGE + PUT_PERCENTAGE:
                    my_map.put(key,
                               "x" * VALUE_SIZE).add_done_callback(self.incr)
                else:
                    my_map.remove(key).add_done_callback(self.incr)

    t = Test()
    start = time.time()
    t.run()
    t.event.wait()
    time_taken = time.time() - start
    print("Took %s seconds for %d requests" % (time_taken, REQ_COUNT))
    print("ops per second: %s" % (t.ops / time_taken))
if __name__ == '__main__':
    logging.basicConfig(format='%(asctime)s%(msecs)03d [%(name)s] %(levelname)s: %(message)s', datefmt="%H:%M%:%S,")
    logging.getLogger().setLevel(logging.INFO)
    logger = logging.getLogger("main")

    config = hazelcast.ClientConfig()
    config.group_config.name = "dev"
    config.group_config.password = "******"

    config.serialization_config.portable_factories[FACTORY_ID] = \
        {SamplePortable.CLASS_ID: SamplePortable}

    try:
        from hzrc.client import HzRemoteController

        rc = HzRemoteController('127.0.0.1', '9701')

        if not rc.ping():
            logger.info("Remote Controller Server not running... exiting.")
            exit()
        logger.info("Remote Controller Server OK...")
        rc_cluster = rc.createCluster(None, None)
        rc_member = rc.startMember(rc_cluster.id)
        config.network_config.addresses.append('{}:{}'.format(rc_member.host, rc_member.port))
    except (ImportError, NameError):
        config.network_config.addresses.append('127.0.0.1')

    client = hazelcast.HazelcastClient(config)

    my_map = client.get_map("map").blocking()  # returns sync map, all map functions are blocking
    print(my_map)
示例#5
0
import logging
from time import sleep

import hazelcast

if __name__ == '__main__':
    logging.basicConfig(
        format='%(asctime)s%(msecs)03d [%(name)s] %(levelname)s: %(message)s',
        datefmt="%H:%M%:%S,")
    logging.getLogger().setLevel(logging.INFO)
    logger = logging.getLogger("main")

    config = hazelcast.ClientConfig()
    try:
        from hzrc.client import HzRemoteController
        rc = HzRemoteController('127.0.0.1', '9701')

        if not rc.ping():
            logger.info("Remote Controller Server not running... exiting.")
            exit()
        logger.info("Remote Controller Server OK...")
        rc_cluster = rc.createCluster(None, None)
        rc_member = rc.startMember(rc_cluster.id)
        config.network_config.addresses.append('{}:{}'.format(
            rc_member.host, rc_member.port))
    except (ImportError, NameError):
        config.network_config.addresses.append('127.0.0.1')

    config.group_config.name = "dev"
    config.group_config.password = "******"
 def create_rc():
     return HzRemoteController('127.0.0.1', 9701)
def do_benchmark():
    PROCESS_COUNT = 10
    ENTRY_COUNT = 10 * 1000
    VALUE_SIZE = 10000
    GET_PERCENTAGE = 40
    PUT_PERCENTAGE = 40

    logging.basicConfig(format='%(asctime)s%(msecs)03d [%(name)s] %(levelname)s: %(message)s', datefmt="%H:%M%:%S,")
    logging.getLogger().setLevel(logging.INFO)
    logger = logging.getLogger("main")

    config = hazelcast.ClientConfig()
    config.group_config.name = "dev"
    config.group_config.password = "******"

    try:
        from hzrc.client import HzRemoteController

        rc = HzRemoteController('127.0.0.1', '9701')

        if not rc.ping():
            logger.info("Remote Controller Server not running... exiting.")
            exit()
        logger.info("Remote Controller Server OK...")
        rc_cluster = rc.createCluster(None, None)
        rc_member = rc.startMember(rc_cluster.id)
        config.network_config.addresses.append('{}:{}'.format(rc_member.host, rc_member.port))
    except (ImportError, NameError):
        config.network_config.addresses.append('127.0.0.1')

    client = hazelcast.HazelcastClient(config)

    class ClientProcess(multiprocessing.Process):
        def __init__(self, name, config, counts):
            multiprocessing.Process.__init__(self, name=name)
            self.counts = counts
            self.config = config
            self.daemon = True

        def run(self):
            client = hazelcast.HazelcastClient(config)
            my_map = client.get_map("default")
            while True:
                key = int(random.random() * ENTRY_COUNT)
                operation = int(random.random() * 100)
                if operation < GET_PERCENTAGE:
                    my_map.get(key)
                    self.counts[0] += 1
                elif operation < GET_PERCENTAGE + PUT_PERCENTAGE:
                    my_map.put(key, "x" * VALUE_SIZE)
                    self.counts[1] += 1
                else:
                    my_map.remove(key)
                    self.counts[2] += 1

    processes = [ClientProcess("client-process-%d" % i, config, multiprocessing.Array('i', 3)) for i in
                 xrange(0, PROCESS_COUNT)]
    for p in processes:
        p.start()

    start = time.time()
    counter = 1
    while counter < 1000:
        time.sleep(5)
        print "ops per second : " + \
              str(sum([sum(p.counts) for p in processes]) / (time.time() - start))
        # for p in processes:
        #     print ("%s: put: %d get: %d: remove: %d" % (p.name, p.counts[0], p.counts[1], p.counts[2]))
        counter += 1
示例#8
0
 def setUpClass(cls):
     cls.controller = HzRemoteController('localhost', 9701)