Browser width
is too narrow.

Rotate the screen
or increase
the width.
OpenSIMPLY Free open source simulation software
▲

M/M/1 Queue Simulation Model

This system is a classic example of queuing theory and is a complicated case of M/M/1/1.

Queue

The concept of a queue includes the following parameters: capacity, timeout, and discipline.

The queue capacity is the maximum number of entities that queue can simultaneously accommodate.

The queue timeout is the maximum amount of time an entity can wait in a queue.
Schematic representation of a queue in queueing theory

Queue Discipline

The queue discipline determines how entities arriving at the queue input will be ranked when the queue is non-empty.

Assume the queue output is connected to a block that can accept entities if it is idle, and cannot accept entities if it is busy. For example, such a block could be a server.

If the queue is empty but the block (server) is busy, the entity arriving at the queue input becomes first in the queue. The same happens if the queue is empty but the queue output is not connected to any block.

If the queue is empty and the block is idle, an entity arriving at the queue input is immediately passed to the queue output.

If the queue is not empty, the entity arriving at the queue input is placed in the queue according to the queue discipline.

If the block (server) changes its status from busy to idle, it requests the queue to pass the entity, and if the queue is not empty, the entity first in the queue is passed to the block.
Queue discipline

FIFO Queue Discipline

FIFO stands for "First-In, First-Out".

This means that the entity first arriving at the queue input is the first to be retrieved from the queue output (for example, to be served).

In an M/M/1 queue, when the server becomes idle, it signals its availability. If the queue is not empty, an entity is selected according to the queue discipline and passed to the server.
FIFO queue discipline

M/M/1 Queue: Theoretical Background

The system consists of a queue and a server.

Entities arrive at a queue according to a Poisson process and are then passed to the server. Service time is exponentially distributed.

The queue capacity and timeout for the M/M/1 queue are assumed to be infinite.

The queue discipline in this system is assumed to be FIFO.

Formally, the full notation should be M/M/1/∞/∞/FIFO.

The characteristics under study are the probability of waiting, mean waiting time and mean queue length.

Watch the learning video about the M/M/1 queue.
 
M/M/1 queue

M/M/1 Model in OpenSIMPLY

This example is only a bit more complicated than the M/M/1/1 example.

In addition to the Generator block to simulate arriving entities and the Server block to simulate entity service, the model of an M/M/1 queue requires the Queue block to simulate queue discipline.

In Delphi and Free Pascal, these blocks are represented by the TGenerator, TServer and TQueue classes, respectively.

Download executable models of queuing theory and call centers.
 
OpenSIMPLY block model of the M/M/1 queue

Model Creation

The variables Gen, Que and Srv will be used for instances of the classes TGenerator, TQueue and TServer, respectively.

The Queue block has the following defaults for initial values:
  • InfiniteCapacity for the Capacity item
  • InfiniteTimeout for the Timeout item
  • FIFO for the Discipline item


So, when creating the Queue block with the defaults, it is not necessary to explicitly specify the initial values.

Model Parameters

The following variables and functions will be used for the initial values of the blocks.
  • Capacity: to specify the total number of entities for simulation (Generator)
  • InterarrivalTime: to specify the mean value between entities arrivals (Generator)
  • ServiceTime: to specify the mean value of service time (Server)
  • ExpTime: a block function that returns exponentially distributed random values

Model Behavior

The code below defines the behavior of the M/M/1 queue as an OpenSIMPLY model.

Gen := TGenerator.Create([Capacity, ExpTime, InterarrivalTime]);    //  Creating a Generator.

Que := TQueue.CreateDefault;                                        //  Creating a Queue with default initial values. 

Srv := TServer.Create([ExpTime, ServiceTime]);                      //  Creating a Server.

Gen.Connect(Que);                                                   //  Connecting Generator to Queue.

Que.Connect(Srv);                                                   //  Connecting Queue to Server.


To compile a model, the code above should be placed in a standard wrapper of a model as in the M/M/1 queue example.
 

Complete Program Code with Input Data and Results

program MM1;
{$apptype xxx }  // xxx "GUI" or "Console" 
{$S-}
uses
  SimBase,
  SimBlocks,
  SimStdGUI;
  
type
  TMyModel = class(TModel)     //  Model declaration.  
    procedure Body; override;
  end;

var 
  Capacity,                    //  Model parameters.  
  NumberOfServers: Integer;
  InterarrivalTime,
  ServiceTime: Double;

procedure TMyModel.Body;       //  Model behavior.
var                            
  Gen: TGenerator;             //  Blocks declaration. 
  Que: TQueue;  
  Srv: TServer; 
begin                          //  Model behavior.

  Gen := TGenerator.Create([Capacity, ExpTime, InterarrivalTime]);
  Que := TQueue.CreateDefault;                 
  Srv := TServer.Create([ExpTime, ServiceTime]);
  Gen.Connect(Que);
  Que.Connect(Srv);

  Run(Gen);                    //  Launching the start block.

  Que.ShowStat;                //  Results.
end; 

begin
  Capacity := 3000;            //  Initial values of the model.
  InterarrivalTime := 1;
  ServiceTime := 1.3;
  
  Simulate(TMyModel);          //  Starting a model.
end.

Model Validation

To validate the M/M/1 queue model, verify its results against the exact formula. Thus, the probability of waiting, mean waiting time and mean queue length can be obtained using the Erlang C formula.

See also the model of an M/M/∞ queue with an infinite number of servers.