Skip to content

Repository files navigation

Most-Queue

Queueing theory in Python: exact analytical solvers paired with discrete-event simulation — for 50+ models from M/M/1 to multiserver-jobs, RDR priorities, SRPT scheduling, age of information, vacations and queueing networks.

🇷🇺 Русская версия

Tests PyPI version Python versions License Downloads DOI GitHub commit activity

Most-Queue banner

Why Most-Queue?

  • Analytics and simulation together. Nearly every analytical calculator ships with a paired discrete-event simulator, and the test suite cross-validates them against each other. You get fast exact numbers and a way to check them.
  • Models you won't find elsewhere in open source: size-based scheduling analytics (SRPT, SJF, PSJF, SPJF with ML-style size predictions, FB/LAS), M/G/1 vacation models, negative customers (RCS / disasters), unreliable servers, multi-server phase-type systems solved by the Takahashi–Takami method (including CV < 1 via complex-fit H₂).
  • Moments, not just means: waiting/sojourn time raw moments, state probabilities, utilization — with a uniform set_sources() / set_servers() / run() API across all models.
  • Pure Python + NumPy/SciPy, pip-installable, MIT license.

Installation

pip install most-queue

Requires Python ≥ 3.9. For network visualization you may also need the system graphviz package.

Quick start: theory vs simulation in 20 lines

from most_queue.theory.fifo.mmnr import MMnrCalc
from most_queue.sim.base import QsSim

# Analytical M/M/3 with a finite queue
calc = MMnrCalc(n=3, r=100)
calc.set_sources(l=2.0)
calc.set_servers(mu=1.0)
theory = calc.run()

# The same system, simulated
sim = QsSim(3)
sim.set_sources(2.0, "M")
sim.set_servers(1.0, "M")
experiment = sim.run(100_000)

print(f"Mean waiting time: theory {theory.w[0]:.3f} vs simulation {experiment.w[0]:.3f}")
# Mean waiting time: theory 0.444 vs simulation 0.448

Showcase: who pays for the scheduling discipline?

Computed by the library's own calculators — conditional slowdown E[T(x)]/x by job size for FCFS, PS, FB (blind) and SRPT (size-aware):

Slowdown by job size for FCFS/PS/FB/SRPT

See the executable comparison of 9 disciplines in tutorials/disciplines_comparison.ipynb.

What's inside

