Queuing Theory
Queue Characteristics:
• finite or infinite
• queue discipline:
FCFS = first-come-first-served LCFS = last -come-first-served
Priority service order Random service order
= lim P ( t )
n
t →∞
For general queues, the steady state probabilities Pn can be difficult to compute.
However, if the queue is a continuous time Markov Chain, then Pn= ωn (if a
steady-state distribution exists).
MS&E 121 Handout #11
Introduction to Stochastic Modeling February 25, 2005
L = LS + LQ
W = the waiting time in the system for an arbitrary customer (random variable)
WQ = the waiting time in the queue for an arbitrary customer (random variable)
W = the long run average amount of time a customer spends in the system
= E(W )
WQ = the long run average amount of time a customer spends in the queue
= E(WQ )
W = WS + WQ
MS&E 121 Handout #11
Introduction to Stochastic Modeling February 25, 2005
Little’s Law
A quick diversion
A few topics I want to weave in before we proceed with Little’s Law and
its variations:
Suppose you have two independent Poisson arrival processes X and Y with
respective rates λx and λy. Then the combination of the two arrival streams is
also a Poisson process with rate λx+ λy.
∑p k = 1.
k =1
Then the arrivals of customers of type k follow a Poisson process with rate
pkλ.
€
An example: suppose arriving customers to a system balk with fixed
probability p independent of the number of people in the system. If the arrival
process is Poisson with rate λ, the arrivals who stay follow a Poisson process
with rate
(1-p)λ. The customers who balk do so according to a Poisson process with
rate pλ.
MS&E 121 Handout #11
Introduction to Stochastic Modeling February 25, 2005
This property is called “Poisson Arrivals See Time Averages.” It depends critically
on the assumption of having a Poisson arrival process. Suppose, instead, for
example, that we have deterministic arrival and service processes with respective
rates λ and µ (with λ < µ).
empty system 1 customer
∑ω q i ij = 0 for j=0,...,S
i= 0
In simple queuing systems that can be modeled as birth and death processes,
the “rate-in = rate-out” equations are particularly simple to write down because
transitions can only occur to adjacent states. In such cases, they are a shortcut
to writing down the steady state equations.
0 1 2 3 ….
µ1 µ2 µ3 µ4
0 µ1ω1 = λ0ω 0
... ...
n-1 λn − 2ω n − 2 + µ nω n = (λn −1 + µ n −1 )ω n −1
0 1 2 3 &.
µ µ µ µ
0 µω1 = λω 0
1 λω 0 + µω 2 = (λ + µ )ω1
... ...
n-1 λω n − 2 + µω n = (λ + µ )ω n −1
n λω n −1 + µω n +1 = (λ + µ )ω n
... ...
Little’s Law
L=λW
MS&E 121 Handout #11
Introduction to Stochastic Modeling February 25, 2005
t
1 Q (t ) 1 Q ( t )
lim N ( s )ds = lim ∑ Wi
t →∞ t ∫ t →∞ t Q (t ) i =1 L=λW
0
LQ = λ W Q
MS&E 121 Handout #11
Introduction to Stochastic Modeling February 25, 2005
By assuming instead that each customer pays $1 per unit time that
they are in service, we have
the average rate at which the system earns = LS
the average amount an entering customer pays = WS
The basic cost identity amounts to:
LS = λ WS
€
Define ρ=λ/µ. This quantity is typically called the traffic intensity for the M/M/1
€
queue. We assume henceforth that ρ<1, in which case we know a steady state
distribution exists and is given by:
Pj = ω j = ρ j (1 − ρ ) for j = 0,1,...
The long run average number of people in the system can be computed using
the steady state distribution:
∞ ∞ ∞
L = ∑ jPj = ∑ jω j = (1 − ρ ) ∑ jρ j
j =0 j =0 j =0
ρ
= (1 − ρ )
(1 - ρ ) 2
ρ
=
(1- ρ )
λ
=
(µ - λ )
MS&E 121 Handout #11
Introduction to Stochastic Modeling February 25, 2005
We can also compute the long run expected number of customers in the
queue LQ using the steady state distribution as follows:
∞ ∞ ∞ ∞
LQ = ∑ ( j − 1) Pj = ∑ ( j − 1)ω j = ∑ jω j − ∑ ω j
j =1 j =1 j =1 j =1
∞
= ∑ jω j − (1 − ω0 )
j =0
= L−ρ
λ λ λ2
= − =
(µ - λ ) µ µ(µ - λ )
€
MS&E 121 Handout #11
Introduction to Stochastic Modeling February 25, 2005
It is easy to verify that we get the same result by taking the expected value of W.
Clearly the function F(n) is convex, so to find its minimum we need only to set its
derivative equal to zero.
Since we must have at least one checkpoint, the optimal number of checkpoints is 1.
Define ρ=λ/Sµ as the traffic intensity for the M/M/S queue. To ensure the existence
of a steady state distribution, we assume that ρ<1. In this case:
P0 = ω0 = (1 + K ) −1 where
−1
λj S −1
λi λS λ
(1 + K ) −1 for j ≤ S K≡ ∑ i ! µ i + S ! µ S 1 − Sµ
j!µ j
Pj = ω j = i =1
λj
j−S j
(1 + K ) −1 for j > S
S !S µ
(λ µ ) S ∞ i
= (1 + K ) −1 ∑ iρ
S ! i =0
S
(λ µ ) ρ
= (1 + K ) −1
S ! (1 − ρ ) 2
Now we can apply Little’s law and our other identities to compute:
W Q = L Q /λ W = WQ + (1/µ) L= λW
Now we want to determine the optimal number of servers; i.e., the number that
minimize Safeway’s total costs. We need to compute the expected costs incurred
per hour.
WQ = LQ /λ = LQ /λ = 0.675/18 = 0.0375
From this and the fact that W = WQ + (1/µ), we find that the average length
of time a person waits in the register area is W = 0.104 hours, and the average
number of people in the register area is L = λW = λW = 1.8738.
Since each open checkout line costs Safeway $20 per hour, and each hour that a
customer waits costs $15, the expected average costs per hour are
$20S + $15L = $68.11
WQ = LQ /λ = LQ /λ = 0.0879/18 =0.0049
C C
1− ρ C
L = ∑ jPj = ∑ jω j =
j =0 j =0
∑ jρ j
1 − ρ C +1 j = 0
1− ρ C d
= ∑ ρ (ρ j )
1 − ρ C +1 j = 0 dρ
1− ρ d C j
= C +1 ρ
∑ ρ
1− ρ dρ j = 0
1− ρ d 1 − ρ C +1
= C +1 ρ
1− ρ dρ 1 − ρ
ρ (C + 1) ρ C +1
= −
1− ρ 1 − ρ C +1
MS&E 121 Handout #11
Introduction to Stochastic Modeling February 25, 2005
∞
= ∑ jω j − (1 − ω0 )
j =0
= L − (1 − ω0 )
From Little’s law and the other identities, the quantities W, WQ, and WS
are easily derived.
W Q = L Q /λ W = WQ + (1/µ) L= λW
We use the basic cost identity to determine the (long-run) average daily
income of each lawyer:
average rate lawyer earns = λ x average amount an accepted client pays
MS&E 121 Handout #11
Introduction to Stochastic Modeling February 25, 2005
In all of the examples we have seen so far, we defined the state of the system to
be the number of customers in the system. This worked because in these
examples, the rate of departure from the system was dependent only on the
number of customers in the system. For example, in the M/M/S server queue, if
the number of people in the system is j >S, all servers are busy and j -S people
are in line. If j <S, then j servers are busy. Since all servers are assumed to be
indistinguishable, we do not care which j servers are busy.
How do we define the number of people in the system in this problem? If there
are 2 or more customers in the system at a particular time, then we know both
servers are busy. If there are no customers in the system, then no servers are
busy. But if there is exactly one customer in the system, which server is busy?
We need to distinguish between the two possibilities in that case.
Define states of the process to be:
0: no customers present
(1,0) : 1 customer present, being served by server 1
(0,1) : 1 customer present, being served by server 2
n : n customers present, n = 2,3,4
λ λ
(1,0)
µ2 λ λ
µ1
0 2 ….
3 4
µ2 µ1
(0,1) µ1+µ2 µ1+µ2
λ
0 − λ λ 0 0 0 0
(1,0) µ1 − ( λ + µ1 ) 0 λ 0 0
(0,1) µ2 0 − ( λ + µ2 ) λ 0 0
Q=
2 0 µ2 µ1 − ( λ + µ1 + µ2 ) λ 0
3 0 0 0 ( µ1 + µ2 ) − ( λ + µ1 + µ2 ) λ
4 0 0 0 0 ( µ1 + µ2 ) − ( µ1 + µ2 )
MS&E 121 Handout #11
Introduction to Stochastic Modeling February 25, 2005
1 = P0 + P(1,0) + P( 0,1) + P2 + P3 + P4
Suppose λ= µ2=1 per minute and µ1=2 per minute. In this case, solving with Matlab
gives us:
(2) What is the average number of customers in service at the Post Office?
L = 0 ⋅ P0 + 1( P( 0,1) + P( 0,1) ) + 2( P2 + P3 + P4 ) = 0.6824
(3) What is the average time a customer spends in service at the Post Office?
λ = λ ( P0 + P( 0,1) + P(1,0) + P2 + P3 ) = 1(1 − P4 ) = 0.8941
W = L / λ = 0.6824 / 0.8941 = 0.7632 minutes
MS&E 121 Handout #11
Introduction to Stochastic Modeling February 25, 2005
The state of the system must include more information than simply the number of
customers in the shop, because the arrival and departure rates depend on where
in the shop the customers are.
P0 + P( 0,1)
Having the server for the second chair server be faster leads to loss of more potential
customers, but shorter average waits and fewer customers in the shop on average.
MS&E 121 Handout #11
Introduction to Stochastic Modeling February 25, 2005
Queueing systems often provide more than a single service. Many real-
world systems involve customers receiving a number of different
services, each at a different service station, where each station has a
queue for service. We can model systems of this kind using networks of
queues. There are two types of queueing networks: open and closed. An
open queueing network is one in which customers can enter and leave
the system. A closed queueing network is one in which there are a fixed
number of customers that never leave; new customers never enter.
S servers,
Poisson each with Poisson
arrivals service departures
with rate λ times with rate λ
~exp(µ)
MS&E 121 Handout #11
Introduction to Stochastic Modeling February 25, 2005
wash wax
λ=30/hr …. …. (1 server)
(1 server)
µ1=60/hr µ2=45/hr
We would like to find the steady state (0,0) (1,0) (2,0) (3,0) ….
distribution ω={ωn1,n2} for X(t)=(n1, n2). To µ1 µ1 µ1 µ1
µ2 µ µ µ
do this we would need to solve the system λ 2 λ 2 λ 2 λ
ωQ = 0, ωe = 1. But the Q matrix is difficult (0,1) (1,1) (2,1) (3,1) ….
to write down.To make our lives easier,
µ1 µ1 µ1 µ1
recall that the equations ωQ = 0 simply µ2 µ µ µ
λ 2 λ 2 λ 2 λ
state that the rate into any state equals
the rate out of that state. (0,2) (1,2) (2,2) (3,2) ….
….
….
….
….
MS&E 121 Handout #11
Introduction to Stochastic Modeling February 25, 2005
….
….
….
….
state rate out = rate in
(0,0) λω0,0 = µ2ω0,1
(n1,0); n1>0 (λ + µ1)ωn1,0 = µ2ωn1,1 + λωn1-1,0
(0,n2); n2>0 (λ + µ2)ω0,n2 = µ2ω0,n2+1 + µ1ω1,n2-1
(n1,n2); n1,n2>0 (λ + µ1 + µ2)ωn1,n2 = µ2ωn1,n2+1 + µ1ωn1+1,n2-1 + λωn1-1,n2
Now, if it were true that the number of cars at the wash and wax stations at
any time were independent random variables, then we would know that
∞ ∞
and ∑∑P
n1 = 0 n2 = 0
n1 ,n2 =1
is called the product form solution for the steady state distribution of the state
of the queueing network.
What is its significance? It tells us that the numbers of cars at the wash and wax
stations at any given time are, in fact, independent random variables!
This result depends heavily on the fact that the queue in front of each station has
infinite capacity. If not, the numbers of cars at the two stations would not be
independent.
MS&E 121 Handout #11
Introduction to Stochastic Modeling February 25, 2005
∞ ∞
n1 n2
= ∑n ρ
n1 = 0
1 1 (1 − ρ1 ) + ∑n ρ
n2 = 0
2 2 (1 − ρ2 )
ρ1 ρ2
= (1 − ρ1 ) + (1 − ρ2 )
(1 − ρ1 ) 2 (1 − ρ2 ) 2
ρ1 ρ2
= +
1 − ρ1 1 − ρ2
λ λ Notice that this equals the sum of the expected
= +
µ1 − λ µ2 − λ
numbers of cars at the two stations, respectively.
30 30
= + =3
30 15
What made the computation of L and W easy in this example was the product
form solution of the steady state distribution. It turns out that there is a much more
general framework under which a product form solutions are available. These are
called Jackson networks.
MS&E 121 Handout #11
Introduction to Stochastic Modeling February 25, 2005
(4) the probability that a customer exiting station i goes to station j is pij
m
(5) a customer exiting station i departs the system with probability 1 − ∑ j =1 pij
p12=1….
a1 =10/hr µ2 =60/hr p24 =0.6
p21=0.1
total arrival
rate into external arrival total arrival rate
station i rate into station i from other stations
It turns out that if λi /siµi <1 for each station i=1,2,…,m, then, as in the
car wash example, the steady state distribution has a product form
solution:
Product Form Solution for Open Jackson Networks
stations 1 and 3 have steady state distributions because the M/M/∞ queue
always does!
P ( j at station 2) = (1 − λ2 µ2 )( λ2 µ2 ) j
( λ3 µ3 ) j − λ3
P ( j at station 3) = e µ3
j!
( λ4 µ4 ) j
(1 + K ) −1 for 0 ≤ j ≤ 3
j!
P ( j at station 4) = j
( λ4 µ4 ) (1 + K ) −1 for j ≥ 4
3! 3 j − 3
2
( λ4 µ4 ) i ( λ4 µ4 ) 3 1
where K = ∑ +
i =0 i! 3! 1 − ( λ4 3µ4 )
( λ1 µ1 ) n1 − λ1
= e µ1
⋅ (1 − λ2 µ2 )(λ2 µ2 ) n2
n1 !
€
( λ4 µ4 ) n4 −1
n3
( λ3 µ3 ) − λ3 n ! (1 + K ) if 0 ≤ n4 ≤ 3
µ3
⋅ e ⋅ 4
n4
n3 ! ( λ4 µ4 ) (1 + K ) −1 if n ≥ 4
n
3! 3 4 − 3 4
This looks cumbersome but is easily evaluated for any particular state vector
(n1, n2, n3, n4). An example is (n1, n2, n3, n4) = (0,0,0,0):
P0,0,0,0 = e− λ 1 µ1
(1− λ2 µ2 )e− λ3 µ3
(1+ K )−1
=e −5.556
(1− 0.185)e −5.556
(1+ 7.11)−1
= 1.4962 ×10−6
€
€
MS&E 121 Handout #11
Introduction to Stochastic Modeling February 25, 2005
(4) The steady state probability that there are n1 customers at station 1,
n2 customers at station 2,…., nm customers at station m is just
Pn1 ,n2 ,...,nm = P (n1 at station 1) P (n2 at station 2)L P (nm at station m)
= ωn11 ⋅ ωn22 ⋅Lωnmm
(4) The steady state probability that there are n1 customers at station 1,
n2 customers at station 2,…., nm customers at station m is just
Pn1 ,n2 ,...,nm = ωn11 ⋅ ωn22 Lωnmm = (1 − ρ1 )( ρ1 ) n1 (1 − ρ2 )( ρ2 ) n2 L (1 − ρm )( ρm ) nm
m
= ∏ (1 − ρi )( ρi ) ni
i =1
MS&E 121 Handout #11
Introduction to Stochastic Modeling February 25, 2005
where
λ1 100/9
L1 = = = 5.56
µ1 2
Thus, their average hourly income from the berry field alone is $83.40.
L = L1 + L2 + L3 + L4 = 11.6
is the average steady state number of people at the farm.
MS&E 121 Handout #11
Introduction to Stochastic Modeling February 25, 2005
(3) the probability that a customer exiting station i goes to station j is pij
m
(4) no customers exiting the system, i.e., ∑ j =1
pij = 1
∑λ
i =1
i =1
(2) For each station i, calculate the steady state distribution ω i = (ω0i , ω1i , ω2i ,...)
for an M/M/si queue with arrival rate λi and the service rate µi.
(If λi exceeds µi, and si=1, then it’s okay to use the steady state
distribution anyway.)
continued….
MS&E 121 Handout #11
Introduction to Stochastic Modeling February 25, 2005
(3) The steady state probability that there are n1 customers at station 1,
n2 customers at station 2,…., nm customers at station m is just
0 if n1 + n2 +. .. nm ≠ n
ωn1 ⋅ ωn2 Lωnm
1 2 m
if n1 + n2 +. .. nm = n
Pn1 ,n2 ,...,nm = ω 1j1 ⋅ ω j22 Lω jmm
∑
j1 , j2 ,..., jm ≥ 0
j1 + j2 + ...+ jm = n
25 22 5
The resulting arrival rates are: λ1 = , λ = , λ3 =
52 2 52 52
j
27 25
station 1 (you): ω 1j =
52 52
j
19 33
station 2 (Barbara): ω j2 =
52 52
j
42 10
station 3 (Joyce): ω j3 =
52 52
(3) Now we want to compute the steady state probability that each of your
roommates has a Gameboy. This probability is denoted by P0,1,1
MS&E 121 Handout #11
Introduction to Stochastic Modeling February 25, 2005
The steady state probability that there are n1 Gameboys with you, n2
Gameboys with Barbara, and n3 Gameboys with Joyce is
0 if n1 + n2 + n3 ≠ 2
ωn1 ⋅ ωn2 ⋅ ωn3
1 2 3
if n1 + n2 + n3 = 2
Pn1 ,n2 ,n3 = ω 1j1 ⋅ ω j22 ⋅ ω j33
∑
j1 , j2 , j3 ≥ 0
j1 + j2 + j3 = 2
1
Let’s first compute the denominator: ∑ω j1 ⋅ ω j22 ⋅ ω j33
j1 , j2 , j3 ≥ 0
j1 + j2 + j3 = 2
2
27 25 19 42 we’re using:
(2, 0, 0) ω21ω02ω03 =
52 52 52 52
j
2
27 19 33 42 27 25
1 2 3
ω0 ω2 ω0 = ω 1j =
(0, 2, 0) 52 52 52 52 52 52
2
27 19 42 10 19 33
j
(0, 0, 2) ω01ω02ω23 = ω j2 =
52 52 52 52 52 52
27 25 19 33 42
(1, 1, 0) ω11ω12ω03 = 42 10
j
52 52 52 52 52 ω j3 =
27 25 19 42 10 52 52
1 2 3
(1, 0, 1) ω1 ω0 ω1 =
52 52 52 52 52
1 2 3 27 19 33 42 10
(0, 1, 1) ω0 ω1 ω1 =
52 52 52 52 52
MS&E 121 Handout #11
Introduction to Stochastic Modeling February 25, 2005
2
1 27 25 19 42
∑ω j1 ⋅ ω j22 ⋅ ω j33 = ω21ω02ω03 =
52 52 52 52
j1 , j2 , j3 ≥ 0 2
j1 + j2 + j3 = 2 27 19 33 42
+ ω01ω22ω03 =
52 52 52 52
2
27 19 42 10
+ ω01ω02ω23 =
52 52 52 52
27 25 19 33 42
+ ω11ω12ω03 =
52 52 52 52 52
27 25 19 42 10
+ 1 2 3
ω1 ω0 ω1 =
52 52 52 52 52
27 19 33 42 10
+ 1 2 3
ω0 ω1 ω1 =
52 52 52 52 52
= 0.1824
0 if n1 + n2 + n3 ≠ 2
ωn1 ⋅ ωn2 ⋅ ωn3
1 2 3
if n1 + n2 + n3 = 2
Pn1 ,n2 ,n3 = ω 1j1 ⋅ ω j22 ⋅ ω j33
∑
j1 , j2 , j3 ≥ 0
j1 + j2 + j3 = 2
The probability that each of your roommates has a Gameboy and you don’t is
• M/G/1 queue
• M/D/1 queue
• M/Ek/1 queue
Nonexponential Service:
The M/G/1 Queue
• Poisson input process with rate λ
• single server
• arbitrary service time distribution (iid for all customers)
with mean 1/µ and variance σ2
• infinite capacity queue
λ2σ 2 + ρ 2
For this class of queues, if ρ=λ/µ<1, then P0 = 1 − ρ and LQ = 2(1 − ρ )
Additional quantities of interest (W, WQ, L , LS) can be derived from LQ and P0.
MS&E 121 Handout #11
Introduction to Stochastic Modeling February 25, 2005
(1) What is the average amount of time a car spends waiting to be served?
(2) What is the average number of cars being served or waiting to be
served?
The mean service time is 1.5 minute (obtained by taking the mean of a
uniform [0,3] random variable) so the average service rate µ is 2/3
cars/minute. Thus ρ=λ/µ=3/4. The variance of the service time is σ2 =
(3)2/12 = 3/4. The average waiting time in queue for each car, measured in
minutes, is computed using the P-K equation and our useful relationship
between LQ and WQ :
LQ LQ λ2σ 2 + ρ 2 (0.5) 2 (0.75) + (0.75) 2
WQ = = = = = 3 minutes
λ λ 2λ (1 − ρ ) 2(0.5)(0.25)
L = LQ + LS
λ2σ 2 + ρ 2
L = LQ + LS = +ρ
2(1 − ρ )
(0.5) 2 (0.75) + (0.75) 2
= + (0.75) = 2.25 cars
2(0.25)
MS&E 121 Handout #11
Introduction to Stochastic Modeling February 25, 2005
Nonexponential Service:
The M/D/1 Queue
Since Jim’s service time is deterministic, the variance of his service time is
zero. In his case, ρ=λ/µ=0.775. By contrast, Jim has people wait in queue on
average
LQ LQ ρ2 (.775) 2
WQ = = = = = 2.6694 minutes
λ λ 2λ (1 − ρ ) 2(0.5)(.225)
W = WQ + WS = 2.6694 + 155
. = 4.2194 minutes
Nonexponential Service:
The M/Ek/1 Queue
Now we consider another special case of the M/G/1 queue, namely the M/
Ek/1 queue. The notation Ek stands for the Erlang distribution with shape
parameter k. To motivate this type of queue, we first mention some
important facts about the Erlang distribution.
The Erlang (µ,k) random variable is also called a Gamma (k,µk) random
variable.
Note: if k = 1, then X is exponentially distributed with parameter µ
MS&E 121 Handout #11
Introduction to Stochastic Modeling February 25, 2005
Nonexponential Service:
The M/Ek/1 Queue
• Poisson input process with rate λ
• single server
• Erlang (µ,k) service time distribution; mean 1/µ and variance 1/kµ2
• infinite capacity queue
or n≤2