コード例 #1
0
    def handle(self, message: Message) -> None:
        """Handle incoming message."""
        self.count += 1

        if message.dialogue_reference[0] != "":
            rtt_ts, latency_ts = struct.unpack("dd",
                                               message.content)  # type: ignore
            if message.dialogue_reference[0] == self.context.agent_address:
                self.rtt_total_time += time.time() - rtt_ts
                self.rtt_count += 1

            self.latency_total_time += time.time() - latency_ts
            self.latency_count += 1

        if message.dialogue_reference[0] in ["", self.context.agent_address]:
            # create new
            response_msg = DefaultMessage(
                dialogue_reference=(self.context.agent_address, ""),
                message_id=1,
                target=0,
                performative=DefaultMessage.Performative.BYTES,
                content=struct.pack("dd", time.time(), time.time()),
            )
        else:
            # update ttfb copy rtt
            response_msg = DefaultMessage(
                dialogue_reference=message.dialogue_reference,
                message_id=1,
                target=0,
                performative=DefaultMessage.Performative.BYTES,
                content=struct.pack("dd", rtt_ts, time.time()),  # type: ignore
            )

        self.context.outbox.put(
            make_envelope(message.to, message.sender, response_msg))
コード例 #2
0
 def handle(self, message: Message) -> None:
     """Handle incoming message."""
     self.context.outbox.put(make_envelope(message.to, message.sender))
コード例 #3
0
 def act(self) -> None:
     """Perform action on periodic basis."""
     s = time.time()
     while time.time() - s < self.tick_interval:
         self.context.outbox.put(make_envelope("1", "2"))
         self.count += 1
コード例 #4
0
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),
    ]