Family Models Method
Classic FIFO M/M/c, M/M/c/r, Erlang B/C, M/G/1, GI/M/c, M/D/c, Eₖ/D/c, M/G/∞ exact
Multi-server phase-type M/H₂/c, H₂/M/c, H₂/H₂/c (CV < 1 via complex fit) Takahashi–Takami
Size-based scheduling M/G/1 SRPT, SJF, PSJF, SPJF (with size predictors + graceful-degradation curves), FB/LAS, PS, LCFS-PR exact (Schrage–Miller, Mitzenmacher)
Priorities M/G/1 PR/NP multi-class, M/G/c PR/NP, M/Ph/c PR; RDR M/M/k & M/PH/k multi-class (exact + RDR-A), per-class response variance; M/M/2 with heterogeneous servers (exact non-birth-death CTMC); accumulating priority (Kleinrock/APQ), priority Erlang-A (impatience), MMAP/PH/1 priorities (NP/PR/RS), retrial with a priority class, preemptive repeat exact / RDR / CTMC / invariant approximation
Multiserver-job (MSJ) jobs holding several servers at once — FCFS response time, saturated-system stability/throughput exact CTMC / saturated product-form
Load balancing (mean-field) dispatching over a large pool — power-of-d / JSQ / JIQ / random mean-field fixed point
Polling systems one server touring Q queues with switchover — exhaustive / gated pseudo-conservation law (Boxma–Groenevelt)
Non-stationary Mt/M/c time-varying arrival rate λ(t) — blocking & waiting probability PSA & MOL approximations
Age of Information M/M/1, M/G/1, preemptive-LCFS — average & peak AoI closed-form + simulation
SLA / deadline-violation probability P(W > D) and SLO quantile from raw moments — works on top of any model in this table; LLM-serving TTFT SLO example H2/Gamma tail fit, M/M/1 exact anchor
Vacations & warm-up M/G/1 multiple vacations, N-policy, warm-up/cooling/delay (M/Ph/c) Fuhrmann–Cooper, Takahashi–Takami
Negative customers M/G/1 and M/G/c with RCS or disasters exact / Takahashi–Takami
Reliability M/G/1 and M/M/c with breakdowns & repairs, machine repair problem (spares, R repairmen, 2 heterogeneous repairmen), working breakdowns, disasters with a repair phase, retrial with an unreliable server Avi-Itzhak–Naor / exact CTMC / birth-death
Matrix-analytic (MAP/PH) MAP/PH/1, M/PH/1, PH/PH/1, MAP/M/c, MAP/PH/c — correlated (bursty) arrivals, single- & multi-server; MMPP fitting QBD, logarithmic reduction
Batch Markovian arrivals BMAP/M/1, BMAP/PH/1 — correlated batch traffic level truncation
Retrial & abandonment M/M/1 and M/G/1 retrial (orbit), Erlang-A (M/M/n+M) with staffing exact / Falin–Templeton
GI/G approximations GI/G/1, GI/G/m mean waiting time Kingman, Krämer–Langenbach-Belz, Allen–Cunneen
Batch arrivals & bulk service Mˣ/M/1 batch arrivals; M/M^[a,b]/1 bulk (batch) service — LLM inference batching, exact N/W moments; general (Erlang- or H2-fitted, CV≤1 or CV≥1) batch-service time with auto-dispatch by CV and batch-size-dependent parameters; exact W moments for the Erlang-fitted case exact
Impatience & closed M/M/1+M, Engset exact
Queueing-inventory M/M/1, M/M/c, or c heterogeneous servers (identical, exponential, or per-server Erlang-/H2-fitted service) with stock-consuming service, general (s,S) replenishment (exponential or Erlang-fitted lead time), backordering or lost sales exact QBD
EDF scheduling Earliest-Deadline-First as the actual service discipline (not post-hoc SLA) DES-exact, no closed form (open problem)
Deadline-aware admission control Accept/reject at arrival based on own-deadline feasibility (not reordering), Exp(θ) deadline — LLM-serving SLO exact convergent series (level-crossing functional equation)
Parallel service Fork-Join, Split-Join; exact heavy-tailed (Pareto) max-of-n; heterogeneous branches, series-parallel task DAGs, (n,k)-join over heterogeneous/DAG branches Markovian / order statistics / exact (Beta function)
Networks open (decomposition, exact Jackson, QNA two-moment flows, MAP input), closed (exact MVA / Buzen / Schweitzer), multi-class BCMP, G-networks (Gelenbe, multi-class), tandems with blocking (finite buffers), fork-join stations, time-varying λ(t), priorities, negative customers, routing optimization decomposition / product form / MVA

Every model comes with a plain-language explanation and a diagram in the illustrated model catalog.

Documentation & tutorials

  • 📖 Documentation — concepts, calculation and simulation guides (English; Russian versions available via in-page switchers)
  • 🎓 Jupyter tutorials — counter-intuitive queueing insights for engineers (the utilization trap, why variability dominates delay, multiserver jobs, Age of Information, …)
  • 🗺 Development roadmaps & trends surveys — literature-driven gap analysis behind each epic, and what's next
  • 🧪 Tests — every model validated against simulation; run with pytest -m "not slow"

Applications

Capacity planning for cloud services and data centers · call-center staffing · manufacturing lines · telecom traffic · healthcare resource planning · scheduling research (SRPT/LAS with ML size predictions).

