Example #1
0
    def connect_rpc(self, timeout):
        if self.site_type == SiteInfo.SiteType.Client:
            if self.process.client_rpc_proxy is not None:
                logger.info("client control rpc already connected for site %s",
                            self.name)
                self.rpc_proxy = self.process.client_rpc_proxy
                return True
            logger.info("start connect to client ctrl rpc for site %s @ %s:%s",
                        self.name, self.process.host_address,
                        self.process.rpc_port)
            port = self.process.rpc_port
        else:
            logger.info("start connect to server ctrl rpc for site %s @ %s:%s",
                        self.name, self.process.host_address, self.rpc_port)
            port = self.rpc_port

        connect_start = time.time()
        self.rpc_client = Client()
        result = None
        while (result != 0):
            bind_address = "{host}:{port}".format(
                host=self.process.host_address, port=port)
            result = self.rpc_client.connect(bind_address)
            if time.time() - connect_start > timeout:
                raise RuntimeError("rpc connect time out")
            time.sleep(0.1)

        if self.site_type == SiteInfo.SiteType.Client:
            self.process.client_rpc_proxy = ClientControlProxy(self.rpc_client)
            self.rpc_proxy = self.process.client_rpc_proxy
        else:
            self.rpc_proxy = ServerControlProxy(self.rpc_client)
        return True
Example #2
0
    def client_run(self, do_sample, do_sample_lock):
        try:
            i = 0
            while (i < len(self.c_info)):
                client = Client()
                con = 1
                connect_start = time.time()
                while (con != 0):
                    con = client.connect(self.c_info[i][0] + ":" +
                                         self.c_info[i][1])
                    if time.time() - connect_start > self.timeout:
                        self.client_kill()
                        return
                    time.sleep(0.1)
                self.rpc_proxy[i] = ClientControlProxy(client)
                #print "Connected to client: " + self.c_info[i][0] + ":" + self.c_info[i][1]
                i += 1

            ready_futures = []
            i = 0
            while (i < len(self.rpc_proxy)):
                ready_futures.append(
                    self.rpc_proxy[i].async_client_ready_block())
                i += 1
            i = 0
            while (i < len(ready_futures)):
                ready_futures[i].wait()
                i += 1

            res = self.rpc_proxy[0].sync_client_get_txn_names()
            for k, v in res.items():
                self.txn_names[k] = v

            print "Clients all ready"

            self.start_client()

            print "Clients started"

            self.benchmark_record(do_sample, do_sample_lock)
            self.client_shutdown()

        except:
            self.client_force_shutdown()
        print "Benchmark finished\n"
Example #3
0
    def client_run(self, do_sample, do_sample_lock):
        try:
            i = 0
            while (i < len(self.c_info)):
                client = Client()
                con = 1
                connect_start = time.time()
                while (con != 0):
                    con = client.connect(self.c_info[i][0] + ":" + self.c_info[i][1])
                    if time.time() - connect_start > self.timeout:
                        self.client_kill()
                        return
                    time.sleep(0.1)
                self.rpc_proxy[i] = ClientControlProxy(client)
                #print "Connected to client: " + self.c_info[i][0] + ":" + self.c_info[i][1]
                i += 1

            ready_futures = []
            i = 0
            while (i < len(self.rpc_proxy)):
                ready_futures.append(self.rpc_proxy[i].async_client_ready_block())
                i += 1
            i = 0
            while (i < len(ready_futures)):
                ready_futures[i].wait()
                i += 1

            res = self.rpc_proxy[0].sync_client_get_txn_names()
            for k, v in res.items():
                self.txn_names[k] = v

            print "Clients all ready"

            self.start_client()

            print "Clients started"

            self.benchmark_record(do_sample, do_sample_lock)
            self.client_shutdown()

        except:
            self.client_force_shutdown()
        print "Benchmark finished\n"
