示例#1
0
    def run(self):
        """
        Run the test.
        """

        utils.print_header("Start {}...\n".format(self.get_kind_of_test()))

        if not self.options.log:
            utils.start_capture_console()
        self.start_time = time.time()
        if self.options.adding or self.options.getting \
                and self.options.clients > 1:
            self.start_tester_in_thread()
        else:
            self.list_tester.append(self.create_tester())
            utils.run_async_method(None, self.list_tester[-1].test)

        self.finish_time = time.time()

        utils.stop_capture_console()
        self.collect_result()
        with open(self.result_path, 'w') as result:
            self.write_result(result)
        self.write_result(sys.stdout)
        requests_sender.RequestsSender.close_log_file()

        utils.print_header("\nFinish {}\n".format(self.get_kind_of_test()))
示例#2
0
 def run_tester_in_thread(tester):
     """
     Execute testing function of tester.
     """
     loop = asyncio.new_event_loop()
     utils.run_async_method(loop, tester.test)
     loop.close()
示例#3
0
 def run_tester_in_thread(tester):
     """
     Execute testing function of tester.
     """
     loop = asyncio.new_event_loop()
     utils.run_async_method(loop, tester.test)
     loop.close()
示例#4
0
    def run(self):
        """
        Run the test.
        """

        utils.print_header("Start {}...\n".format(self.get_kind_of_test()))

        if not self.options.log:
            utils.start_capture_console()
        self.start_time = time.time()
        if self.options.adding or self.options.getting \
                and self.options.clients > 1:
            self.start_tester_in_thread()
        else:
            self.list_tester.append(self.create_tester())
            utils.run_async_method(None, self.list_tester[-1].test)

        self.finish_time = time.time()

        utils.stop_capture_console()
        self.collect_result()
        with open(self.result_path, 'w') as result:
            self.write_result(result)
        self.write_result(sys.stdout)
        requests_sender.RequestsSender.close_log_file()

        utils.print_header("\nFinish {}\n".format(self.get_kind_of_test()))
示例#5
0
    def submit_reqs_in_thread(self, args, file, kind):
        """
        Thread function that submit request from one request file.

        :param args: arguments to submit requests.
        :param file: request file (store all request you want to submit).
        :param kind: kind of request.
        """
        start_time = finish_time = 0
        with open(file, "r") as req_file:
            loop = asyncio.new_event_loop()
            asyncio.set_event_loop(loop)
            for line in req_file:
                response_time = utils.run_async_method(loop, self.submit_req,
                                                       args, kind, line)
                if start_time == 0:
                    start_time = response_time
                if response_time > finish_time:
                    finish_time = response_time
            loop.close()
        try:
            os.remove(file)
        except IOError as e:
            utils.force_print_error_to_console(str(e) + "\n")

        self.update_start_and_finish_time(start_time, finish_time)
示例#6
0
    def __init__(self, number_of_clients: int = 2,
                 transactions_delay: int = 100,
                 time_out: int = 300, log=False,
                 seed="000000000000000000000000Trustee1"):
        super().__init__(log=log, seed=seed)
        utils.run_async_method(
            None, TesterSimulateTraffic._prepare_samples_for_get_req,
            TesterSimulateTraffic.__number_of_request_samples)

        if time_out <= 0 or transactions_delay <= 0 or number_of_clients <= 0:
            return

        self.transactions_delay = transactions_delay
        self.time_out = time_out
        self.number_of_clients = number_of_clients
        self.current_total_txn = 0
        self.__current_time = time.time()
        self.__lock = threading.Lock()
        self.__sender = requests_sender.RequestsSender()
示例#7
0
    def __simulate_client(self):
        """
        Simulate the client to perform the test.
        """
        loop = asyncio.new_event_loop()
        args = {"wallet_handle": self.wallet_handle,
                "pool_handle": self.pool_handle,
                "submitter_did": self.submitter_did}

        asyncio.set_event_loop(loop)
        while time.time() - self.__current_time < self.time_out:
            if self.__update():
                break

            self.finish_time = utils.run_async_method(
                loop, TesterSimulateLoad._build_and_send_request,
                self.__sender, args)

        loop.close()
