-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
50 lines (41 loc) · 1.29 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import asyncio
import time
import rakun_python
@rakun_python.AgentMetric
@rakun_python.Agent()
class MyAgent:
counter = 1
start_time = time.time_ns()
async def run(self):
while True:
msg = {
# "receiver": "myagent-1",
"data": {
"code": self.code,
"counter": self.counter,
"start_time": self.start_time,
}
}
await self.core.send(msg)
self.metric.save("count", self.counter)
# await asyncio.sleep(2)
async def receiver(self, sender, message):
metrics = self.metric.all()
print(metrics)
if self.counter % 20 == 0:
diff = (time.time_ns() - self.start_time) / 1e9
rate = self.counter / diff
print(f"Rate {sender} {self.code}: {rate:f} msg/s")
self.start_time = time.time_ns()
self.counter = 0
await self.core.exit()
self.counter += 1
async def main():
# agent = MyAgent()
agent_manager = rakun_python.AgentManager()
for i in range(2):
agent_manager.register(MyAgent, f"myagent-{i}")
await agent_manager.start()
# await agent.core.start()
if __name__ == '__main__':
asyncio.run(main())