Operations 9 min read

Mastering Queueing Theory: Models, Little’s Law, Erlang & Python Simulation

This article introduces core queueing theory concepts such as Kendall notation, M/M/1 and M/M/c models, Little’s Law, Erlang formulas, and demonstrates their practical application through a detailed Python simulation of a bank service system.

Model Perspective
Model Perspective
Model Perspective
Mastering Queueing Theory: Models, Little’s Law, Erlang & Python Simulation

Queueing theory, at the intersection of operations research and probability, is a fundamental tool for analyzing and optimizing systems such as banks, supermarkets, hospitals, computer networks, and production lines. Understanding its basic principles helps explain these phenomena and provides scientific guidance for improving service quality and efficiency.

Key Concepts

Kendall Notation

The Kendall notation describes a queueing system with three components:

Arrival process distribution.

Service time distribution.

Number of service facilities (e.g., M/M/1 denotes Poisson arrivals, exponential service times, and a single server).

Queue Models

The basic M/M/1 model features:

Arrival process: Poisson with rate λ.

Service time: Exponential with rate μ.

Number of servers: 1.

Performance metrics: utilization, average queue length, average waiting time, etc.

M/M/c Model

The M/M/c model extends M/M/1 to c parallel service facilities. Its performance metrics include utilization, average queue length, average waiting time, and the probability that the system is idle.

Little’s Law

Little’s Law relates the average number of customers in the system (L), the average waiting time (W), and the arrival rate (λ) by L = λ·W. It holds for a wide variety of queueing systems, regardless of arrival or service time distributions.

Erlang Models

Erlang models are used for telephone exchange and other service systems:

Erlang B: Calculates the blocking probability when all servers are busy.

Erlang C: Calculates the waiting probability when a call must wait for service.

Case Study: Bank Queue

In a bank, customers arrive for deposits, withdrawals, loans, etc. Key factors include arrival rate (varying by time of day), service time (depending on transaction type), number of service windows, and service policies (whether each window handles all services or specialized ones).

Using queueing theory, we model the bank with an M/M/c system:

Arrival process (M): Poisson arrivals with rate λ.

Service time (M): Exponential service with rate μ.

Number of service facilities (c): Number of teller windows.

Performance metrics:

System utilization: ρ = λ / (c·μ).

Probability of an idle system.

Average queue length.

Average waiting time.

The following Python code simulates the bank queue and computes the average waiting time.

<code>import numpy as

# Parameters
lambda_rate = 10  # customer arrival rate per hour
mu_rate = 5       # service rate per window per hour
c = 3             # number of service windows
total_hours = 8   # total simulation time (hours)

# Initialization
current_time = 0
queue = []               # stores arrival times of customers
service_times = [float('inf')] * c  # completion time for each window
waiting_times = []

while current_time < total_hours:
    arrival_time = current_time + np.random.exponential(1 / lambda_rate)
    next_service_time = min(service_times)
    next_event_time = min(arrival_time, next_service_time)

    if arrival_time <= next_service_time:
        current_time = arrival_time
        queue.append(current_time)
        if len(queue) <= c:
            service_index = len(queue) - 1
            service_times[service_index] = current_time + np.random.exponential(1 / mu_rate)
    else:
        current_time = next_service_time
        finished_service_index = service_times.index(next_service_time)
        arrival_time_of_served_customer = queue.pop(0)
        waiting_time = current_time - arrival_time_of_served_customer
        if len(queue) >= c:
            service_times[finished_service_index] = current_time + np.random.exponential(1 / mu_rate)
        else:
            service_times[finished_service_index] = float('inf')
        waiting_times.append(waiting_time)

average_waiting_time = np.mean(waiting_times)
print("Average waiting time (hours):", average_waiting_time)
</code>

Code Explanation:

Parameter settings: λ (arrival rate), μ (service rate), c (number of windows), total simulation time.

Initialization: current simulation time, queue for arrival times, list of service completion times.

Simulation loop: generate next arrival and next service completion times, advance to the earlier event, update queue and service states accordingly.

Result calculation: compute the mean waiting time of all served customers.

The diagram below illustrates the simulation process.

Conclusion

Queueing theory is a rich mathematical discipline and a practical analysis tool applicable to many real‑world scenarios. Precise models and theorems enable quantification of key performance indicators such as waiting time, queue length, and system utilization, offering decision‑makers actionable insights to improve service quality, customer satisfaction, and operational efficiency.

operations researchperformance analysisLittle's Lawqueueing theoryPython simulation
Model Perspective
Written by

Model Perspective

Insights, knowledge, and enjoyment from a mathematical modeling researcher and educator. Hosted by Haihua Wang, a modeling instructor and author of "Clever Use of Chat for Mathematical Modeling", "Modeling: The Mathematics of Thinking", "Mathematical Modeling Practice: A Hands‑On Guide to Competitions", and co‑author of "Mathematical Modeling: Teaching Design and Cases".

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.