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 tests.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.addresses.append('{}:{}'.format(rc_member.host,
                                                       rc_member.port))
    except (ImportError, NameError):
        config.network.addresses.append('127.0.0.1')

    client = hazelcast.HazelcastClient(config)
    my_map = client.get_map("default")
    for i in range(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)
Esempio n. 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.addresses.append("127.0.0.1")

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

    try:
        from tests.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.addresses.append('{}:{}'.format(rc_member.host,
                                                       rc_member.port))
    except (ImportError, NameError):
        config.network.addresses.append('127.0.0.1')

    client = hazelcast.HazelcastClient(config)

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

    print("START INIT")
    for key in range(0, ENTRY_COUNT):
        my_map.put(key, VALUE)
    for key in range(0, ENTRY_COUNT):
        my_map.get(key)
    print("INIT COMPLETE")
    return my_map
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 tests.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.addresses.append('{}:{}'.format(rc_member.host,
                                                       rc_member.port))
    except (ImportError, NameError):
        config.network.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 range(0, PROCESS_COUNT)
    ]
    for p in processes:
        p.start()

    start = time.time()
    counter = 1
    while counter < 1000:
        time.sleep(5)
        six.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
Esempio n. 4
0
def do_benchmark():
    THREAD_COUNT = 1
    ENTRY_COUNT = 10 * 1000
    VALUE_SIZE = 100
    GET_PERCENTAGE = 40
    PUT_PERCENTAGE = 40

    VALUE = "x" * VALUE_SIZE

    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 tests.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.addresses.append('{}:{}'.format(rc_member.host, rc_member.port))
    except (ImportError, NameError):
        config.network.addresses.append('127.0.0.1')

    client = hazelcast.HazelcastClient(config)

    class ClientThread(threading.Thread):
        def __init__(self, name):
            threading.Thread.__init__(self, name=name)
            self.gets = 0
            self.puts = 0
            self.removes = 0
            self.setDaemon(True)

        def run(self):
            my_map = client.get_map("default").blocking()
            while True:
                key = int(random.random() * ENTRY_COUNT)
                operation = int(random.random() * 100)
                if operation < GET_PERCENTAGE:
                    my_map.get(key)
                    self.gets += 1
                elif operation < GET_PERCENTAGE + PUT_PERCENTAGE:
                    my_map.put(key, VALUE)
                    self.puts += 1
                else:
                    my_map.remove(key)
                    self.removes += 1

    threads = [ClientThread("client-thread-%d" % i) for i in range(0, THREAD_COUNT)]
    for t in threads:
        t.start()

    start = time.time()
    counter = 1
    while counter < 1000:
        time.sleep(5)
        six.print_("ops per second : " + \
              str(sum([t.gets + t.puts + t.removes for t in threads]) // (time.time() - start)))
        for t in threads:
            six.print_("{}: put: {} get: {}: remove: {}".format(t.name, t.puts, t.gets, t.removes))
        counter += 1
Esempio n. 5
0
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 tests.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 range(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(1)
    time_taken = time.time() - start
    six.print_("Took {} seconds for {} requests".format(time_taken, REQ_COUNT))
    six.print_("ops per second: {}".format(t.ops // time_taken))
Esempio n. 6
0
 def create_rc():
     return HzRemoteController("127.0.0.1", 9701)