This repository implements a simulation of an M/M/∞ queueing model, a foundational model in queueing theory used to study systems with unlimited service capacity.
The M/M/∞ model is defined by:
- M (Markovian Inter-Arrival Times): The time between successive arrivals follows an exponential distribution.
- M (Markovian Service Times): The service times are exponentially distributed.
- ∞ (Infinite Servers): Every arriving entity is immediately served without delay, as there are unlimited servers available.
The model is commonly used to simulate systems where resources are abundant compared to demand, such as cloud computing or large-scale server farms.
The simulation revolves around two types of events:
- Arrival Event: A new call enters the system. It is immediately assigned to a server. Each arrival event generates the next arrival time (
next_arrival_time
) by sampling from the exponential inter-arrival time distribution. - Departure Event: A call completes its service and leaves the system.
Each event updates the system state, including the current number of active calls (num_calls
) and the time (current_time
).
At any point, the simulation determines which event (arrival or departure) occurs next:
- Arrival Time: Calculated as the current time plus a random inter-arrival time (
exprnd(1 / lambda)
). This is updated every time an arrival event occurs. - Departure Time: The earliest scheduled departure time from the scheduled departures (
scheduled_departure_times
) list.
The simulation compares the next arrival time (next_arrival_time
) and the earliest departure time (min(scheduled_departure_times)
) to decide:
- If the arrival time is sooner, an arrival event occurs:
- Updates the number of active calls (
num_calls
). - Schedules a departure for the arriving call.
- Determines the next arrival time by sampling a new inter-arrival time.
- Updates the number of active calls (
- Otherwise, a departure event occurs:
- Reduces the number of active calls (
num_calls
). - Removes the completed departure from the schedule.
- Reduces the number of active calls (
- Arrival Rate (λ): The average number of arrivals per unit time.
- Service Rate (μ): The average number of services completed per unit time.
- Total Time: The duration of the simulation.
lambda = 10 % arrivals / unit time
mu = 2 % services / unit time
total_time = 100 % units
- Start the simulation clock at zero (
current_time = 0
). - Generate the first arrival event and initialize the system state:
- Sample the time until the first arrival from the exponential distribution.
- Log the initial system state (time and number of calls).
- Iteratively process events by determining whether the next event is an arrival or departure:
- Compare the time of the next arrival with the earliest departure.
- Update the system state based on the type of event:
- Arrival Event:
- Increase the number of active calls.
- Schedule a departure for the arriving call by sampling its service time.
- Generate the next arrival time by sampling a new inter-arrival time.
- Departure Event:
- Decrease the number of active calls.
- Remove the completed departure from the schedule.
- Arrival Event:
- Log the system state after each event (time and number of calls).
- Continue until simulation time is exceeded (
current_time >= total_time
).
This plot tracks the evolution of the number of active calls during the simulation. The orange line represents the number of active calls at each logged event. The red dashed line shows the time-weighted average number of calls, computed across the simulation duration.
This histogram displays the probability distribution of the number of active calls during the simulation. The distribution reflects the system's ability to handle all arriving calls due to infinite servers.
This plot provides two separate distributions:
- Inter-Arrival Times: The time intervals between consecutive arrivals.
- Service Times: The duration of service for each call.
Both distributions align with the expected exponential behavior, given the model assumptions.
- Clone the repository:
git clone https://github.com/mantvydasdeltuva/m_m_infinity-queue-simulation.git cd m_m_infinity-queue-simulation
- Open the MATLAB script in the MATLAB editor.
- Modify the parameters (
lambda
,mu
,total_time
) if needed. - Run the script to simulate and generate the visualizations.
- MATLAB (Recommended version: R2023a or later).
- Statistics and Machine Learning Toolbox
This project is licensed under the MIT License. See the LICENSE file for more details.
Contributions and suggestions are welcome. Please feel free to submit an issue or a pull request for improvements.