Example #4
0
    def connect_rpc(self, timeout):
        if self.site_type == SiteInfo.SiteType.Client:
            if self.process.client_rpc_proxy is not None:
                logger.info("client control rpc already connected for site %s",
                             self.name)
                self.rpc_proxy = self.process.client_rpc_proxy
                return True
            logger.info("start connect to client ctrl rpc for site %s @ %s:%s", 
                     self.name, 
                     self.process.host_address, 
                     self.process.rpc_port)
            port = self.process.rpc_port
        else:
            logger.info("start connect to server ctrl rpc for site %s @ %s:%s", 
                     self.name, 
                     self.process.host_address, 
                     self.rpc_port)
            port = self.rpc_port

        connect_start = time.time()
        self.rpc_client = Client()
        result = None 
        while (result != 0):
            bind_address = "{host}:{port}".format(
                host=self.process.host_address,
                port=port)
            result = self.rpc_client.connect(bind_address)
            if time.time() - connect_start > timeout:
                raise RuntimeError("rpc connect time out")
            time.sleep(0.1)

        if self.site_type == SiteInfo.SiteType.Client:
            self.process.client_rpc_proxy = ClientControlProxy(self.rpc_client)
            self.rpc_proxy = self.process.client_rpc_proxy
        else:
            self.rpc_proxy = ServerControlProxy(self.rpc_client)
        return True
Example #5
0
    def server_heart_beat(self, cond, s_init_finish, do_sample,
                          do_sample_lock):
        try:
            i = 0
            while (i < len(self.s_info)):
                client = Client()
                con = 1
                connect_start = time.time()
                while (con != 0):
                    con = client.connect(self.s_info[i][0] + ":" +
                                         self.s_info[i][1])
                    if time.time() - connect_start > self.timeout:
                        self.server_kill()
                        exit(1)
                    time.sleep(0.1)
                self.rpc_proxy[i] = ServerControlProxy(client)
                #print "Connected to server: " + self.s_info[i][0] + ":" + self.s_info[i][1]
                i += 1

            i = 0
            while (i < len(self.rpc_proxy)):
                while (self.rpc_proxy[i].sync_server_ready() != 1):
                    time.sleep(1)  # waiting for server to initialize
                i += 1

            cond.acquire()
            s_init_finish.value = 1
            cond.notify()
            cond.release()

            avg_r_cnt = 0.0
            avg_r_sz = 0.0
            avg_cpu_util = 0.0
            sample_result = []
            #timeout_counter = 0
            while (True):
                do_statistics = False
                do_sample_lock.acquire()
                if do_sample.value == 1:
                    do_statistics = True
                    do_sample.value = 0
                do_sample_lock.release()
                i = 0
                r_cnt_sum = 0
                r_cnt_num = 0
                r_sz_sum = 0
                r_sz_num = 0
                statistics = dict()
                cpu_util = [0.0] * len(self.rpc_proxy)
                futures = []
                while (i < len(self.rpc_proxy)):
                    if do_statistics:
                        futures.append(self.rpc_proxy[i].
                                       async_server_heart_beat_with_data())
                    else:
                        futures.append(
                            self.rpc_proxy[i].async_server_heart_beat())
                    i += 1

                i = 0
                while (i < len(futures)):
                    #if timeout_counter == 4:
                    if do_statistics:
                        ret = futures[i].result
                        r_cnt_sum += ret.r_cnt_sum
                        r_cnt_num += ret.r_cnt_num
                        r_sz_sum += ret.r_sz_sum
                        r_sz_num += ret.r_sz_num
                        cpu_util[i] = ret.cpu_util
                        for k, v in ret.statistics.items():
                            if k not in statistics:
                                statistics[k] = ServerResponse(v)
                            else:
                                statistics[k].add_one(v)
                    else:
                        futures[i].wait()
                    i += 1
                #if timeout_counter == 4:
                #    timeout_counter = 0
                if do_statistics:
                    total_result = []
                    interval_result = []
                    cur_time = time.time()
                    interval_time = cur_time - self.pre_time
                    self.pre_time = cur_time
                    for k, v in statistics.items():
                        total_result.append(
                            [k, v.get_value(),
                             v.get_times(),
                             v.get_ave()])
                        #if k not in self.pre_statistics:
                        interval_result.append([
                            k,
                            v.get_value(),
                            v.get_times(),
                            v.get_ave(), interval_time
                        ])
                        #else:
                        #    pre_v = self.pre_statistics[k]
                        #    value_buf = v.get_value() - pre_v.get_value()
                        #    times_buf = v.get_times() - pre_v.get_times()
                        #    if times_buf == 0:
                        #        interval_result.append([k, value_buf, times_buf, 0.0, interval_time])
                        #    else:
                        #        interval_result.append([k, value_buf, times_buf, 1.0 * value_buf / times_buf, interval_time])
                    #print "\n=== SERVER STATISTICS: ===\nTOTAL:\n" + tabulate(total_result, headers=["Key", "Total Number", "Times", "Ave"]) + "\n\nINTERVAL:\n" + tabulate(interval_result, headers=["Key", "Total Number", "Times", "Ave", "Time"]) + "\n==========================\n"
                    self.pre_statistics = statistics
                    #do_sample_lock.acquire()
                    #if (do_sample.value == 1):
                    sample_result = interval_result
                    #    avg_cpu_util = sum(cpu_util) / len(cpu_util)

                    #    do_sample.value = 0
                    #do_sample_lock.release()
                    avg_cpu_util = sum(cpu_util) / len(cpu_util)
                    if r_cnt_num != 0:
                        avg_r_cnt = (1.0 * r_cnt_sum) / r_cnt_num
                    else:
                        avg_r_cnt = -1.0
                    if r_sz_num != 0:
                        avg_r_sz = (1.0 * r_sz_sum) / r_sz_num
                    else:
                        avg_r_sz = -1.0
                cond.acquire()
                if (s_init_finish.value == 0):
                    cond.release()
                    break
                cond.release()
                time.sleep(self.timeout / 4)
                #timeout_counter += 1

            for single_record in sample_result:
                print "SERVREC: " + str(single_record[0]) + ": VALUE: " + str(
                    single_record[1]) + "; TIMES: " + str(
                        single_record[2]) + "; MEAN: " + str(
                            single_record[3]) + "; TIME: " + str(
                                single_record[4])
            print "CPUINFO: " + str(avg_cpu_util) + ";"
            print "AVG_LOG_FLUSH_CNT: " + str(avg_r_cnt) + ";"
            print "AVG_LOG_FLUSH_SZ: " + str(avg_r_sz) + ";"
            print "BENCHMARK_SUCCEED"

            print "Shutting down servers ..."
            i = 0
            while (i < len(self.rpc_proxy)):
                try:
                    self.rpc_proxy[i].sync_server_shutdown()
                except:
                    pass
                i += 1
            time.sleep(1)
            self.server_kill()
        except:
            cond.acquire()
            s_init_finish.value = 5
            cond.notify()
            cond.release()
            print "Shutting down servers ..."
            i = 0
            while (i < len(self.rpc_proxy)):
                try:
                    self.rpc_proxy[i].sync_server_shutdown()
                except:
                    pass
                i += 1
            time.sleep(1)
            self.server_kill()
