Skip to content

Commit f0cdd46

Browse files
committed
improved tests and all calculation of th. vs observed indip
1 parent 667e435 commit f0cdd46

9 files changed

Lines changed: 538 additions & 631 deletions

File tree

asyncflow_queue_limit/asyncflow_mm1.ipynb

Lines changed: 65 additions & 336 deletions
Large diffs are not rendered by default.

asyncflow_queue_limit/asyncflow_mmc.ipynb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
},
2121
{
2222
"cell_type": "code",
23-
"execution_count": 9,
23+
"execution_count": 19,
2424
"id": "3e168d4a",
2525
"metadata": {},
2626
"outputs": [],
@@ -45,7 +45,7 @@
4545
},
4646
{
4747
"cell_type": "code",
48-
"execution_count": 10,
48+
"execution_count": 20,
4949
"id": "dd39a8e3",
5050
"metadata": {},
5151
"outputs": [
@@ -112,7 +112,7 @@
112112
},
113113
{
114114
"cell_type": "code",
115-
"execution_count": 11,
115+
"execution_count": 21,
116116
"id": "d2937e5e",
117117
"metadata": {},
118118
"outputs": [],
@@ -201,7 +201,7 @@
201201
},
202202
{
203203
"cell_type": "code",
204-
"execution_count": 12,
204+
"execution_count": 22,
205205
"id": "d0634bc8",
206206
"metadata": {},
207207
"outputs": [
@@ -365,7 +365,7 @@
365365
},
366366
{
367367
"cell_type": "code",
368-
"execution_count": 13,
368+
"execution_count": 23,
369369
"id": "ccd7379b",
370370
"metadata": {},
371371
"outputs": [
@@ -378,13 +378,13 @@
378378
"-------------------------------------------------------------------\n",
379379
"sym metric theory observed abs rel%\n",
380380
"-------------------------------------------------------------------\n",
381-
"λ Arrival rate (1/s) 270.000000 269.696111 -0.303889 -0.11\n",
382-
"μ Service rate (1/s) 100.000000 100.016488 0.016488 0.02\n",
383-
"rho Utilization 0.900000 0.898839 -0.001161 -0.13\n",
384-
"L Mean items in sys 10.053549 9.849654 -0.203895 -2.03\n",
385-
"Lq Mean items in queue 7.353549 7.153121 -0.200428 -2.73\n",
386-
"W Mean time in sys (s) 0.037235 0.036521 -0.000714 -1.92\n",
387-
"Wq Mean waiting (s) 0.027235 0.026523 -0.000712 -2.62\n",
381+
"λ Arrival rate (1/s) 270.000000 269.751667 -0.248333 -0.09\n",
382+
"μ Service rate (1/s) 100.000000 100.058789 0.058789 0.06\n",
383+
"rho Utilization 0.900000 0.898517 -0.001483 -0.16\n",
384+
"L Mean items in sys 10.053549 9.865831 -0.187718 -1.87\n",
385+
"Lq Mean items in queue 7.353549 7.170280 -0.183269 -2.49\n",
386+
"W Mean time in sys (s) 0.037235 0.036556 -0.000680 -1.83\n",
387+
"Wq Mean waiting (s) 0.027235 0.026562 -0.000674 -2.47\n",
388388
"===================================================================\n"
389389
]
390390
}

asyncflow_queue_limit/asyncflow_mmc_split.ipynb

Lines changed: 64 additions & 193 deletions
Large diffs are not rendered by default.

src/asyncflow/queue_theory_analysis/mmc.py

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ def evaluate(self, payload: SimulationPayload) -> MMcResults:
465465
# Observed KPIs → MMcResults (coerenti con definizioni sopra)
466466
# ────────────────────────────────────────────────────────────────────
467467

468-
def _observed_kpis(
468+
def _observed_kpis( # noqa: PLR0915
469469
self,
470470
payload: SimulationPayload,
471471
results_analyzer: ResultsAnalyzer,
@@ -534,6 +534,8 @@ def _observed_kpis(
534534
)
535535

536536
else:
537+
# not FCFS → RANDOM
538+
# Wq̂: mean server waiting_time (independent of Lq)
537539
arrays_map = results_analyzer.get_server_event_arrays()
538540
wait_sum = 0.0
539541
wait_count = 0
@@ -543,9 +545,37 @@ def _observed_kpis(
543545
wait_count += len(vals)
544546
wq_hat = (wait_sum / wait_count) if wait_count > 0 else 0.0
545547

546-
l_hat = lambda_hat * w_hat
547-
lq_hat = lambda_hat * wq_hat
548-
rho_hat = (
548+
# L̂: mean L_SYSTEM time-series (fallback to λ̂·Ŵ)
549+
lsys_map = results_analyzer.get_metric_map(SampledMetricName.L_SYSTEM)
550+
aid = payload.arrivals.id
551+
lsys_series = lsys_map.get(aid, [])
552+
l_hat = (
553+
(sum(lsys_series) / len(lsys_series))
554+
if lsys_series else (lambda_hat * w_hat)
555+
)
556+
557+
# Lq̂: sum over servers of mean LQ_SERVER (fallback to λ̂·Wq̂)
558+
lq_map = results_analyzer.get_metric_map(SampledMetricName.LQ_SERVER)
559+
lq_hat = 0.0
560+
have_any = False
561+
for sid in results_analyzer.list_server_ids():
562+
series = lq_map.get(sid, [])
563+
if series:
564+
lq_hat += (sum(series) / len(series))
565+
have_any = True
566+
if not have_any:
567+
lq_hat = lambda_hat * wq_hat
568+
569+
# rho: mean SERVER_UTILIZATION across servers (fallback to λ̂/(c·μ̂))
570+
util_map = (results_analyzer.get_metric_map(
571+
SampledMetricName.SERVER_UTILIZATION)
572+
)
573+
total_busy = 0.0
574+
total_samples = 0
575+
for series in util_map.values():
576+
total_busy += float(sum(series))
577+
total_samples += len(series)
578+
rho_hat = (total_busy / total_samples) if total_samples > 0 else (
549579
lambda_hat / (server_count * mu_hat)
550580
if mu_hat not in (0.0, float("inf")) else 0.0
551581
)

tests/system/test_sys_ev_inj_lb_two_servers.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,6 @@ def _build_payload(*, with_events: bool) -> SimulationPayload:
139139
settings = SimulationSettings(
140140
total_simulation_time=100.0, # >= 5 s
141141
sample_period_s=0.05,
142-
enabled_sample_metrics=[
143-
"ready_queue_len",
144-
"event_loop_io_sleep",
145-
"ram_in_use",
146-
"edge_concurrent_connection",
147-
],
148-
enabled_event_metrics=["rqs_clock"],
149142
)
150143

151144
flow = (

tests/system/test_sys_ev_inj_single_server.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,6 @@ def _build_payload(*, with_spike: bool) -> SimulationPayload:
116116
settings = SimulationSettings(
117117
total_simulation_time=100.0, # >= 5 (schema lower bound)
118118
sample_period_s=0.05,
119-
enabled_sample_metrics=[
120-
"ready_queue_len",
121-
"event_loop_io_sleep",
122-
"ram_in_use",
123-
"edge_concurrent_connection",
124-
],
125-
enabled_event_metrics=["rqs_clock"],
126119
)
127120

128121
flow = (

tests/system/test_sys_lb_two_servers.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,6 @@ def _build_payload() -> SimulationPayload:
130130
settings = SimulationSettings(
131131
total_simulation_time=600,
132132
sample_period_s=0.05,
133-
enabled_sample_metrics=[
134-
"ready_queue_len",
135-
"event_loop_io_sleep",
136-
"ram_in_use",
137-
"edge_concurrent_connection",
138-
],
139-
enabled_event_metrics=["rqs_clock"],
140133
)
141134

142135
flow = (

tests/system/test_sys_single_server.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,6 @@ def _build_payload() -> SimulationPayload:
100100
settings = SimulationSettings(
101101
total_simulation_time=400,
102102
sample_period_s=0.05,
103-
enabled_sample_metrics=[
104-
"ready_queue_len",
105-
"event_loop_io_sleep",
106-
"ram_in_use",
107-
"edge_concurrent_connection",
108-
],
109-
enabled_event_metrics=["rqs_clock"],
110103
)
111104

112105
flow = (

0 commit comments

Comments
 (0)