Skip to content

Commit 7649866

Browse files
authored
Features/simulation runner (#10)
* added the first method to the simulation runner * added methods to handle nodes * completed simulation runtime + integration test
1 parent 84f9897 commit 7649866

File tree

9 files changed

+637
-9
lines changed

9 files changed

+637
-9
lines changed

poetry.lock

Lines changed: 74 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ pydantic = {extras = ["email"], version = "^2.11.7"}
1616
numpy = "^2.3.1"
1717
simpy = "^4.1.1"
1818
matplotlib = "^3.10.3"
19+
pyyaml = "^6.0.2"
1920

2021
[tool.poetry.group.dev.dependencies]
2122
pytest = "^8.4.1"
2223
pytest-asyncio = "^1.0.0"
2324
pytest-cov = "^6.2.1"
2425
mypy = "^1.16.1"
2526
ruff = "^0.12.1"
27+
types-pyyaml = "^6.0.12.20250516"
2628

2729
[build-system]
2830
requires = ["poetry-core"]

src/app/metrics/analyzer.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,11 @@ def get_latency_stats(self) -> dict[LatencyKey, float]:
158158
return self.latency_stats or {}
159159

160160
def get_throughput_series(self) -> tuple[list[float], list[float]]:
161-
"""Return throughput time series (timestamps, RPS)."""
161+
"""Return (timestamps, RPS). Empty lists when no traffic."""
162162
self.process_all_metrics()
163-
assert self.throughput_series is not None
163+
if self.throughput_series is None:
164+
return [], []
165+
164166
return self.throughput_series
165167

166168
def get_sampled_metrics(self) -> dict[str, dict[str, list[float]]]:

src/app/runtime/actors/rqs_generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def __init__(
3535
self,
3636
*,
3737
env: simpy.Environment,
38-
out_edge: EdgeRuntime,
38+
out_edge: EdgeRuntime | None,
3939
rqs_generator_data: RqsGeneratorInput,
4040
sim_settings: SimulationSettings,
4141
rng: np.random.Generator | None = None,

src/app/runtime/actors/server.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,30 @@
2929
class ServerRuntime:
3030
"""class to define the server during the simulation"""
3131

32-
def __init__( # noqa: PLR0913
32+
def __init__( # noqa: PLR0913
3333
self,
3434
*,
3535
env: simpy.Environment,
3636
server_resources: ServerContainers,
3737
server_config: Server,
38-
out_edge: EdgeRuntime,
38+
out_edge: EdgeRuntime | None,
3939
server_box: simpy.Store,
4040
settings: SimulationSettings,
4141
rng: np.random.Generator | None = None,
42-
) -> None:
43-
"""Docstring to complete"""
42+
) -> None:
43+
"""
44+
Definition of the instance attributes
45+
Args:
46+
env (simpy.Environment): simpy environment
47+
server_resources (ServerContainers):resource defined in the
48+
input for each server
49+
server_config (Server): parameter to define the server from the input
50+
out_edge (EdgeRuntime): edge connecting the server to the next node
51+
server_box (simpy.Store): box with the states that the server
52+
should elaborate
53+
settings (SimulationSettings): general input settings for the simulation
54+
rng (np.random.Generator | None, optional): random number generator.
55+
"""
4456
self.env = env
4557
self.server_resources = server_resources
4658
self.server_config = server_config
@@ -231,6 +243,7 @@ def _handle_request( # noqa: PLR0915, PLR0912, C901
231243
self._ram_in_use -= total_ram
232244
yield self.server_resources[ServerResourceName.RAM.value].put(total_ram)
233245

246+
assert self.out_edge is not None
234247
self.out_edge.transport(state)
235248

236249

@@ -263,7 +276,6 @@ def _dispatcher(self) -> Generator[simpy.Event, None, None]:
263276
The main dispatcher loop. It pulls requests from the inbox and
264277
spawns a new '_handle_request' process for each one.
265278
"""
266-
assert self.out_edge is not None
267279
while True:
268280
# Wait for a request to arrive in the server's inbox
269281
raw_state = yield self.server_box.get()

0 commit comments

Comments
 (0)