Recent highlights

  • 2026-09 — Realism wave, part 2: Erlang everywhere, batch-size-dependent params, exact moments: queueing-inventory replenishment lead time generalized from Exp(θ) to Erlang-fitted (the phase dimension only applies where an order can be in transit — a first for this phase-type family); the per-server heterogeneous model gained an Erlang-fitted (CV≤1) service sibling to its H2 case, with a real outflow-splitting bug (departure vs. mid-service phase-advance rates) caught via a deliberately non-degenerate regression check; bulk-service batch-service parameters (Erlang and H2) can now depend on batch size (LLM/GPU dynamic-batching realism), and the Erlang-fitted case gained exact raw moments of W (not just the mean), extending EPIC-032's PASTA technique to the phase-augmented CTMC. See the epic registry for the full breakdown (EPIC-040 through EPIC-043).
  • 2026-09 — Realism wave: heterogeneous branches, general service, admission control: fork-join generalized to heterogeneous branches, series-parallel task DAGs and (n,k)-join (exact order-statistics moments, closed-form Pareto); bulk-service batch-service time generalized from exponential to Erlang (CV≤1) and H2 (CV≥1) phase-type fits, with exact N/W moments and an auto-dispatcher picking the family by CV; exact deadline-aware admission control (accept/reject at arrival based on own-deadline feasibility, Exp(θ) deadline — solved via a level-crossing functional equation and truncated power-series moment extraction, after an initial "obvious" shortcut was proven wrong); and queueing-inventory generalized to c heterogeneous servers (state-splitting + stacked-boundary QBD) with, going one step further, per-server H2-fitted (non-exponential) service time — each server can have its own realistic service-time distribution instead of a single shared rate. See the epic registry for the full breakdown (EPIC-030 through EPIC-039).
  • 2026-09 — Priorities, inventory & scheduling wave: M/M/2 priorities with heterogeneous servers (exact non-birth-death CTMC, canonicalized state construction); queueing-inventory generalized to lost-sales, the full (s,S) reorder-point policy (not just (0,S)), and M/M/c multi-server stock-sharing (exact QBD via a stacked boundary superblock, reduces exactly to M/M/1 at c=1); and EDF (Earliest Deadline First) as an actual service discipline rather than a post-hoc SLA metric — deliberately DES-only, since exact finite-state EDF analysis turned out to be a genuinely open problem (four candidate exact reductions were tried and numerically/analytically disproven; see docs/research/edf-scheduling-2026.md).
  • 2026-09 — SLA & exact-extensions wave: a horizontal SLA/deadline-violation probability layer (P(W > D) and SLO quantiles from raw moments, on top of any calculator in the table above — LLM-serving TTFT SLO example); exact heavy-tailed (Pareto) fork-join (closed-form max-of-n via the Beta function, no approximation); machine repair with two heterogeneous repairmen (Krishnamoorthi's non-birth-death CTMC technique); and the first queueing-inventory system (M/M/1 with stock-consuming service, (0,S) replenishment, backordering — an exact QBD, reusing the MAP/PH stack's solver). See the research folder for the literature review behind each.
  • 2026 — Scale & dynamics wave: load balancing in the mean-field limit (power-of-d / JSQ / JIQ — the "power of two choices" behind modern dispatchers); polling systems (one server touring Q queues with switchover, exhaustive/gated, the Boxma–Groenevelt pseudo-conservation law); and non-stationary Mt/M/c with time-varying load (PSA & MOL approximations for surging demand — call-center staffing, autoscaling). Each with a paired simulator and tests. See the trends survey.
  • 2026 (v2.9) — Datacenter & multi-priority wave: RDR for multi-server multi-class preemptive priorities (M/M/k and M/PH/k, exact + RDR-A, per-class response-time variance); the multiserver-job model (jobs holding several servers at once — FCFS response time and saturated-system stability, the first open-source implementation); Age of Information (average & peak AoI); bulk-service queues for LLM inference batching; and graceful-degradation curves for prediction-based scheduling. See the trends survey.
  • 2026 — Matrix-analytic MAP/PH stack: PH distributions and MAPs (most_queue.random.map_ph), a QBD solver with logarithmic reduction, and exact calculators for MAP/PH/1, M/PH/1, PH/PH/1, MAP/M/c, MAP/PH/c, plus BMAP/M/1 and BMAP/PH/1 for batch arrivals and MMPP fitting from data; MAP and PH sources in the simulator. Plus retrial queues (orbit) and Erlang-A abandonment with a staffing helper. See tutorials/map_ph_correlation.ipynb.
  • 2026 — Wave of exact classics: Erlang B/C, M/G/∞, GI/G approximations, M/G/1 vacation models (multiple vacations, N-policy), PS, LCFS-PR, FB/LAS, unreliable server — each with a paired simulator and tests. Illustrated model catalog with generated diagrams.
  • 2026 — Size-based scheduling analytics: SRPT / SJF / PSJF / SPJF with prediction models (reproduces the Mitzenmacher–Shahout 2025 table in tests) + SizeBasedQsSim.
  • 2026 (preprint) — Multi-server queues with negative customers via Takahashi–Takami: preprint & reproduction code.
  • 2025 (paper) — Multi-channel system with warm-up, cooling and cooling delay: Lokhvitsky, Khabarov, Yakovlev, DOI 10.25791/aviakosmos.1.2025.1456.

Contributing

Issues and pull requests are welcome! Open an issue for bugs or model requests. Development conventions: docs/PROJECT.md, definition of done: docs/DOD.md.

Citation

If you use Most-Queue in research, please cite it (see CITATION.cff):

@software{most_queue,
  author  = {Khabarov, Roman},
  title   = {Most-Queue: queueing theory calculations and simulation in Python},
  url     = {https://github.com/xabarov/most-queue},
  doi     = {10.5281/zenodo.21268402},
  license = {MIT}
}

License

MIT © Roman Khabarov

About

Python package for calculation and simulation of queueing systems (QS) and networks.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages