4 - I - Simulation of Queue
4 - I - Simulation of Queue
-4 (A)
AIM:
Write a program for Simulation of M/M/1 and M/M/1/N queues Network Protocols.
SOFTWARE REQUIRED:
MATLAB
THEORY:
In queueing theory, a discipline within the mathematical theory of probability, an M/M/1 queue
represents the queue length in a system having a single server, where arrivals are determined by
a Poisson process and job service times have an exponential distribution. The model name is
written in Kendall's notation.
An M/M/1 queue is a stochastic process whose state space is the set {0,1,2,3,...} where the
value corresponds to the number of customers in the system, including any currently in service.
Arrivals occur at rate λ according to a Poisson process and move the process from state i to
i+1.
Service times have an exponential distribution with rate parameter μ in the M/M/1 queue,
where 1/μ is the mean service time.
A single server serves customers one at a time from the front of the queue, according to a
first-come, first-served discipline. When the service is complete the customer leaves the
queue and the number of customers in the system reduces by one.
The buffer is of infinite size, so there is no limit on the number of customers it can contain.
In fig 4.1 l represent the birth (Creation) of new process and m represent the death
(Completion) of old processes.
%results output
util(j+1) = time_in_server/sim_time;
avg_num_in_queue(j+1) = time_in_queue/sim_time;
avg_delay(j+1) = total_delays/num_pack_insys;
P(j+1) = service_mean_time./arrival_mean_time(j+1);
end
%----------------------graphs--------------------------------
figure('name','mean number of clients in system diagram(simulated)');
plot(P,avg_num_in_queue,'r');
xlabel('P');
ylabel('mean number of clients');
axis([0 0.92 0 15]);
Method 2:
M/M/1 Queuing System: This example shows how to model a single-queue single-server
system with a single trafficsource and an infinite storage capacity. In the notation, the M stands
for Markovian; M/M/1means that the system has a Poisson arrival process, an exponential
service time distribution,and one server. Queuing theory provides exact theoretical results for
some performancemeasures of an M/M/1 queuing system and this model makes it easy to
compare empiricalresults with the corresponding theoretical results.
Structure
The model includes the components listed below:
Entity Generator block: Models a Poisson arrival process by generating entities(also known as
in queuing theory).
Simulink Function exponentialArrivalTime(): Returns data representing theinterarrival times
for the generated entities. The interarrival time of a Poisson arrivalprocess is an exponential
random variable.
Entity Queue block: Stores entities that have yet to be served in FIFO order
Entity Server block: Models a server whose service time has an exponentialdistribution.
Fig. 2: Simulink representation of M/M/1 Queuing model
Fig. 3: Mean number of clients versus ratio of service time and arrival time
Fig. 4: Mean delay versus ratio of service time and arrival time
M/M/1/N Queue:
In this queuing model, the arrivals occur one by one in accordance to Poisson process with
parameter (1+𝜂), where ‘𝜂’ represents the percentage change in number of customers calculated
from past or observed data. For instance, if in past an organization offered discounts and the
percentage change in number of customers was observed + 50% or 1 20% then 𝜂 =0.5 or 𝜂
=1.2respectively.
%%
gapt = exprnd(lambda,1,nv);
st = exprnd(mu,1,nv);
st = [st; exprnd(mu,1,nv)];
st = [st; exprnd(mu,1,nv)];
%%
%gapt = zeros(1,nv) + 10;
%st = zeros(3,nv) + 1;
%%
%init the index of three service
at(1) = 0;
fori =2 :nv
at(i) = at(i-1) + gapt(i-1);
end
%%
fori = 2 : k
ct(i) = at(i);
lt(i) = ct(i) + st(i,pointer(i));
pointer(i) = pointer(i) + 1;
index(i) = i;
end
%%
fori = (k+1):nv
if at(i) >= v
ct(i) = at(i);
else
prev = index(pos);
ct(i) = lt(prev);
end
%%
%legnth of the queue
lenat = zeros(nv,2);
lenlt = zeros(nv,2);
fori = 1:nv
lenat(i,1) = at(1,i);
lenat(i,2) = 1;
lenlt(i,1) = lt(1,i);
lenlt(i,2) = -1;
end
%%
len = [lenat; lenlt];
len = sortrows(len,1);
%%
leng = zeros(1,size(len,1));
fori = 2:size(len,1)
iflen(i,2) > 0
leng(1,i) = leng(1,i-1) + 1;
else
ifleng(1,i-1) > 0
leng(1,i) = leng(1,i-1)-1 ;
else
leng(1,i) = 0;
end
end
end
figure
hold on
subplot(2,1,1)
x = 1:size(len,1);
plot(x, leng);
title('queue length vs time');
xlabel('Time(ms)');
ylabel('Queue Length');
meanlen(x) = mean(leng);
subplot(2,1,2)
plot(x, meanlen)
title('Mean queue length');
xlabel('Time(ms)');
ylabel('Mean Queue Length');
end
Fig. 9: Queue Length v/s time graph for M/M/1/N queuing model
CONCLUSION:
M/M/1 queuing theory is simulated in MATLAB environment. This experiment is done using
two methods (i) Matlab code (ii) Simulink representation. The outcome of this experiment is to
calculate the mean delay, mean number of clients and utilization of processor, when the
processes is continuously arriving and execution. This calculation is useful to the finding the
number of severs required to execute the processes without delay.
M/M/1/N queuing model is simulated in Matlab environment. In this model one server is used
for execution of process. The mean Queue length is higher than the other Queuing model.
DISCUSSION:
Q1. How is queuing delay calculated?
Q2. What is utilization factor in Queuing theory?
Q3. What is queuing model in simulation?
Q4. What is steady state in Queuing theory?