44
55import simpy
66
7- from asyncflow .config .enums import SampledMetricName
7+ from asyncflow .config .enums import LbAlgorithmsName , SampledMetricName
8+ from asyncflow .runtime .actors .arrivals_generator import ArrivalsGeneratorRuntime
89from asyncflow .runtime .actors .edge import EdgeRuntime
10+ from asyncflow .runtime .actors .load_balancer import LoadBalancerRuntime
911from asyncflow .runtime .actors .server import ServerRuntime
1012from asyncflow .schemas .settings .simulation import SimulationSettings
1113
1719class SampledMetricCollector :
1820 """class to define a centralized object to collect sampled metrics"""
1921
20- def __init__ (
22+ def __init__ (# noqa: PLR0913
2123 self ,
2224 * ,
25+ arrivals : ArrivalsGeneratorRuntime ,
2326 edges : list [EdgeRuntime ],
2427 servers : list [ServerRuntime ],
28+ lb : LoadBalancerRuntime | None ,
2529 env : simpy .Environment ,
2630 sim_settings : SimulationSettings ,
2731 ) -> None :
2832 """
2933 Args:
34+ arrivals: (ArrivalsGeneratorRuntime): usefull to compute l_system
3035 edges (list[EdgeRuntime]): list of the class EdgeRuntime
3136 servers (list[ServerRuntime]): list of server of the class ServerRuntime
37+ lb (LoadBalancerRuntime): useful to compute Lq
3238 env (simpy.Environment): environment for the simulation
3339 sim_settings (SimulationSettings): general settings for the simulation
3440
3541 """
42+ self .arrivals = arrivals
3643 self .edges = edges
3744 self .servers = servers
45+ self .lb = lb
3846 self .sim_settings = sim_settings
3947 self .env = env
4048 self ._sample_period = sim_settings .sample_period_s
4149
4250
4351 # enum keys instance-level for mandatory sampled metrics to collect
44- self ._conn_key = SampledMetricName .EDGE_CONCURRENT_CONNECTION
45- self ._ram_key = SampledMetricName .RAM_IN_USE
46- self ._io_key = SampledMetricName .EVENT_LOOP_IO_SLEEP
47- self ._ready_key = SampledMetricName .READY_QUEUE_LEN
52+ self ._conn_key = SampledMetricName .EDGE_CONCURRENT_CONNECTION
53+ self ._ram_key = SampledMetricName .RAM_IN_USE
54+ self ._io_key = SampledMetricName .LQ_IO
55+ self ._ready_key = SampledMetricName .LQ_SERVER
56+ self ._l_system = SampledMetricName .L_SYSTEM
57+ self ._lq_lb = SampledMetricName .LQ_LB
4858
4959
5060 def _build_time_series (self ) -> Generator [simpy .Event , None , None ]:
@@ -65,6 +75,16 @@ def _build_time_series(self) -> Generator[simpy.Event, None, None]:
6575 server .enabled_metrics [self ._io_key ].append (server .io_queue_len )
6676 server .enabled_metrics [self ._ready_key ].append (server .ready_queue_len )
6777
78+ if self ._l_system in self .arrivals .enabled_metrics :
79+ self .arrivals .enabled_metrics [self ._l_system ].append (
80+ float (self .arrivals .l_system ),
81+ )
82+
83+ if (self .lb is not None and
84+ self .lb is not None and
85+ self .lb .lb_config .algorithms == LbAlgorithmsName .FCFS ):
86+ self .lb .enabled_metrics [self ._lq_lb ].append (self .lb .lq_lb )
87+
6888
6989
7090 def start (self ) -> None :
0 commit comments