Sie sind auf Seite 1von 17

Recitation 9: Computer Assignment 2: M/M/m/N

Queueing System Simulation


Hung-Bin (Bing) Chang1 and Yu-Yu Lin2
hungbin@seas.ucla.edu1 and skywoods2001@ucla.edu2

Prof. Izhak Rubin (UCLA)

EE 132B

2014 Fall

1/9

Outline

Admin

M/M/1 Queueing System (QS)

M/M/m/N Queueing System (QS)

Sample Code for M/M/1 QS

Prof. Izhak Rubin (UCLA)

EE 132B

2014 Fall

2/9

Admin

Admin

Computer Assignment #2
Submit a WORD or pdf file that contains graphs, results, and (e.g.,
Matlab) code into our CCLE.
Specify the software/language used (e.g., MATLAB).
Deadline: 12/10/14 (Wed.) Midnight

Prof. Izhak Rubin (UCLA)

EE 132B

2014 Fall

3/9

M/M/1 Queueing System (QS)

Illustration: M/M/1 Queueing System (QS)

Arrival process
Message (customer) inter-arrival times are i.i.d. random variables
that are governed by an exponential distribution with parameter .

Service Times
Message (customer) service times are i.i.d. random variables that
follow an exponential distribution with parameter .

Single server (m = 1)
Buffer capacity: unlimited (infinite)
Service policy: FCFS (FIFO)

Prof. Izhak Rubin (UCLA)

EE 132B

2014 Fall

4/9

M/M/1 Queueing System (QS)

M/M/1 QS Process

Queue size area


Service area

3
2
1
ttotal

Figure : M/M/1 QS Process

Prof. Izhak Rubin (UCLA)

EE 132B

2014 Fall

5/9

M/M/1 Queueing System (QS)

M/M/1 QS Process - Performance metrics


System size area = queue size area + service area
Performance metrics include:
Performance Metrics
Description
Mean System Size (E[X ])
System size area/ttotal
Mean Queueing Size (E[Q]) Queue size area/ttotal
Mean Delay Time (E[D])
total delay time/Ntotal
Mean Waiting Time (E[W ])
total wait time/Ntotal
Table : Performance metrics in a queueing system
Number of message (Ntotal ) = total number of messages served
during the simulation run.
Total delay time = cumulative sum of the delays incurred by
messages served by the system during the simulation run
Total wait time = cumulative sum of the waiting times incurred by
messages served by the system during the simulation run
Prof. Izhak Rubin (UCLA)

EE 132B

2014 Fall

6/9

M/M/1 Queueing System (QS)

M/M/1 QS - Summary of Analytical Results

E[X ] =

i = , i 1.
=

<1

P(j) = (1 )j , j 0.

E[Q] = D E[W ] =

D =

Prof. Izhak Rubin (UCLA)

j=0 jP(j) = 1 ,
1
E[D] = 1
D E[X ] = (1) ,

E[W ] = E[D] 1 = (1)


,

i = , i 0.

EE 132B

2
1 .

2014 Fall

7/9

M/M/m/N Queueing System (QS)

M/M/m/N QS - Summary of Analytical Results


