File tree Expand file tree Collapse file tree 2 files changed +39
-2
lines changed Expand file tree Collapse file tree 2 files changed +39
-2
lines changed Original file line number Diff line number Diff line change
1
+ from maslite import Agent , Scheduler , AgentMessage
2
+
3
+ class Msg (AgentMessage ):
4
+ def __init__ (self , sender , receiver = None , topic = None ):
5
+ super ().__init__ (sender , receiver , topic )
6
+ self .value = 0
7
+
8
+ class A (Agent ):
9
+ def __init__ (self , uuid = None ):
10
+ super ().__init__ (uuid )
11
+
12
+ def update (self ):
13
+ if self .messages :
14
+ m = self .receive ()
15
+ assert isinstance (m , Msg )
16
+ m .value += 1
17
+ m .receiver , m .sender = m .sender , m .receiver
18
+ self .send (m )
19
+
20
+
21
+ if __name__ == "__main__" :
22
+ s = Scheduler ()
23
+ a = A ()
24
+ b = A ()
25
+ s .add (a )
26
+ s .add (b )
27
+ m = Msg (a ,b )
28
+ a .send (m )
29
+ s .run (seconds = 10 )
30
+ print (f"{ m .value / 10 :,} messages/second" )
31
+
32
+ # :~$ python3.10 benchmarks.py
33
+ # 340,283.8 messages/second
34
+
35
+ # :-$ pypy3 benchmarks.py
36
+ # 2,975,577.7 messages/second
37
+
Original file line number Diff line number Diff line change @@ -24,15 +24,15 @@ All right reserved © 2016-2023. MIT-license. All code has been written by t
24
24
MASlite is a simle python module for creating multi-agent simulations.
25
25
26
26
- _ Simple_ API: Only 3 modules to learn: Scheduler, Agent & Agent message
27
- - _ Fast_ : Handles up to 2.7 million messages per second
27
+ - _ Fast_ : Handles up to 2.7M messages per second ( [ pypy, py310 ] ( ./benchmark.py ) )
28
28
- _ Lightweight_ : 52kB.
29
29
30
30
It only has 3 components:
31
31
32
32
- The scheduler (main loop)
33
33
- handles pause and proceed with a single call.
34
34
- assures repeatability in execution, which makes agents easy to debug.
35
- - handles up to 2.7 million messages per second.
35
+ - handles up to 2.7M messages per second (pypy)
36
36
37
37
- Agent's
38
38
You can’t perform that action at this time.
0 commit comments