def react_speed_in_loop(benchmark: BenchmarkControl, inbox_amount=1000) -> None:
    """
    Test inbox message processing in a loop.

    :param benchmark: benchmark special parameter to communicate with executor
    :param inbox_amount: num of inbox messages for every agent

    :return: None
    """
    aea_test_wrapper = AEATestWrapper(
        name="dummy agent",
        components=[
            AEATestWrapper.make_skill(handlers={"dummy_handler": DummyHandler})
        ],
    )

    for _ in range(inbox_amount):
        aea_test_wrapper.put_inbox(aea_test_wrapper.dummy_envelope())

    aea_test_wrapper.set_loop_timeout(0.0)

    benchmark.start()

    aea_test_wrapper.start_loop()

    while not aea_test_wrapper.is_inbox_empty():
        time.sleep(0.1)

    aea_test_wrapper.stop_loop()
def react_speed_in_loop(
    benchmark: BenchmarkControl,
    agents_num: int = 1,
    skills_num: int = 1,
    inbox_num: int = 5000,
    agent_loop_timeout: float = 0.01,
) -> None:
    """
    Test inbox message processing in a loop.

    Messages are generated by fake connection.

    :param benchmark: benchmark special parameter to communicate with executor
    :param agents_num: number of agents to start
    :param skills_num: number of skills to add to each agent
    :param inbox_num: num of inbox messages for every agent
    :param agent_loop_timeout: idle sleep time for agent's loop

    :return: None
    """
    wrappers = []
    envelope = AEATestWrapper.dummy_envelope()

    for i in range(agents_num):
        aea_test_wrapper = AEATestWrapper(
            **_make_custom_config(f"agent{i}", skills_num)
        )
        aea_test_wrapper.set_loop_timeout(agent_loop_timeout)
        aea_test_wrapper.set_fake_connection(inbox_num, envelope)
        wrappers.append(aea_test_wrapper)

    benchmark.start()

    for aea_test_wrapper in wrappers:
        aea_test_wrapper.start_loop()

    try:
        # wait all messages are pushed to inboxes
        while sum([i.is_messages_in_fake_connection() for i in wrappers]):
            time.sleep(0.01)

        # wait all messages are consumed from inboxes
        while sum([not i.is_inbox_empty() for i in wrappers]):
            time.sleep(0.01)
    finally:
        for aea_test_wrapper in wrappers:
            aea_test_wrapper.stop_loop()
Beispiel #3
0
def cpu_burn(benchmark: BenchmarkControl, run_time=10, sleep=0.0001) -> None:
    """
    Do nothing, just burn cpu to check cpu load changed on sleep.

    :param benchmark: benchmark special parameter to communicate with executor
    :param run_time: time limit to run this function
    :param sleep: time to sleep in loop

    :return: None
    """
    benchmark.start()
    start_time = time.time()

    while True:
        time.sleep(sleep)
        if time.time() - start_time >= run_time:
            break
Beispiel #4
0
def react_speed_in_loop(
    benchmark: BenchmarkControl,
    agents_num: int = 2,
    skills_num: int = 1,
    inbox_num: int = 1000,
    agent_loop_timeout: float = 0.01,
) -> None:
    """
    Test inbox message processing in a loop.

    :param benchmark: benchmark special parameter to communicate with executor
    :param agents_num: number of agents to start
    :param skills_num: number of skills to add to each agent
    :param inbox_num: num of inbox messages for every agent
    :param agent_loop_timeout: idle sleep time for agent's loop

    :return: None
    """
    aea_test_wrappers = []

    for i in range(agents_num):
        aea_test_wrapper = AEATestWrapper(
            **_make_custom_config(f"agent{i}", skills_num))
        aea_test_wrapper.set_loop_timeout(agent_loop_timeout)
        aea_test_wrappers.append(aea_test_wrapper)

        for _ in range(inbox_num):
            aea_test_wrapper.put_inbox(aea_test_wrapper.dummy_envelope())

    benchmark.start()

    for aea_test_wrapper in aea_test_wrappers:
        aea_test_wrapper.start_loop()

    try:
        while sum([not i.is_inbox_empty() for i in aea_test_wrappers]):
            time.sleep(0.1)

    finally:
        # wait to start, Race condition in case no messages to process
        while sum([not i.is_running() for i in aea_test_wrappers]):
            pass
        for aea_test_wrapper in aea_test_wrappers:
            aea_test_wrapper.stop_loop()
Beispiel #5
0
    def _prepare(self, func: Callable, args: tuple) -> Process:
        """
        Start process and wait process ready to be measured.

        :param func: function or callable to be tested for performance.
        :param args: tuple of argument to pass to function tested.

        :return: process with tested code
        """
        control: BenchmarkControl = BenchmarkControl()
        process = Process(target=func, args=(control, *args))
        process.start()
        msg = control.wait_msg()
        assert msg == control.START_MSG
        return process
Beispiel #6
0
    def _prepare(func: Callable, args: tuple) -> Process:
        """
        Start process and wait process ready to be measured.

        :param func: function or callable to be tested for performance.
        :param args: tuple of argument to pass to function tested.

        :return: process with tested code
        """
        control: BenchmarkControl = BenchmarkControl()
        process = Process(target=func, args=(control, *args))
        process.start()
        msg = control.wait_msg()
        if msg != control.START_MSG:
            raise ValueError("Msg does not match control start message.")
        return process