(
i =

, 0 i N 1,
0 , i = N.

i = min(i, m), i 1.
f = , =

m .

P(j) = aj P(0), j 0.
P

P(0) =
aj =
j
f

j!

fj

m!mjm
a0 = 1.

N
j=0

aj

E[D] =

1

E[X ]
D .

E[W ] = E[D] 1
P
E[X ] = N
j=0 jP(j),

, 0 < j < m,

E[Q] = D E[W ].

, m j N.
N

PB = P(N) = P(0) m!mf Nm .


D = (1 PB ).
Prof. Izhak Rubin (UCLA)

EE 132B

2014 Fall

8/9

Sample Code for M/M/1 QS

Illustrative discrete event simulation of M/M/1 QS


Global parameters
Definitions and calculation routines of the system states, variables
and their parameters.

Initialize
Setting the initial values of system states and parameters

Main and called routines


Defining the flow of the iterative progress of the simulation program
from start to end (when the termination conditions are met)
At each step, a cited routine is called; when a result is returned by
this routine, the proper next routine, if applicable, is called; or the
simulation is terminated, at which time performance metrics are
updated.

Report
Collect simulation data to compute and present performance
metrics.
Prof. Izhak Rubin (UCLA)

EE 132B

2014 Fall

9/9

M/M/1 Simulation:
Global Parameters

time_next_event(1:2) = 0;

% Events = {arrivals, departures}

% Identifier of arrival event = 1; Identifier of departure event = 2

% Refers to class 1 and 2 event times, which are initially set to 0.


num_events = 2;

% The state evolution of a single node queueing system is described through the iterative computation of
2 types of events (arrival and departure times)

% Number of events = 2 = Arrival and departure events


mean_interarrival = 2;

% Average interarrival time between packet arrivals [sec]

% 1/ = 2 sec (illustrative case)


mean_service_time = 1;

% Average packet service time [sec]

% 1/ = 1 sec (illustrative case)


limit_packets = 1e6; (illustrative case)

% Maximum number of packets that arrive to the system (whether admitted or blocked) which induce,
when met, termination of the simulation run

2013 by Izhak Rubin

Initialization

sim_time = 0.0; % Initializes simulation time


server_status = 0;

% server is initially idle. Recall that status = 0


implies the system to be idle and status =1
indicates the server to be busy.
system_size = 0;

% number of packets in the system (or system


size, denoted as X)
queueing_size = 0;

% number of packets in the queue (wait size,


denoted as Q)
time_last_event = 0;

% the time of the latest recorded event


% Initialize the statistical counters:
num_packets_delay = 0;

% cumulative number of packets that have


experienced delay up to this time
num_packets_wait = 0;

% cumulative number of packets that have


experienced waiting time up to this time
total_of_wait_time = 0;

% cumulative sum of the waiting times


experience by all packets served by the system
up to this time

total_of_delay_time = 0;

% cumulative sum of the delay times experience


by all packets served by the system up to this
time
system_size_area = 0;

% cumulative system size area up to this time


queueing_size_area = 0;

% cumulative queue size area up to this time


service_area = 0;

% cumulative service area up to this time


% Initialize event list. Initially, no packets are present.
% departure (service completion) events are not yet
involved.
time_next_event(1) = sim_time +
exprnd(mean_interarrival);

% time of next arrival event

% Matlab defines exprnd(mean_interarrival) =


exponentially distributed RV with this specified
mean
time_next_event(2) = 1e30;

% time of next departure event; 1e30 denotes


infinite

2013 by Izhak Rubin

main

while total_of_packets-1 < limit_packets

% checks that the max number of served packets is below the specified limit and calls the timing( )
routine.

% The program should also include termination conditions that involve maximum a simulation run time
and queue-size limits to assure timely completion and stable operation.

timing(); % Determines the next event type and updates the current simulation time.

update_time_avg_stats(); % updates_the values of the computed system state / performance statistical


measures.
switch next_event_type % iterative progress of the simulation process as it goes through successive
arrival or departure events.
case 1

arrive();
case 2

depart();
end

end
report(); % report subroutine is called to generate performance exhibits.

2013 by Izhak Rubin

timing()

min_time_next_event = 1.0e+30; % infinity


next_event_type = 0;

% Initial default value


for k = 1:num_events

% class-k event; k =1 designates an arrival event; k =2 designates a departure event

if time_next_event(k) < min_time_next_event

min_time_next_event = time_next_event(k);

next_event_type = k;

end
end
sim_time = min_time_next_event;

2013 by Izhak Rubin

update_time_avg_stats()

time_since_last_event = sim_time - time_last_event;


time_last_event = sim_time;

system_size_area = system_size_area + system_size*time_since_last_event;

% Update area under number in-system function

queueing_size_area = queueing_size_area + queueing_size*time_since_last_event;

% Update area under number in-queue function

service_area = service_area + server_status*time_since_last_event;

% Update area under server-busy indicator function.

2013 by Izhak Rubin

arrive()

time_next_event(1) = sim_time +
exprnd(mean_interarrival);
system_size = system_size + 1;
time_arrival_system(system_size) = sim_time;

% time arrival system (i) = time of arrival of


packet-i

% time arrival system (system_size) = time of


arrival of the last packet to arrive

if server_status == 1

% busy status is 1 and idle status is 0

% Server is busy, so increment number of


packets in queue

queueing_size = queueing_size + 1;

time_arrival_queue(queueing_size) = sim_time;

else % i.e., server_status == 0;

Server is idle, a new packet arrives and is


admitted into service.

% Arriving packet has wait time of zero.

% The following two statements are for


program clarity and they do not affect the
results of the simulation.

wait = 0;

total_of_wait_time = total_of_wait_time + wait;

% Increment the number of waiting packets


and identify the server to be in busy status.

num_packets_wait = num_packets_wait + 1;

server_status = 1;

% server is busy

% Schedule a departure (service completion).

time_next_event(2) = sim_time +
exprnd(mean_service_time);
end

2013 by Izhak Rubin

departure()

system_size = system_size - 1;
delay = sim_time - time_arrival_system(1);

% delay experienced by the departing


packet

% time_arrival_system(1) identifies the time


of arrival of the head-of-the-line (HOL)
packet.
total_of_delay_time = total_of_delay_time + delay;

% Increment the total by adding the delay


incurred by the currently departing packet
num_packets_delay = num_packets_delay + 1;
for k = 1 : system_size

time_arrival_system(k) =
time_arrival_system(k+1);

% pushes up packet arrival times in the


array so that the current HOL packet
arrival time is at entry 1
end
if queueing_size == 0

% The queue becomes empty, the server is


set to idle and we eliminate the next
departure event from consideration.

server_status = 0;

time_next_event(2) = 1.0e+30;

else

% The queue is nonempty, so decrement the


number of packets in queue.
queueing_size = queueing_size - 1;
% Compute the wait of the customer that is
starting service and update the total wait
accumulator.
wait = sim_time - time_arrival_queue(1);
total_of_wait_time = total_of_wait_time + wait;
% Increment the number of waiting packets
and schedule the next departure.
num_packets_wait = num_packets_wait + 1;
time_next_event(2) = sim_time +
exprnd(mean_service_time);
% Move each customer in queue up one place
upwards (FIFO service assumed):
for k = 1:queueing_size

time_arrival(k) = time_arrival(k+1);
end

end

2013 by Izhak Rubin

report()

display(['E[D] = 'num2str(total_of_delay_time/num_packets_delay)]);

% Average delay in the system E[D]


display(['E[X] = 'num2str(system_size_area /sim_time)]);

% Average number in the system E[X]


display(['E[W] = 'num2str(total_of_wait_time/num_packets_wait)]);

% Average delay in the queue E[W]


display(['E[Q] = 'num2str(queueing_size_area /sim_time)]);

% Average number in the queue E[Q]


display(['Server utilization = 'num2str(service_area/sim_time)]);

% Server utilization = fraction of time that the service channel is busy;

% At steady state, for M/M/1 system, it will be equal to = /.

2013 by Izhak Rubin

Das könnte Ihnen auch gefallen