def run(duration: int, runtime_mode: str) -> List[Tuple[str, Union[int, float]]]: """Test act message generate performance.""" # 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) skill = make_skill(agent, behaviours={"test": TestBehaviour}) agent.resources.add_skill(skill) t = Thread(target=agent.start, daemon=True) t.start() wait_for_condition(lambda: agent.is_running, timeout=5) time.sleep(duration) agent.stop() t.join(5) rate = connection.count_in / duration return [ ("envelopes sent", cast(TestBehaviour, skill.behaviours["test"]).count), ("envelopes received", connection.count_in), ("rate(envelopes/second)", rate), ]
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, connection_mode: str) -> List[Tuple[str, Union[int, float]]]: """Test 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) if connection_mode not in CONNECTION_MODES: raise ValueError( f"bad connection mode {connection_mode}. valid is one of {list(CONNECTION_MODES.keys())}" ) base_cls = CONNECTION_MODES[connection_mode] conn_cls = type("conn_cls", (TestConnectionMixIn, base_cls), {}) connection = conn_cls.make() # type: ignore # pylint: disable=no-member 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() agent.stop() t.join(5) latency = mean( map(lambda x: x[1] - x[0], zip( connection.sends, connection.recvs, ))) total_amount = len(connection.recvs) rate = total_amount / duration return [ ("envelopes received", len(connection.recvs)), ("envelopes sent", len(connection.sends)), ("latency(ms)", 10**6 * latency), ("rate(envelopes/second)", rate), ]
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), ]