Discrete Event Simulation
Discrete Event Simulation
Discrete Event Simulation
Time Slicing: If we plot the system’s behavior against time the graph will be smooth, i.e system is
chaning continiously.
Example: Weather. Think about change of Temperature with time. In picture, y is the system
variable.
Discrete event simulation can be used to understand nature of various kind of systems and be able to
answer different kind of questions about the system. Here are a few example.
2
1. A system with wolves and sheep:
The number of wolves changes at a constant birthrate and death rate is inversely proportional to
the number of sheep. The number of sheep changes with a constant birthrate and a death rate
directly proportional to the number of wolves.
Naturalist asks: Do the number of sheep and wolves stabilize in the long run, if yes, to what
values. Or do they vary cyclically, if yes with what period and phrase.
Computer Scientists asks: Is there a server which is always busy while the other servers are
mostly idle?
Customers arrive with certain service requirements. Customers arrive with service requirements,
get served in some defined order (FIFO, LIFO, Service time etc.) and leaves when their service is
complete. A customer has to wait when the server is busy.
Management asks: The average waiting time for customers, average number of customers in
the system, the fraction of time the server is busy, etc.
3. Simulation Executive: Responsible for controlling the time advance and executing discrete events.
4. Random Number Generator: Helps to simulate different data conming into the simulation model.
Random data can be reproduced in different simulation runs.
5. Results and Statistics: For validating the model and for providing performance measures.
3
2.1.3 Discrete Event Simulation Paradigms
1. Event Oriented Paradigm: This approach describes an instantaneous describes an instantaneous
change, usually a stop event and a start event.
3. Process: This approach groups activities to describe the life cycle of an entity.
Example: A machine.
Example 1:
Building a simulation of gas station with a single pump served by a single service man. Assumption:
Arrival of cars as well as well as their service times are random.
First ldentify the:
1. States: Number of cars waiting for service and number of cars served at any moment
3. Entities: Cars
5. Distributions: Assuming exponential distributions for both the inter-arrival time and service time.
4
• At event of entity arrival: create next arrival.
• If the server is free, send entity for start of service, otherwise it joins the queue.
• If any entities waiting in queue: remove on entity from the queue: send it for start of service.
Initialization:
Implementation:
Using simPy.
Example 2:
Interaction of the principle and interest associated with a savings account.
System thinking diagram:
The diagram indicates that Deposits increase with the Principal and Withdraws decrease the Principal.
Also, the principal interacts with the Interest Rate on some periodic basis to create Interest. The interest
then serves to increase the Principal.
Assumptions:
Turning this into a 10-year simulation: The graph between principal and time(year) of running the
model for 10 years.
The interest is computed and added to the Principale at the end of each year. So, the discrete
nature of the simulation is very evident.
5
2.1.4 SimPy Overview
Here are the major SimPy classes
• Process: simulates an entity which evolves in time, e.g. one customer who needs to be served
by an ATM machine; we will refer to it as a thread, even though it is not a formal Python thread
• yield hold: used to indicate the passage of a certain amount of time within a thread; yield is a
Python operator whose first operand is a function to be called, in this case a code for a function
that performs the hold operation in the SimPy library
• yield request: used to cause a thread to join a queue for a given resource (and start using it
immediately if no other jobs are waiting for the resource)
• yield release: used to indicate that the thread is done using the given resource, thus enabling
the next thread in the queue, if any, to use the resource
• yield passivate: used to have a thread wait until “awakened" by some other thread
Examples:
A processor provides service to processes;
A transmission line provides a transmission service to packets or frames of data;
An I/O device provides a read or write service for I/O requests.
6
Types of Queue:
1. Single Server Queue
2. Multi Server Queue
Queuing Parameter:
From the picture we can illustrate some important parameters associated with a queuing model:
7
If we assume, that the capacity of the queue is infinite, then no items are ever lost from the system;
they are just delayed until they can be served. Under these circumstances, the departure rate equals the
arrival rate.
As the arrival rate (the rate of traffic passing through the system) increases, the utilization increases
and so does the congestion. The queue becomes longer increasing the waiting time.
When utilization, ρ = 1 the server becomes saturated working 100% of the time.
The theoretical maximum input rate that can be handled by the system is
1
λmax =
Ts
Near system saturation the queue becomes large, growing without bound.
Practical Considerations, such as buffer sizes, usually limit the input rate for a single server to
70 − 90% of the theoretical maximum.
2.2.1 Assumptions:
Given as follows—
Item Population: Typically infinite population is assumed. This means that the arrival rate is
not altered by the loss if population. If the population is finite, then the number of items reduces the
available population for arrival currently in the system.
Queue Size: Infinite Queue size is assumed. Thus the waiting line can grow without bound. With
a finite queue, it is possible for items to be lost from the system. In practice, any queue is finite.
Dispatching discipline: When the server becomes free, and if there is more than one item waiting,
a decision must be made as yo which item is to dispatch next.
3. Service time.
Example: A packet switching node may choose to dispatch packets on the basis of shortest first
(to generate the most outgoing packets) or longest first (to minimize processing time relative to
transmission time)
8
2.2.2 Exception in Parameters for the Case of Multi server queue:
1. If an item arrives and at least one server is available, then the item is immediately dispatched to that
server.
2. Assumption: All servers are identical; thus if more than one server is available, it makes no difference
which server is chosen for the item If all servers are busy, a queue begins to form. As soon as a server
becomes free, an item is dispatched from the queue using the dispatching discipline force.
The utilization of the entire system, Nρ is often referred to as the traffic intensity, u
2.2.3 Variability
• Definition: Variability is anything that causes the system to depart from regular, predictable
behavior.
• Sources of Variability:
9
• Probability distribution of the arrival rate and service time.
1. The arrival rate obeys the Poisson distribution, which is equivalent to saying that the inter arrival
times are exponential. Meaning that the arrivals occur randomly and independently of one another.
Notation:
To summarize the principal assumptions about the queueing model, a notation X/Y/Z is developed.
Distributions:
The most commonly used queuing model is M/M/1, a single server queueing model with Poisson ar-
rivals and exponential service times.
10
2.3 Single Server Queue
Considering a single server queue following the M/G/1 Model.
• Mean waiting time, Tw (including items with waiting time = 0 and items that have to wait),
To simplify the computation of the outputs easier, the following quantities are introduced.
σ
• Coefficient of Variation, CS : CS = TTss is the ratio of the standard deviation to the mean
service time. This quantity gives a normalized measure of variability.
11
Table 3: Formulas for Single-Server Queues
1. Poisson arrival rate.
2. Dispatching discipline does not give preference to items based on service times.
3. Formulas for standard deviation assume first-in, first-out dispatching.
4. No items are discarded from the queue.
a. General Service Times(M/G/1) Exponential Service Times(M/M/1) Constant Service Times (M/D/1)
[ ( ) ]
1 σTS 2 ρ ρ2 ρ2
A= 1+ r= meow w = r= +ρ
2 TS (1 − ρ) (1 − ρ) 2(1 − ρ)
2
ρ A Ts (2 − ρ) ρTS ρ2
r =ρ+ Tr = meowTw = w=
(1 − ρ) (1√− ρ) (1 − ρ) 2(1 − ρ)
ρ2 A ρ Ts TS (2 − ρ)
w= σr = meow σTr = Tr =
(1 − ρ) (1 − ρ) (1 − ρ) 2(1 − ρ)
ρTS A ρTS
Tr = TS + Pr[R = N ] = (1 − ρ)ρN Tw =
1−ρ √ 2(1 − ρ)
ρTs A ∑N 1 3ρ2 5ρ3 ρ4
Tw = Pr[R <= N ] = i=0 (1 − ρ)ρi σr = ρ− + −
(1 − ρ) 1−ρ √2 6 12
Pr[Ts <= T ] = 1 − e−(1−ρ)t/Ts ρ
σTr = 1−ρ 3 − 12
TS ρ2
( )
100
mTr (y) = Tr × ln
(100 − y )
Tw 100ρ
mTr (y) = × ln
ρ 100 − y
• Case 1: When the standard deviation is equal to the mean, the service time distribution is
exponential and the model is M/M/1.
• Case 2: When standard deviation is equal to zero. Then the service time distribution becomes
fixed and the model is M/D/1.
The following graph plots values of average queue size and residence time versus utilization for three
values of coefficient of variation.
12
From the graph, we can see that the poorest performance is exhibited by the exponential service time,
and the best by a constant service time.
Analysis can be done considering the worst case. The values can be looked up easily from the table
available for M/M/1 case.
σ
Four regions of TTSS :
• Zero: A rare case of constant service time. Example: If all transmitted messages are of the same
length.
• Less than 1: The ratio is better than the exponential case. So, the M/M/1 table will give slightly
larger queue sizes and times which will be on the safe side. Example: Data entry application of a
particular form.
• Close to 1: Corresponds to exponential service time meaning that the service times are random.
Example: Message lengths to a computer terminal: A full screen might be 1920 characters, with
message sizes varying over the full range. Airline reservations, file lookups on inquiries, shared
LAN, and packet switching networks are some other examples of this category.
• Greater than 1: Corresponds to bimodal distribution with a wide spread between the peaks. and
M/G/1 model arises. So, M/M/1 model is not reliable for this case. Example: A system that
experiences many short messages, many long messages and few in between.
Similar consideration should apply in calculating the arrival rate distribution.
13
• For a Poisson arrival rate, the inter arrival times are exponential and the ratio of standard deviation
to mean is 1.
• For a ratio much smaller than 1, the arrivals tend to be evenly spaced. So, Poisson assumption
will overestimate the queue sizes and delays.
• If the ratio is greater than 1, then arrivals tend to cluster and congestion becomes more acute.
• Number of Customers in the System: In steady-state, the expected value of the state distri-
bution vector {πk } gives the mean number of customers in the system. We will find a solution
for the stationary distribution {πk } for continuous-time Birth-Death processes (queuing systems)
later in this section. Given {πk }, many of the other performance measures of interest may be
derived.
14
• Utilisation (ρ) For a queuing system with a single server, utilisation ρ is the fraction of time the
server is busy. When there is no limit on the capacity of the system, then
mean service time arrival rate λ
ρ= = =
mean inter-arrival time service rate µ
The utilization ρ when there are multiple servers, is the mean fraction of busy servers. Since mµ
is the overall service rate, in this case we have
λ
ρ=
mµ
• Throughput (λ): The throughput for a queuing system with infinite capacity is the mean
number of customers processed in a unit of time, i.e. the departure rate. Since the departure rate
is equal to the arrival rate (and assuming ρ < 1 ), the throughput is
λ=m·ρ·µ
For a queuing system with finite capacity, there can be loss in the systems, and so the throughput
can be less than the arrival rate. In this case, throughput is often denoted differently (e.g. as S
) to distinguish it from the arrival rate λ.
• Response Time (T ): (or sojourn time) is the total time a customer spends in the system.
• Waiting Time (W ) : is the time a job spends in the queue waiting to be serviced. Therefor,
response time is the sum of the waiting time and the service time for a customer. T and W are,
in general, random variables, so the expected values ( T̄ and W̄ ) are often used and we may
write:
1
T̄ = W̄ +
µ
• Number of Customers in the System (N ) Again N is a random variable and its expected value
N̄ is often of interest:
∞
∑
N̄ = k · πk
k=1
15
Each user has at least one separate program in memory. A time shared operating system allows the
many users to share the computer simultaneously.
As the system switches rapidly from one user to the next, each user is given the impression that she has
her own computer, whereas actually one computer is being shared among many users.
Example: SimOS
SimOS is a software that models the hardware components of a target machine.
• Contains software simulation of all the hardware components of modern computer systems:
– Processors
– Memory Management Units
– Caches, Memory Systems
– I/O Devices ex. SCSI disks, Ethernets, hardware clocks, and consoles.
• It simulates the hardware of a computer system in detail to boot a commercial operating system
and run realistic workloads on top of it.
• The user can explicitly control the tradeoff between simulation speed and simulation detail.
• It contains flexible annotation and event classification mechanisms that map the data back to
concepts meaningful to the user.
• This allows the users to handle the large amount of low-level data generated by the hardware
simulation models.
16