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 more general 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 a 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 queuing 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

Theoretical Background

The M/M/1 system consists of an infinite-capacity queue and a single 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 model.
 
M/M/1 queue

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.

Since the TQueue class has the CreateDefault constructor, the Queue block instance can be created with default values, and the items of the InitialValues parameter do not need to be explicitly specified.

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


Model Parameters

The following variables and constants will be used for the Initial Values of the blocks.
  • TotalEntities — the total number of entities to be simulated during the model run.
  • InterarrivalTime — the mean time between entity arrivals.
  • ServiceTime — the mean service time.
  • ExpTime — a pointer to a function that returns exponentially distributed random values.

Model Behavior

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

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

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

Srv := TServer.Create([ExpTime, ServiceTime]);                           //  Creating 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                                    //  Model parameters.
  TotalEntities,                 
  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([TotalEntities, ExpTime, InterarrivalTime]);
  Que := TQueue.CreateDefault;                 
  Srv := TServer.Create([ExpTime, ServiceTime]);
  
  Gen.Connect(Que);
  Que.Connect(Srv);

  Run(Gen);                            //  Launching start block.

                                       //  Results.
                                       
  Que.ShowStats;                       //  Probability of waiting,
                                       //  mean waiting time, mean queue length                     
end; 

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

Model Validation

To validate the M/M/1 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/c with a limited number of servers, which is a bit more realistic
  • the model of an M/M/∞ with an infinite number of servers