def run(messages_amount: int): """Test messages generation and memory consumption with dialogues.""" handler = DialogueHandler() mem_usage_on_start = get_mem_usage_in_mb() start_time = time.time() for _ in range(messages_amount): handler.process_message() mem_usage = get_mem_usage_in_mb() return [ ("Mem usage(Mb)", mem_usage - mem_usage_on_start), ("Time (seconds)", time.time() - start_time), ]
def run(messages_amount: int) -> List[Tuple[str, Union[int, float]]]: """Test messages generation and memory consumption.""" messages: List[Any] = [ 0 for i in range(messages_amount) ] # generate dummy list to count list structure memory mem_usage_on_start = get_mem_usage_in_mb() start_time = time.time() for i in range(messages_amount): messages[i] = make_message() mem_usage = get_mem_usage_in_mb() return [ ("Mem usage(Mb)", mem_usage - mem_usage_on_start), ("Time (seconds)", time.time() - start_time), ]
def run(duration: int, runtime_mode: str) -> List[Tuple[str, Union[int, float]]]: """Check memory usage.""" # pylint: disable=import-outside-toplevel,unused-import # import manually due to some lazy imports in decision_maker import aea.decision_maker.default # noqa: F401 agent = make_agent(runtime_mode=runtime_mode) connection = SyncedGeneratorConnection.make() agent.resources.add_connection(connection) agent.resources.add_skill(make_skill(agent, handlers={"test": TestHandler})) t = Thread(target=agent.start, daemon=True) t.start() wait_for_condition(lambda: agent.is_running, timeout=5) connection.enable() time.sleep(duration) connection.disable() mem_usage = get_mem_usage_in_mb() agent.stop() t.join(5) rate = connection.count_in / duration return [ ("envelopes received", connection.count_in), ("envelopes sent", connection.count_out), ("rate (envelopes/second)", rate), ("mem usage (Mb)", mem_usage), ]
def run( duration: int, runtime_mode: str, runner_mode: str, start_messages: int, num_of_agents: int, ) -> List[Tuple[str, Union[int, float]]]: """Test multiagent message exchange.""" # pylint: disable=import-outside-toplevel,unused-import # import manually due to some lazy imports in decision_maker import aea.decision_maker.default # noqa: F401 local_node = LocalNode() local_node.start() agents = [] skills = {} handler_name = "httpingpong" for i in range(num_of_agents): agent_name = f"agent{i}" agent = make_agent(agent_name=agent_name, runtime_mode=runtime_mode) connection = OEFLocalConnection( local_node, configuration=ConnectionConfig( connection_id=OEFLocalConnection.connection_id, ), identity=agent.identity, ) agent.resources.add_connection(connection) skill = make_skill(agent, handlers={handler_name: HttpPingPongHandler}) agent.resources.add_skill(skill) agents.append(agent) skills[agent_name] = skill runner = AEARunner(agents, runner_mode) runner.start(threaded=True) for agent in agents: wait_for_condition(lambda: agent.is_running, timeout=5) wait_for_condition(lambda: runner.is_running, timeout=5) time.sleep(1) for agent1, agent2 in itertools.permutations(agents, 2): for _ in range(int(start_messages)): cast( HttpPingPongHandler, skills[agent1.identity.address].handlers[handler_name], ).make_request(agent2.identity.address) time.sleep(duration) mem_usage = get_mem_usage_in_mb() local_node.stop() runner.stop() total_messages = sum([ cast(HttpPingPongHandler, skill.handlers[handler_name]).count for skill in skills.values() ]) rate = total_messages / duration rtt_total_time = sum([ cast(HttpPingPongHandler, skill.handlers[handler_name]).rtt_total_time for skill in skills.values() ]) rtt_count = sum([ cast(HttpPingPongHandler, skill.handlers[handler_name]).rtt_count for skill in skills.values() ]) if rtt_count == 0: rtt_count = -1 latency_total_time = sum([ cast(HttpPingPongHandler, skill.handlers[handler_name]).latency_total_time for skill in skills.values() ]) latency_count = sum([ cast(HttpPingPongHandler, skill.handlers[handler_name]).latency_count for skill in skills.values() ]) if latency_count == 0: latency_count = -1 return [ ("Total Messages handled", total_messages), ("Messages rate(envelopes/second)", rate), ("Mem usage(Mb)", mem_usage), ("RTT (ms)", rtt_total_time / rtt_count), ("Latency (ms)", latency_total_time / latency_count), ]
def run(duration, runtime_mode, runner_mode, start_messages, num_of_agents): """Test multiagent message exchange.""" # pylint: disable=import-outside-toplevel,unused-import # import manually due to some lazy imports in decision_maker import aea.decision_maker.default # noqa: F401 local_node = LocalNode() local_node.start() agents = [] skills = [] for i in range(num_of_agents): agent = make_agent(agent_name=f"agent{i}", runtime_mode=runtime_mode) connection = OEFLocalConnection( local_node, configuration=ConnectionConfig( connection_id=OEFLocalConnection.connection_id, ), identity=agent.identity, ) agent.resources.add_connection(connection) skill = make_skill(agent, handlers={"test": TestHandler}) agent.resources.add_skill(skill) agents.append(agent) skills.append(skill) runner = AEARunner(agents, runner_mode) runner.start(threaded=True) for agent in agents: wait_for_condition(lambda: agent.is_running, timeout=5) wait_for_condition(lambda: runner.is_running, timeout=5) time.sleep(1) for agent1, agent2 in itertools.permutations(agents, 2): env = make_envelope(agent1.identity.address, agent2.identity.address) for _ in range(int(start_messages)): agent1.outbox.put(env) time.sleep(duration) mem_usage = get_mem_usage_in_mb() local_node.stop() runner.stop() total_messages = sum([skill.handlers["test"].count for skill in skills]) rate = total_messages / duration rtt_total_time = sum( [skill.handlers["test"].rtt_total_time for skill in skills]) rtt_count = sum([skill.handlers["test"].rtt_count for skill in skills]) if rtt_count == 0: rtt_count = -1 latency_total_time = sum( [skill.handlers["test"].latency_total_time for skill in skills]) latency_count = sum( [skill.handlers["test"].latency_count for skill in skills]) if latency_count == 0: latency_count = -1 return [ ("Total Messages handled", total_messages), ("Messages rate(envelopes/second)", rate), ("Mem usage(Mb)", mem_usage), ("RTT (ms)", rtt_total_time / rtt_count), ("Latency (ms)", latency_total_time / latency_count), ]