示例#8
0
    def __simulate_client(self):
        """
        Simulate a client to create real time traffic.
        """
        loop = asyncio.new_event_loop()
        args = {"wallet_handle": self.wallet_handle,
                "pool_handle": self.pool_handle,
                "submitter_did": self.submitter_did}

        asyncio.set_event_loop(loop)
        while True:
            self.__update()
            if time.time() - self.__current_time >= self.time_out:
                break

            self.finish_time = utils.run_async_method(
                loop, TesterSimulateTraffic._build_and_send_request,
                self.__sender, args)

        loop.close()
示例#9
0
    def __simulate_client(self):
        """
        Simulate the client to perform the test.
        """
        loop = asyncio.new_event_loop()
        args = {
            "wallet_handle": self.wallet_handle,
            "pool_handle": self.pool_handle,
            "submitter_did": self.submitter_did
        }

        asyncio.set_event_loop(loop)
        while time.time() - self.__current_time < self.time_out:
            if self.__update():
                break

            self.finish_time = utils.run_async_method(
                loop, TesterSimulateLoad._build_and_send_request,
                self.__sender, args)

        loop.close()
示例#10
0
    async def _build_and_send_request(sender, args):
        """
        Build a request and send it onto ledger.

        :param sender: send the request.
        :param args: contains some arguments to send request to ledger
                     (pool handle, wallet handle, submitter did)
        :return: response time.
        """
        kind = TesterSimulateLoad._random_req_kind()

        req = await requests_builder.RequestBuilder.build_request(args, kind)

        return await sender.send_request(args, kind, req)


if __name__ == '__main__':
    opts = Option().args

    tester = TesterSimulateLoad(time_out=opts.time_out,
                                number_of_clients=opts.clients,
                                log=opts.log,
                                number_of_transactions=opts.transactions_num)

    utils.run_async_method(None, tester.test)

    elapsed_time = tester.finish_time - tester.start_time

    utils.print_client_result(tester.passed_req, tester.failed_req,
                              elapsed_time)
示例#11
0
        """
        Collect all request info file from directory.

        :return: list of file name.
        """
        lst_files = glob.glob(
            os.path.join(self.info_dir,
                         '{}_requests_info*{}'.format(self.req_kind, '.txt')))
        if not lst_files:
            utils.force_print_error_to_console(
                'Cannot found any request info. '
                'Skip sending get request... Abort')
            sys.exit(1)

        return lst_files


if __name__ == '__main__':
    options = Options()
    opts = options.args
    tester = PerformanceTesterGetSentRequestFromLedger(opts.info_dir,
                                                       opts.kind,
                                                       opts.thread_num,
                                                       opts.log)

    # Start the method
    elapsed_time = utils.run_async_method(None, tester.test)

    utils.print_client_result(tester.passed_req, tester.failed_req,
                              elapsed_time)
示例#12
0
        """
        Collect all request info file from directory.

        :return: list of file name.
        """
        lst_files = glob.glob(os.path.join(
            self.info_dir, '{}_requests_info*{}'.format(self.req_kind,
                                                        '.txt')))
        if not lst_files:
            utils.force_print_error_to_console(
                'Cannot found any request info. '
                'Skip sending get request... Abort')
            sys.exit(1)

        return lst_files


if __name__ == '__main__':
    options = Options()
    opts = options.args
    tester = PerformanceTesterGetSentRequestFromLedger(opts.info_dir,
                                                       opts.kind,
                                                       opts.thread_num,
                                                       opts.log)

    # Start the method
    elapsed_time = utils.run_async_method(None, tester.test)

    utils.print_client_result(tester.passed_req, tester.failed_req,
                              elapsed_time)
示例#13
0
    async def _build_and_send_request(sender, args):
        """
        Build a request and send it onto ledger.

        :param sender: send the request.
        :param args: contains some arguments to send request to ledger
                     (pool handle, wallet handle, submitter did)
        :return: response time.
        """
        kind = TesterSimulateLoad._random_req_kind()

        req = await requests_builder.RequestBuilder.build_request(args, kind)

        return await sender.send_request(args, kind, req)


if __name__ == '__main__':
    opts = Option().args

    tester = TesterSimulateLoad(time_out=opts.time_out,
                                number_of_clients=opts.clients,
                                log=opts.log,
                                number_of_transactions=opts.transactions_num)

    utils.run_async_method(None, tester.test)

    elapsed_time = tester.finish_time - tester.start_time

    utils.print_client_result(tester.passed_req, tester.failed_req,
                              elapsed_time)