1010import numpy as np
1111
1212from asyncflow .config .enums import SystemNodes
13+ from asyncflow .metrics .client import RqsClock
1314from asyncflow .runtime .rqs_state import RequestState
1415from asyncflow .samplers .arrivals import general_interarrivals
1516
2526
2627class ArrivalsGeneratorRuntime :
2728 """
28- A “ node” that produces request contexts at stochastic inter-arrival times
29+ A node that produces request contexts at stochastic inter-arrival times
2930 and immediately pushes them down the pipeline via an EdgeRuntime.
3031 """
3132
32- def __init__ (
33+ def __init__ ( # noqa: PLR0913
3334 self ,
3435 * ,
3536 env : simpy .Environment ,
3637 out_edge : EdgeRuntime | None ,
3738 arrivals : ArrivalsGenerator ,
3839 sim_settings : SimulationSettings ,
3940 rng : np .random .Generator | None = None ,
41+ arrivals_generator_box : simpy .Store ,
42+ completed_box : simpy .Store ,
4043 ) -> None :
4144 """
4245 Definition of the instance attributes for the ArrivalsGeneratorRuntime
@@ -47,14 +50,19 @@ def __init__(
4750 arrivals (ArrivalsGenerator): data do define the sampler
4851 sim_settings (SimulationSettings): settings to start the simulation
4952 rng (np.random.Generator | None, optional): random variable generator.
53+ arrivals_generator_box: simpy box to collect request when they come back
54+ completed_box: box to collect all satisfied requests
5055
5156 """
5257 self .arrivals = arrivals
5358 self .sim_settings = sim_settings
5459 self .rng = rng or np .random .default_rng ()
5560 self .out_edge = out_edge
5661 self .env = env
62+ self .arrivals_generator_box = arrivals_generator_box
63+ self .completed_box = completed_box
5764 self .id_counter = 0
65+ self ._rqs_clock : list [RqsClock ] = []
5866
5967
6068 def _next_id (self ) -> int :
@@ -90,6 +98,28 @@ def _event_arrival(self) -> Generator[simpy.Event, None, None]:
9098 # from one node to another
9199 self .out_edge .transport (state )
92100
101+ def _collector (self ) -> Generator [simpy .Event , None , None ]:
102+ """The request has been satisfied"""
103+ while True :
104+ state : RequestState = yield self .arrivals_generator_box .get () # type: ignore[assignment]
105+
106+ state .finish_time = self .env .now
107+ clock_data = RqsClock (
108+ start = state .initial_time ,
109+ finish = state .finish_time ,
110+ )
111+ self ._rqs_clock .append (clock_data )
112+ yield self .completed_box .put (state )
113+
114+
93115 def start (self ) -> simpy .Process :
94116 """Passing the structure as a simpy process"""
95- return self .env .process (self ._event_arrival ())
117+ self .env .process (self ._event_arrival ())
118+ self .env .process (self ._collector ())
119+
120+
121+
122+ @property
123+ def rqs_clock (self ) -> list [RqsClock ]:
124+ """Readable version to compute aggregate metrics"""
125+ return self ._rqs_clock
0 commit comments