Example #6
0
class SiteInfo:
    class SiteType:
        Client = 1
        Server = 2

    CTRL_PORT_DELTA = 10000
    id = -1

    @staticmethod
    def next_id():
        SiteInfo.id += 1
        return SiteInfo.id

    def __init__(self, process, site_name, site_type, port):
        self.id = SiteInfo.next_id()
        self.process = process
        self.name = site_name
        if type(site_type) == str:
            if site_type == 'client':
                self.site_type = SiteInfo.SiteType.Client
            else:
                self.site_type = SiteInfo.SiteType.Server
        else:
            self.site_type = site_type

        if site_type == 'client':
            self.port = int(port)
            self.rpc_port = int(port)
        elif port is not None:
            self.port = int(port)
            self.rpc_port = self.port + self.CTRL_PORT_DELTA
        else:
            logger.error("server definition should have a port")
            sys.exit(1)

    def connect_rpc(self, timeout):
        if self.site_type == SiteInfo.SiteType.Client:
            if self.process.client_rpc_proxy is not None:
                logger.info("client control rpc already connected for site %s",
                            self.name)
                self.rpc_proxy = self.process.client_rpc_proxy
                return True
            logger.info("start connect to client ctrl rpc for site %s @ %s:%s",
                        self.name, self.process.host_address,
                        self.process.rpc_port)
            port = self.process.rpc_port
        else:
            logger.info("start connect to server ctrl rpc for site %s @ %s:%s",
                        self.name, self.process.host_address, self.rpc_port)
            port = self.rpc_port

        connect_start = time.time()
        self.rpc_client = Client()
        result = None
        while (result != 0):
            bind_address = "{host}:{port}".format(
                host=self.process.host_address, port=port)
            result = self.rpc_client.connect(bind_address)
            if time.time() - connect_start > timeout:
                raise RuntimeError("rpc connect time out")
            time.sleep(0.1)

        if self.site_type == SiteInfo.SiteType.Client:
            self.process.client_rpc_proxy = ClientControlProxy(self.rpc_client)
            self.rpc_proxy = self.process.client_rpc_proxy
        else:
            self.rpc_proxy = ServerControlProxy(self.rpc_client)
        return True
