Skip to content

xabarov/most-queue

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 exact / RDR / 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
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 with breakdowns & repairs Avi-Itzhak–Naor
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
Impatience & closed M/M/1+M, Engset exact
Parallel service Fork-Join, Split-Join Markovian / order statistics
Networks open (decomposition, exact Jackson, QNA two-moment flows), closed (exact MVA / Buzen / Schweitzer), multi-class BCMP, G-networks (Gelenbe), 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 survey — what's next (queueing-inventory, networks with blocking, fork-join extensions)
  • 🧪 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

  • 2026Scale & 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.
  • 2026Matrix-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

License

Stars

1 star

Watchers

1 watching

Forks

Packages

 
 
 

Contributors

Languages