Skip to content

Commit 3cad1c2

Browse files
authored
Queue Theory: MMc (split & FCFS/Erlang-C), independent Observed KPIs, richer sampled metrics, and updated notebooks (#32)
* Logic to handle completed rqs move to arr-gen * Added metrics L system and Lq LB * Calculations theory vs observed indipendent * improved tests and all calculation of th. vs observed indip
1 parent c5a8a52 commit 3cad1c2

32 files changed

+981
-962
lines changed

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: 61 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
},
2121
{
2222
"cell_type": "code",
23-
"execution_count": 96,
23+
"execution_count": 19,
2424
"id": "3e168d4a",
2525
"metadata": {},
2626
"outputs": [],
@@ -45,7 +45,7 @@
4545
},
4646
{
4747
"cell_type": "code",
48-
"execution_count": 97,
48+
"execution_count": 20,
4949
"id": "dd39a8e3",
5050
"metadata": {},
5151
"outputs": [
@@ -112,7 +112,7 @@
112112
},
113113
{
114114
"cell_type": "code",
115-
"execution_count": 98,
115+
"execution_count": 21,
116116
"id": "d2937e5e",
117117
"metadata": {},
118118
"outputs": [],
@@ -168,9 +168,9 @@
168168
" LinkEdge(id=\"lb-srv1\", source=\"lb-1\", target=\"srv-1\", ),\n",
169169
" LinkEdge(id=\"lb-srv2\", source=\"lb-1\", target=\"srv-2\", ),\n",
170170
" LinkEdge(id=\"lb-srv3\", source=\"lb-1\", target=\"srv-3\", ),\n",
171-
" LinkEdge(id=\"srv1-client\", source=\"srv-1\", target=\"client-1\",),\n",
172-
" LinkEdge(id=\"srv2-client\", source=\"srv-2\", target=\"client-1\",),\n",
173-
" LinkEdge(id=\"srv3-client\", source=\"srv-3\", target=\"client-1\",),\n",
171+
" LinkEdge(id=\"srv1-client\", source=\"srv-1\", target=\"rqs-1\",),\n",
172+
" LinkEdge(id=\"srv2-client\", source=\"srv-2\", target=\"rqs-1\",),\n",
173+
" LinkEdge(id=\"srv3-client\", source=\"srv-3\", target=\"rqs-1\",),\n",
174174
" ]\n",
175175
"\n",
176176
" settings = SimulationSettings(\n",
@@ -201,7 +201,7 @@
201201
},
202202
{
203203
"cell_type": "code",
204-
"execution_count": 99,
204+
"execution_count": 22,
205205
"id": "d0634bc8",
206206
"metadata": {},
207207
"outputs": [
@@ -285,47 +285,73 @@
285285
"\n",
286286
"---\n",
287287
"\n",
288-
"## Observed (from simulation)\n",
288+
"## Observed (from simulation, FCFS/Erlang-C)\n",
289289
"\n",
290-
"After processing metrics:\n",
290+
"Under FCFS we derive **each KPI directly** from sampled time series or per-request buckets, **not** by deriving one observed KPI from another. This keeps Little’s law checks as **independent validations**, not definitions.\n",
291291
"\n",
292-
"1. **Arrival rate**:\n",
292+
"1. **Arrival rate**\n",
293293
"\n",
294294
"$$\n",
295-
"\\lambda_{\\text{Observed}} = \\text{mean throughput (client completions)}\n",
295+
"\\lambda_{\\text{obs}}=\\mathrm{mean}(\\text{Throughput RPS})\n",
296296
"$$\n",
297297
"\n",
298-
"2. **Service rate**:\n",
298+
"Mean of the throughput series (client completions per fixed window, typically 1 s).\n",
299+
"\n",
300+
"2. **Service rate**\n",
299301
"\n",
300302
"$$\n",
301-
"\\mu_{\\text{Observed}} = 1 / \\overline{S}, \\quad \\overline{S} = \\text{mean(service\\_time)}\n",
303+
"\\mu_{\\text{obs}}=\\frac{1}{\\overline{S}},\\quad \n",
304+
"\\overline{S}=\\mathrm{mean}(\\texttt{SERVICE\\_TIME})\n",
302305
"$$\n",
303306
"\n",
304-
"3. **End-to-end latency**:\n",
307+
"Computed from per-request server buckets, aggregated across all servers.\n",
308+
"\n",
309+
"3. **End-to-end time**\n",
305310
"\n",
306311
"$$\n",
307-
"W_{\\text{Observed}} = \\text{mean(client latencies)}\n",
312+
"W_{\\text{obs}}=\\mathrm{mean}(\\text{client latencies})\n",
308313
"$$\n",
309314
"\n",
310-
"4. **Waiting time**:\n",
315+
"From the generator’s request clocks (start/finish per request).\n",
316+
"\n",
317+
"4. **Queue waiting time (LB)**\n",
311318
"\n",
312319
"$$\n",
313-
"W_{q,\\text{Observed}} = \\text{mean(waiting\\_time)} \n",
320+
"W_{q,\\text{obs}}=\\mathrm{mean}(\\text{LB waiting times})\n",
314321
"$$\n",
315322
"\n",
316-
"5. **Little’s law check**:\n",
323+
"Mean of the **load balancer FCFS** waiting time recorded per request (not inferred from queue length).\n",
324+
"\n",
325+
"5. **Mean number in system**\n",
317326
"\n",
318327
"$$\n",
319-
"L_{\\text{Observed}} = \\lambda_{\\text{Observed}} W_{\\text{Observed}}, \\qquad\n",
320-
"L_{q,\\text{Observed}} = \\lambda_{\\text{Observed}} W_{q,\\text{Observed}}\n",
328+
"L_{\\text{obs}}=\\mathrm{mean}(\\texttt{L\\_SYSTEM})\n",
321329
"$$\n",
322330
"\n",
323-
"6. **Utilization**:\n",
331+
"Time average of the sampled series of **concurrent requests in the system** (sampled every $\\Delta t$).\n",
332+
"*Fallback if the series is unavailable in tests:* $L_{\\text{obs}}=\\lambda_{\\text{obs}} W_{\\text{obs}}$.\n",
333+
"\n",
334+
"6. **Mean number in queue (LB)**\n",
324335
"\n",
325336
"$$\n",
326-
"\\rho_{\\text{Observed}} = \\lambda_{\\text{Observed}}/(c\\,\\mu_{\\text{Observed}})\n",
337+
"L_{q,\\text{obs}}=\\mathrm{mean}(\\texttt{LQ\\_LB})\n",
327338
"$$\n",
328339
"\n",
340+
"Time average of the **LB queue length** series.\n",
341+
"*Fallback:* $L_{q,\\text{obs}}=\\lambda_{\\text{obs}} W_{q,\\text{obs}}$.\n",
342+
"\n",
343+
"7. **Global utilization**\n",
344+
"\n",
345+
"$$\n",
346+
"\\rho_{\\text{obs}}=\\mathrm{mean}(\\texttt{SERVER\\_UTILIZATION})\n",
347+
"$$\n",
348+
"\n",
349+
"Each server samples a 0/1 “busy” indicator; $\\rho_{\\text{obs}}$ is the time average (with 1 core/server it matches the busy fraction).\n",
350+
"*Fallback:* $\\rho_{\\text{obs}}=\\lambda_{\\text{obs}}/(c\\,\\mu_{\\text{obs}})$.\n",
351+
"\n",
352+
"> Because each quantity comes from its own primary measurement (series or buckets), cross-relations like $L=\\lambda W$ and $L_q=\\lambda W_q$ are genuine **consistency checks**, not tautologies.\n",
353+
"\n",
354+
"\n",
329355
"---\n",
330356
"\n",
331357
"## Comparison\n",
@@ -339,27 +365,27 @@
339365
},
340366
{
341367
"cell_type": "code",
342-
"execution_count": 100,
368+
"execution_count": 23,
343369
"id": "ccd7379b",
344370
"metadata": {},
345371
"outputs": [
346372
{
347373
"name": "stdout",
348374
"output_type": "stream",
349375
"text": [
350-
"=================================================================\n",
376+
"===================================================================\n",
351377
"MMc (FCFS/Erlang-C) — Theory vs Observed\n",
352-
"-----------------------------------------------------------------\n",
353-
"sym metric theory observed abs rel%\n",
354-
"-----------------------------------------------------------------\n",
355-
"λ Arrival rate (1/s) 270.000000 270.258333 0.258333 0.10\n",
356-
"μ Service rate (1/s) 100.000000 100.036707 0.036707 0.04\n",
357-
"rho Utilization 0.900000 0.900531 0.000531 0.06\n",
358-
"L Mean items in sys 10.053549 10.073544 0.019994 0.20\n",
359-
"Lq Mean items in queue 7.353549 7.371934 0.018385 0.25\n",
360-
"W Mean time in sys (s) 0.037235 0.037274 0.000038 0.10\n",
361-
"Wq Mean waiting (s) 0.027235 0.027277 0.000042 0.15\n",
362-
"=================================================================\n"
378+
"-------------------------------------------------------------------\n",
379+
"sym metric theory observed abs rel%\n",
380+
"-------------------------------------------------------------------\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",
388+
"===================================================================\n"
363389
]
364390
}
365391
],

0 commit comments

Comments
 (0)