Example #7
0
    def server_heart_beat(self, cond, s_init_finish, do_sample, do_sample_lock):
        try:
            i = 0
            while (i < len(self.s_info)):
                client = Client()
                con = 1
                connect_start = time.time()
                while (con != 0):
                    con = client.connect(self.s_info[i][0] + ":" + self.s_info[i][1])
                    if time.time() - connect_start > self.timeout:
                        self.server_kill()
                        exit(1)
                    time.sleep(0.1)
                self.rpc_proxy[i] = ServerControlProxy(client)
                #print "Connected to server: " + self.s_info[i][0] + ":" + self.s_info[i][1]
                i += 1

            i = 0
            while (i < len(self.rpc_proxy)):
                while (self.rpc_proxy[i].sync_server_ready() != 1):
                    time.sleep(1)# waiting for server to initialize
                i += 1

            cond.acquire()
            s_init_finish.value = 1
            cond.notify()
            cond.release()

            avg_r_cnt = 0.0
            avg_r_sz = 0.0
            avg_cpu_util = 0.0
            sample_result = []
            #timeout_counter = 0
            while (True):
                do_statistics = False
                do_sample_lock.acquire()
                if do_sample.value == 1:
                    do_statistics = True
                    do_sample.value = 0
                do_sample_lock.release()
                i = 0
                r_cnt_sum = 0
                r_cnt_num = 0
                r_sz_sum = 0
                r_sz_num = 0
                statistics = dict()
                cpu_util = [0.0] * len(self.rpc_proxy)
                futures = []
                while (i < len(self.rpc_proxy)):
                    if do_statistics:
                        futures.append(self.rpc_proxy[i].async_server_heart_beat_with_data())
                    else:
                        futures.append(self.rpc_proxy[i].async_server_heart_beat())
                    i += 1

                i = 0
                while (i < len(futures)):
                    #if timeout_counter == 4:
                    if do_statistics:
                        ret = futures[i].result
                        r_cnt_sum += ret.r_cnt_sum
                        r_cnt_num += ret.r_cnt_num
                        r_sz_sum += ret.r_sz_sum
                        r_sz_num += ret.r_sz_num
                        cpu_util[i] = ret.cpu_util
                        for k, v in ret.statistics.items():
                            if k not in statistics:
                                statistics[k] = ServerResponse(v)
                            else:
                                statistics[k].add_one(v)
                    else:
                        futures[i].wait()
                    i += 1
                #if timeout_counter == 4:
                #    timeout_counter = 0
                if do_statistics:
                    total_result = []
                    interval_result = []
                    cur_time = time.time()
                    interval_time = cur_time - self.pre_time
                    self.pre_time = cur_time
                    for k, v in statistics.items():
                        total_result.append([k, v.get_value(), v.get_times(), v.get_ave()])
                        #if k not in self.pre_statistics:
                        interval_result.append([k, v.get_value(), v.get_times(), v.get_ave(), interval_time])
                        #else:
                        #    pre_v = self.pre_statistics[k]
                        #    value_buf = v.get_value() - pre_v.get_value()
                        #    times_buf = v.get_times() - pre_v.get_times()
                        #    if times_buf == 0:
                        #        interval_result.append([k, value_buf, times_buf, 0.0, interval_time])
                        #    else:
                        #        interval_result.append([k, value_buf, times_buf, 1.0 * value_buf / times_buf, interval_time])
                    #print "\n=== SERVER STATISTICS: ===\nTOTAL:\n" + tabulate(total_result, headers=["Key", "Total Number", "Times", "Ave"]) + "\n\nINTERVAL:\n" + tabulate(interval_result, headers=["Key", "Total Number", "Times", "Ave", "Time"]) + "\n==========================\n"
                    self.pre_statistics = statistics
                    #do_sample_lock.acquire()
                    #if (do_sample.value == 1):
                    sample_result = interval_result
                    #    avg_cpu_util = sum(cpu_util) / len(cpu_util)

                    #    do_sample.value = 0
                    #do_sample_lock.release()
                    avg_cpu_util = sum(cpu_util) / len(cpu_util)
                    if r_cnt_num != 0:
                        avg_r_cnt = (1.0 * r_cnt_sum) / r_cnt_num
                    else:
                        avg_r_cnt = -1.0
                    if r_sz_num != 0:
                        avg_r_sz = (1.0 * r_sz_sum) / r_sz_num
                    else:
                        avg_r_sz = -1.0
                cond.acquire()
                if (s_init_finish.value == 0):
                    cond.release()
                    break
                cond.release()
                time.sleep(self.timeout / 4)
                #timeout_counter += 1

            for single_record in sample_result:
                print "SERVREC: " + str(single_record[0]) + ": VALUE: " + str(single_record[1]) + "; TIMES: " + str(single_record[2]) + "; MEAN: " + str(single_record[3]) + "; TIME: " + str(single_record[4])
            print "CPUINFO: " + str(avg_cpu_util) + ";"
            print "AVG_LOG_FLUSH_CNT: " + str(avg_r_cnt) + ";"
            print "AVG_LOG_FLUSH_SZ: " + str(avg_r_sz) + ";"
            print "BENCHMARK_SUCCEED"

            print "Shutting down servers ..."
            i = 0
            while (i < len(self.rpc_proxy)):
                try:
                    self.rpc_proxy[i].sync_server_shutdown()
                except:
                    pass
                i += 1
            time.sleep(1)
            self.server_kill()
        except:
            cond.acquire()
            s_init_finish.value = 5
            cond.notify()
            cond.release()
            print "Shutting down servers ..."
            i = 0
            while (i < len(self.rpc_proxy)):
                try:
                    self.rpc_proxy[i].sync_server_shutdown()
                except:
                    pass
                i += 1
            time.sleep(1)
            self.server_kill()
Example #8
0
class SiteInfo:
    class SiteType:
        Client = 1
        Server = 2

    CTRL_PORT_DELTA = 10000
    id = -1

    @staticmethod
    def next_id():
        SiteInfo.id += 1
        return SiteInfo.id

    def __init__(self, process, site_name, site_type, port):
        self.id = SiteInfo.next_id()
        self.process = process
        self.name = site_name 
        if type(site_type) == str:
            if site_type == 'client':
                self.site_type = SiteInfo.SiteType.Client
            else:
                self.site_type = SiteInfo.SiteType.Server
        else:
            self.site_type = site_type
        
        if site_type == 'client':
            self.port = int(port)
            self.rpc_port = int(port)
        elif port is not None:
            self.port = int(port)
            self.rpc_port = self.port + self.CTRL_PORT_DELTA
        else:
            logger.error("server definition should have a port")
            sys.exit(1) 


    def connect_rpc(self, timeout):
        if self.site_type == SiteInfo.SiteType.Client:
            if self.process.client_rpc_proxy is not None:
                logger.info("client control rpc already connected for site %s",
                             self.name)
                self.rpc_proxy = self.process.client_rpc_proxy
                return True
            logger.info("start connect to client ctrl rpc for site %s @ %s:%s", 
                     self.name, 
                     self.process.host_address, 
                     self.process.rpc_port)
            port = self.process.rpc_port
        else:
            logger.info("start connect to server ctrl rpc for site %s @ %s:%s", 
                     self.name, 
                     self.process.host_address, 
                     self.rpc_port)
            port = self.rpc_port

        connect_start = time.time()
        self.rpc_client = Client()
        result = None 
        while (result != 0):
            bind_address = "{host}:{port}".format(
                host=self.process.host_address,
                port=port)
            result = self.rpc_client.connect(bind_address)
            if time.time() - connect_start > timeout:
                raise RuntimeError("rpc connect time out")
            time.sleep(0.1)

        if self.site_type == SiteInfo.SiteType.Client:
            self.process.client_rpc_proxy = ClientControlProxy(self.rpc_client)
            self.rpc_proxy = self.process.client_rpc_proxy
        else:
            self.rpc_proxy = ServerControlProxy(self.rpc_client)
        return True