25
Notes on queuing theory T. M. Jonassen [email protected] Department of Computer Science Faculty of Technology, Art and Design Oslo and Akershus University College of Applied Sciences November 3, 2011 Abstract These notes contains part 2 of some stuff I lectured in Analytical System Ad- ministration autumn 2011 at Department of Computer Science, Faculty of Technol- ogy, Art and Design, Oslo and Akershus University College of Applied Sciences at the Master Programme in Network and System Administration. These notes should be considered as notes only, in addition you will need your own handwrit- ten notes from the lectures. I have also included some examples of solved exercises, taken from given ex- ercises. A triangle () ends a solved exercise. The basic model The basic queue model consists of three main systems, the arriving objects, a queue of arrived objects waiting to be processed by a processing unit, and the processing unit itself. In our models we don’t care what happens to the objects after they have been processed. Incomming objects Objects in queue Processing unit Processed objects Figure 1: The basic diagram for a queuing model. 1

Notes on queuing theory - HiOA · Notes on queuing theory T. M. Jonassen [email protected] Department of Computer Science Faculty of Technology, Art and Design ... queuing discipline

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Notes on queuing theory - HiOA · Notes on queuing theory T. M. Jonassen torejo@hio.no Department of Computer Science Faculty of Technology, Art and Design ... queuing discipline

Notes on queuing theory

T. M. [email protected]

Department of Computer ScienceFaculty of Technology, Art and Design

Oslo and Akershus University College of Applied Sciences

November 3, 2011

Abstract

These notes contains part 2 of some stuff I lectured in Analytical System Ad-ministration autumn 2011 at Department of Computer Science, Faculty of Technol-ogy, Art and Design, Oslo and Akershus University College of Applied Sciencesat the Master Programme in Network and System Administration. These notesshould be considered as notes only, in addition you will need your own handwrit-ten notes from the lectures.

I have also included some examples of solved exercises, taken from given ex-ercises. A triangle (△) ends a solved exercise.

The basic modelThe basic queue model consists of three main systems, the arriving objects, a queue ofarrived objects waiting to be processed by a processing unit, and the processing unititself. In our models we don’t care what happens to the objects after they have beenprocessed.

Incomming objects

Objects in queue

Processing unit

Processed objects

Figure 1: The basic diagram for a queuing model.

1

Page 2: Notes on queuing theory - HiOA · Notes on queuing theory T. M. Jonassen torejo@hio.no Department of Computer Science Faculty of Technology, Art and Design ... queuing discipline

2 T. M. Jonassen

In many systems we don’t have exact knowledge about the arrival process of ob-jects, and we don’t have exact knowledge of the time the processing unit takes to pro-cess each object. Hence the basic model given in figure 1 can be seen as the interactionbetween two stochastic systems, the arrival process and the processing of objects.

Example 1. A familiar example from real life is customers arriving to a store. Thecustomers shops different amounts of goods, and the time it takes in the counter(s) toprocess each customer will vary.

Example 2. The arriving objects may be requests to a web-server. Assuming that theweb-server don’t have static pages, and some pages has server-side scripts, the process-ing time of each request will vary.

The Kendall notationThis section describes the standard notation for queuing models. The notation forqueuing discipline policy may vary in the literature.

The full Kendall naming convention for queue models is

A/S/c/b/k/PNote that

A/S/cis the most used naming convention. In the full Kendall naming convention, the differ-ent symbols have the following meaning:

• A : The probability distribution for arrival times

• S : The probability distribution for service times

• c : The number of parallel service channels

• b : System capacity restriction (max in queue)

• k : Maximum potential population size

• P : Policy (queuing discipline)

The standard letter codes for A and S are

• M : Exponential distribution (memoryless)

• D : Deterministic distribution

• Ek : Erlang-k distribution

• Hk : Hyperexponential-k distribution

• G : General

Page 3: Notes on queuing theory - HiOA · Notes on queuing theory T. M. Jonassen torejo@hio.no Department of Computer Science Faculty of Technology, Art and Design ... queuing discipline

Lecture note: Queues 3

c, b and k are extended positive integers (meaning infinity included).The standard codes for the policy P are

• FCFS : First come first served

• LCFS : Last come first served

• RSS : Random selected

• PR : Priority

• PS : Processor sharing

• GD : General dicipline

Basic queueing model metricsWe will use the following notation:

• λ – arrival rate

• µ – service rate

• ρ = λ/µ < 1 – mean number of objects in service (M/M/1-model)

• ρ = λ/nµ < 1 – mean number of objects in service (M/M/n-model)

• E(B) – mean service time

• E(L) – average number of objects

• E(S) – average sojourn time (wait + service time)

• E(W ) – average waiting time

• E(Lq) – average queue length

• ρu = λE(B) – utilization rate

Little’s lawLittle’s law states that

E(L) = λE(S)

that is, that the average number of objects, E(L), in the system is proportional with theaverage sojourn time, E(S). The proportional factor is the arrival rate of objects, λ.

Applying Little’s law to the average queue length E(Lq) and the average waitingtime E(W ), we obtain the following relation.

E(Lq) = λE(W )

Page 4: Notes on queuing theory - HiOA · Notes on queuing theory T. M. Jonassen torejo@hio.no Department of Computer Science Faculty of Technology, Art and Design ... queuing discipline

4 T. M. Jonassen

Little’s law applied to the processing unit alone, gives

ρ = λE(B)

where ρ is the mean number of objects at the processing unit, and E(B) is the meanservice time. Note that the mean number of objects at the processing unit is the sameas the fraction of time the processing unit is working, that is the utilization rate.

The Arrival Theorem and the PASTA propertyThe Arrival Theorem, also called ROP (Random Observer Property), states that thestate of a system immediately before an arrival is independent of that arrival.

This implies that the distribution an object in transit to state i sees the equilibriumdistribution of the system.

The PASTA property (Poisson Arrivals See Time Averages) states that the proba-bility of the state as seen by an outside random observer is the same as the probabilityof the state seen by an arriving object.

More precisely, the fraction of objects finding the system in some state i, is thesame as the fraction of time the system is in state i. Note that PASTA property is trueonly for Poisson arrivals.

A telephone switchboard exampleWe will look at a model for the traffic intensity on a telephone switchboard. This willillustrate how we by a calculus approach obtain the exponeltal distribution.

Consider a time interval of length h > 0 given by I = [t, t + h). The probabilityfor an incoming call in I is denoted by P (t, t+ h).

The average traffic intensity in I is then given by

λI =P (t, t+ h)

h

Assume that the limit given by

λ(t) = limh→0+

P (t, t+ h)

h

exists. We will call the quantity λ(t) for the traffic intensity at time t.Hence the probability for a call in a time interval (t, t+∆t), ∆t > 0 small, is approx-imately λ(t)∆t:

P (t, t+∆t) ≈ λ(t)∆t

We will in the following assume that λ(t) is independent of t, λ(t) = λ.Consider two disjoint intervals [t1, t2] and [t′1, t

′2] and assume that the events A, “a

call between t1 and t2” and B: “a call between t′1 and t′2” are independent events.Independence means that the conditional probabilities P (A|B) and P (A|B′) are equal,that is, the probability of A doesn’t change whether we are given B or given not B.

Page 5: Notes on queuing theory - HiOA · Notes on queuing theory T. M. Jonassen torejo@hio.no Department of Computer Science Faculty of Technology, Art and Design ... queuing discipline

Lecture note: Queues 5

t t t’ t’1 2 1 2

Figure 2: Illustration of two disjoint intervals

The object now is to find the probability function for the time T of the first call,that is, we need to find the probability F (t) for the first call to take place at latest attime t. Then

Q(t) = 1− F (t)

is the probability for no calls in time [0, t].

The event “no call in time [0, t+∆t]” is the intersection of the event “no call in time[0, t)” and the event “no call in time [t, t+∆t]”. Hence by the previous approximationexpression P (t, t+∆t) ≈ λ(t)∆t the probability is the product

Q(t+∆t) = Q(t)(1− λ∆t)

because the two events are independent.The equation Q(t+∆t) = Q(t)(1− λ∆t) can be written as

Q(t+∆t)−Q(t)

∆tQ(t)= −λ

and by taking the limit ∆t→ 0+, we obtain the separable first order differential equa-tion

Q′(t)

Q(t)+ λ = 0 with Q(0) = 1

The general solution is easily found by integration.We find

lnQ(t) + λt = C where C is a constant

This gives us the following expression for Q:

Q(t) = eC−λt with Q(0) = 1

The initial condition then gives C = 0, and hence the solution

Q(t) = e−λt

Since F (t) = 1−Q(t) the probability function F for the first call is

F (t) = 1− e−λt for t ≥ 0

Note: This is the exponential distribution, here shown below with λ = 0.475:

Page 6: Notes on queuing theory - HiOA · Notes on queuing theory T. M. Jonassen torejo@hio.no Department of Computer Science Faculty of Technology, Art and Design ... queuing discipline

6 T. M. Jonassen

2 4 6 8 10t

0.2

0.4

0.6

0.8

1

F

Figure 3: The exponential distribution with parameter λ = 0.475.

The M/M/1 modelThis section describes the M/M/1 model. In this model the arriving objects as anexponentially distributed arrival times with parameter λ and the processing unit hasexponentially distributed services time with parameter µ. There is a single processingunit, that can only handle one job at the time. From the properties of the exponentialdistribution we know that the mean of the interarrival times is 1/λ, that is the meantime interval between two consecutive arrivals, and the mean time to perform a singleservice (job) is 1/µ.

We will assume that the average interarrival time 1/λ is greater that the averageprocessing time 1/µ, that is,

ρ =λ

µ< 1

If this is not the case, the incoming amount of work is greater than the system’s capac-ity, and the queue of waiting objects will clearly grow to infinity.

We will now derive the equations describing the M/M/1-model. We will assumethat the arrival rate λ and the service rate µ are constants, independent of time t. Letpn(t) denote the probability that there are n objects in the system. Note that we canhave transitions n− 1 ↔ n↔ n+ 1, for n = 1, 2, 3, . . . , for the number of objects inthe system. We have seen (lecture note 1) that the probability for an arrival in the timeinterval (t, t+∆t) is given by

P (X < t+∆t|X > t) = 1− exp(−λ∆t) = λ∆t+ o(∆t)

where this probability depends only of the length of the time interval, not of the past orof the future. For small ∆t > 0 we then have

p0(t+∆t) = (1− λ∆t)p0(t) + µ∆tp1(t) + o(∆t)

pn(t+∆t) = λ∆tpn−1(t) + (1− (λ+ µ)∆t)pn(t) + µ∆tpn+1(t) + o(∆t)

Page 7: Notes on queuing theory - HiOA · Notes on queuing theory T. M. Jonassen torejo@hio.no Department of Computer Science Faculty of Technology, Art and Design ... queuing discipline

Lecture note: Queues 7

where n ≥ 1. Note that

lim∆t→0+

pn(t+∆t)− pn(t)

∆t=dpn(t)

dt

we obtain that

p′0(t) = −λp0(t) + µp1(t)

p′n(t) = λpn−1(t)− (λ+ µ)pn(t) + µpn+1(t)

where n ≥ 1, and subject to the condition that

∞∑i=0

pn(t) = 1

The flow diagram for the M/M/1-model is given in figure 4. It is possible to solve theabove set of differential equations, however, we will look for the steady-state solution,that is, when p′n(t) = 0 for n = 0, 1, 2, 3, . . . . Hence we write pn = pn(t), and obtain

0 = −λp0 + µp1

0 = λpn−1 − (λ+ µ)pn + µpn+1

where n ≥ 1, and∞∑i=0

pn = 1

0 1 n− 1 n n+ 1

λ λ λ

µ µ µ

Figure 4: The flow diagram for the M/M/1 model.

Let ρ = λ/µ. The the above difference equations for pn becomes

p1 = ρp0

pn+1 = −ρpn−1 + (ρ+ 1)pn

where n ≥ 1. We find

p1 = ρp0

p2 = −ρp0 + (ρ+ 1)p1 = −ρp0 + ρ2p0 + ρp0 = ρ2p0

p3 = −ρp1 + (ρ+ 1)p2 = −ρ2p0 + ρ3p0 + ρ2p0 = ρ3p0

...

Page 8: Notes on queuing theory - HiOA · Notes on queuing theory T. M. Jonassen torejo@hio.no Department of Computer Science Faculty of Technology, Art and Design ... queuing discipline

8 T. M. Jonassen

and by induction we conclude that pn = ρnp0 for n = 0, 1, 2, 3, . . . . Furthermore weobtain

1 =∞∑i=0

pn =∞∑

n=0

ρnp0 = p0

∞∑n=0

ρn =p0

1− ρ

from the sum of a geometric series, and the assumption that 0 < ρ < 1. This gives

p0 = 1− ρ

and consequently that

pn = (1− ρ)ρn where n = 0, 1, 2, . . .

Metrics for the M/M/1-modelThe number n of objects in the system is a discrete geometrically distributed randomvariable, where we have shown (lecture note 1) that

E(L) =ρ

1− ρ

Furthermore, by Little’s law we have

E(L) = λE(S)

These two relations can be used to derive the following formulas for the M/M/1-model metrics.

E(S) =1

λE(L) =

1

λ

ρ

1− ρ=

1/µ

1− ρ

E(Lq) = E(L)− ρ =ρ

1− ρ− ρ =

ρ− ρ(1− ρ)

1− ρ=

ρ2

1− ρ

E(W ) = E(S)− 1

µ=

1/µ

1− ρ− 1

µ=

1− (1− ρ)

µ(1− ρ)=

ρ

µ(1− ρ)

Example 3. By using the derived metrics for the M/M/1-model we can obtain thefollowing table, where λ = 5 has been kept constant, and µ is varied.

λ µ ρ E(L) E(S) E(Lq) E(W )

5. 5.25 0.952381 20. 4. 19.0476 3.809525. 5.5 0.909091 10. 2. 9.09091 1.818185. 5.75 0.869565 6.66667 1.33333 5.7971 1.159425. 6. 0.833333 5. 1. 4.16667 0.8333335. 6.25 0.8 4. 0.8 3.2 0.645. 6.5 0.769231 3.33333 0.666667 2.5641 0.5128215. 6.75 0.740741 2.85714 0.571429 2.1164 0.423285. 7. 0.714286 2.5 0.5 1.78571 0.3571435. 7.25 0.689655 2.22222 0.444444 1.53257 0.3065135. 7.5 0.666667 2. 0.4 1.33333 0.266667

Page 9: Notes on queuing theory - HiOA · Notes on queuing theory T. M. Jonassen torejo@hio.no Department of Computer Science Faculty of Technology, Art and Design ... queuing discipline

Lecture note: Queues 9

Exercise example 1. Suppose that arrivals occur at T1, T2, . . . . The interarrival timesAn = Tn − Tn−1 are independent and have a common exponential distribution withmean 1/λ, where we define T0 = 0. Let N(t) denote the number of arrivals in theinterval It = [0, t], and define

pn(t) = P (N(t) = n), t > 0, n = 0, 1, 2, 3, . . .

(1) Determine p0(t).

(2) Show that for n = 1, 2, 3, . . . we have

pn(t) =

t∫0

pn−1(t− ξ)λe−λξ dξ, t > 0

(3) Solve the above integral equations for n = 1, 2, 3, . . . .

Solution exercise example 1. We note that this exercise is concerned with a Poissoncounting process with discrete arrival times.

(1)

By our definition of p0(t) we have

p0(t) = P (N(t) = 0)

whereN(t) is the number arrivals in [0, t]. Hence p0(t) is the probability of no arrivalsin the interval [0, t], or in other words, the first arrival occurs after time t, so p0(t) =P (A1 > t). By our general remarks above we then have

p0(t) = P (A1 > t) = 1− Fλ(t) = 1− (1− e−λt) = e−λt

since P (A1 ≤ t) = Fλ(t) by the assumptions of arrival distribution in the model.

(2)

We have An = Tn − Tn−1 with T0 = 0 where Ti is the time of the i-te arrival, so

Tj =

j∑i=1

Ai

By assumption the events (the arrivals) are independent. Independence implies that thedensity function of all the events is a product of the density functions for each event.We denote the density function for event i by fi. Hence

P (Tn ≤ t) =

∫· · ·∫

A1+···+An≤t

f1(A1) · · · fn(An) dA1 · · · dAn

Page 10: Notes on queuing theory - HiOA · Notes on queuing theory T. M. Jonassen torejo@hio.no Department of Computer Science Faculty of Technology, Art and Design ... queuing discipline

10 T. M. Jonassen

Let us consider a special case, that is two independent events with X = t1 + t2, anddensity functions f1 and f2 respectively. Then

P (X ≤ t) = P (t1 + t2 ≤ t) =

∫∫t1+t2≤t

f1(t1)f2(t2) dt1dt2

The region t1 + t2 ≤ t in the t1t2-plane can be written as (−∞, t − t2) × R, so weobtain ∫∫

t1+t2≤t

f1(t1)f2(t2) dt1dt2 =

∞∫−∞

t−t2∫−∞

f1(t1)f2(t2) dt1dt2

=

∞∫−∞

f2(t2)

t−t2∫−∞

f1(t1) dt1

dt2

=

∞∫−∞

f2(t2)F1(t− t2) dt2

where F1 is the distribution with density f1.If we now consider density functions fi = fi(t) with the property that fi(t) = 0

for t < 0 (as in our exponential case), the integral above takes the form

P (X ≤ t) =

∞∫−∞

f2(t2)F1(t− t2) dt2 =

t∫0

f2(t2)F1(t− t2) dt2

since f2(t2) = 0 for t2 < 0 and F1(t− t2) = 0 if t− t2 < 0.We can now apply the above argument to our arrival process. The arrivals are

independent with density f(t) = λe−λt. Consider n − 1 arrivals as one event, and asingle event as another event. These two events are independent, and we may use ourabove computation as follows.

Let f2(t) = f(t) = λe−λt and F1(t) = pn−1(t) is the last integral above, and wethen have

pn(t) =

t∫0

pn−1(t− ξ)f(ξ) dξ =

t∫0

pn−1(t− ξ)λe−λξ dξ

for n = 1, 2, 3, . . . .

(3)

We observe that for n = 1 we have

p1(t) =

t∫0

p0(t− ξ)λe−λξ dξ =

t∫0

e−λ(t−xi)λe−λξ dξ =

t∫0

λe−λt dξ = λte−λt

Page 11: Notes on queuing theory - HiOA · Notes on queuing theory T. M. Jonassen torejo@hio.no Department of Computer Science Faculty of Technology, Art and Design ... queuing discipline

Lecture note: Queues 11

Assume that

pn−1(t) =(λt)n−1

(n− 1)!e−λt

In particular, this formula is true for p0(t) = e−λt and p1(t) = λte−λt By the formulain the solution in part (2) and the assumption we obtain

pn(t) =

t∫0

pn−1(t− ξ)λe−λξ dξ =

t∫0

(λ(t− ξ))n−1

(n− 1)!e−λ(t−ξ)λe−λξ dξ

=

t∫0

(λ(t− ξ))n−1

(n− 1)!λe−λt dξ = −

0∫λt

un−1

(n− 1)!e−λt du

=

λt∫0

un−1

(n− 1)!e−λt du =

un

n(n− 1)!e−λt

∣∣∣λt0

=(λt)n

n!e−λt

and the result follows by induction on n. △

Exercise example 2. Consider a work station where jobs arrive according to a Poissonprocess with arrival rate λ. The jobs have an exponentially distributed service timewith mean 1/µ. So the service completion rate (the rate at which jobs depart from thesystem) is equal to µ. If the queue length drops below the threshold QL the servicecompletion rate is lowered to µL. If the queue length reaches QH , where QH ≥ QL,the service rate is increased to µH . (L stands for low, H for high.)

Determine the queue length distribution and the mean time spent in the system.

Solution exercise example 2. We have

µs =

µL if n < QL

µ if QL ≤ n < QH

µH if n ≥ QH

where µL < µ < µH and QL ≤ QH . The stationary solution is then given by

λpn = µspn+1

Hence we have

λpn =

µLpn+1 if n+ 1 < QL

µpn+1 if QL ≤ n+ 1 < QH

µHpn+1 if n+ 1 ≥ QH

We obtain

pn+1 =λ

µspn

Page 12: Notes on queuing theory - HiOA · Notes on queuing theory T. M. Jonassen torejo@hio.no Department of Computer Science Faculty of Technology, Art and Design ... queuing discipline

12 T. M. Jonassen

so p1 = λµsp0, p2 = λ

µsp1 =

(λµs

)2p0 and we obtain

pn =

µs

)n

p0

where µs changes at n = QL and n = QH . Hence we obtain

pn =

p0

(λµL

)nif n < QL

p0

(λµL

)QL−1 (λµ

)n−QL+1

if QL ≤ n < QH

p0

(λµL

)QL−1 (λµ

)QH−QL(

λµH

)n−QH+1

if n > QH

We will need the following algebraic expressions for some finite geometric sums(shown in the lectures):

N∑n=0

rn =rN+1 − 1

r − 1

N∑n=1

rn =rN+1 − 1

r − 1− r − 1

r − 1=rN+1 − r

r − 1

and the infinite geometric series

∞∑n=0

rn+1 =r

1− r

We know that∞∑

n=0

pn = 1

where pn is given above. We will use this to determine p0. We write

∞∑n=0

pn =

QL−1∑n=0

pn +

QH−1∑n=QL

pn +∞∑

n=QH

pn

and use the following notation to simplify our expressions. Let

ρL =λ

µL, ρN =

λ

µand ρH =

λ

µH

We find that

QL−1∑n=0

pn =

QL−1∑n=0

p0ρnL = p0

QL−1∑n=0

ρnL = p0ρQL

L − 1

ρL − 1

Page 13: Notes on queuing theory - HiOA · Notes on queuing theory T. M. Jonassen torejo@hio.no Department of Computer Science Faculty of Technology, Art and Design ... queuing discipline

Lecture note: Queues 13

QH−1∑n=QL

pn =

QH−1∑n=QL

p0ρQL−1L ρn−QL+1

N

= p0ρQL−1L

QH−1∑n=QL

ρn−QL+1N

= p0ρQL−1L

QH−QL∑m=1

ρmN

= p0ρQL−1L

ρQH−QL+1N − ρN

ρN − 1

and∞∑

n=QH

pn =

∞∑n=QH

p0ρQL−1L ρQH−QL

N ρn−QH+1H

= p0ρQL−1L ρQH−QL

N

∞∑n=QH

ρn−QH+1H

= p0ρQL−1L ρQH−QL

N

∞∑m=0

ρm+1H

= p0ρQL−1L ρQH−QL

N

ρH1− ρH

Hence we have∞∑

n=0

pn =

QL−1∑n=0

pn +

QH−1∑n=QL

pn +∞∑

n=QH

pn

= p0

(ρQL

L − 1

ρL − 1+ ρQL−1

L

ρQH−QL+1N − ρN

ρN − 1+ p0ρ

QL−1L ρQH−QL

N

ρH1− ρH

)= p0A = 1

This gives

p0 =1

A=

1

ρQLL −1

ρL−1 + ρQL−1L

ρQH−QL+1

N −ρN

ρN−1 + p0ρQL−1L ρQH−QL

NρH

1−ρH

Hence we have all information about the queue length distribution.In order to find the mean sojourn time E(S), we can apply Little’s law, stating that

E(L) = λE(S). Hence we need to compute E(L). This can be done as above with

E(L) =∞∑

n=1

npn =

QL−1∑n=1

npn +

QH−1∑n=QL

npn +∞∑

n=QH

npn

using thatN∑

n=1

nrn =rN+1(nr − n− 1) + r

(1− r)2and

∞∑n=1

nrn =r

(r − 1)2

Page 14: Notes on queuing theory - HiOA · Notes on queuing theory T. M. Jonassen torejo@hio.no Department of Computer Science Faculty of Technology, Art and Design ... queuing discipline

14 T. M. Jonassen

The calculations are rather lengthy and tedious, and is left to the reader. △

Exercise example 3. In a gas station there is one gas pump. Cars arrive at the gasstation according to a Poisson process. The arrival rate is 20 cars per hour. Cars areserved in order of arrival. The service time (i.e. the time needed for pumping andpaying) is exponentially distributed. The mean service time is 2 minutes.

(1) Determine the distribution, mean and variance of the number of cars at thegas station.

(2) Determine the distribution of the sojourn time and the waiting time.

(3) What is the fraction of cars that has to wait longer than 2 minutes?

An arriving car finding 2 cars at the station immediately leaves.

(4) Determine the distribution, mean and variance of the number of cars at thegas station.

(5) Determine the mean sojourn time and the mean waiting time of all cars (in-cluding the ones that immediately leave the gas station).

Solution exercise example 3. The arrival rate and the service time are both distributedas Possion processes, so we can use the M/M/1-model in the computations.

We have λ = 20 and µ = 60/2 = 30, time measured in hours, so ρ = λ/µ =20/30 = 2/3. The quantity ρ is independent of the time unit, of course. However ifwe use minutes as our time unit, we have λ = 1/3 and µ = 1/2.

(1)

From the stationary solution of the M/M/1-queue we know that the queuelenght dis-tribution, is given by the geometric distribution pn = P (L = n) = (1 − ρ)ρn wheren = 0, 1, 2, . . . . Hence

pn = P (L = n) = (1− 2

3)

(2

3

)n

=1

3

(2

3

)n

where n = 0, 1, 2, . . .

Furthermore

E(L) =ρ

1− ρ=

23

1− 23

=2313

= 2

The variance σ2(L) for the geometric distribution with parameter ρ is given by

σ2(L) =ρ

(1− ρ)2=

2319

= 6

(Remark: The computational formulas for the geometrical distribution can be foundby using a generating function argument, and has been done in the lectures.)

Page 15: Notes on queuing theory - HiOA · Notes on queuing theory T. M. Jonassen torejo@hio.no Department of Computer Science Faculty of Technology, Art and Design ... queuing discipline

Lecture note: Queues 15

(2)

It can be shown by general theory that the distribution of the sojourn time when theexponential interarrival times with mean 1/λ and exponential service times with mean1/µ and ρ = λ/µ < 1 that the distribution of the sojourn time S is

P (S > t) = e−µ(1−ρ)t where t ≥ 0

and the distribution of the waiting time W is

P (W > t) = ρe−µ(1−ρ)t where t ≥ 0

soP (S ≤ t) = 1− e−µ(1−ρ)t where t ≥ 0

andP (W ≤ t) = 1− ρe−µ(1−ρ)t where t ≥ 0.

The expression for P (S > t) can be found using the Laplace-Stieltes transform, andthe details is not included here. Furthermore, P (W > t) is obtained from the previousresult by observing that S = W + B where B is the service time. W and B isindependent, and we can use the Laplace-Stieltes transform to find f∗W (s), since f∗S(s)and f∗B(s) are known. The details are omitted here.

In our case, we have ρ = 2/3, and µ = 30 if the time unit is hours and µ = 1/2 ifthe time unit is minutes. Using minutes as our scale we find that µ(1−ρ) = 1/2·1/3 =1/6 so

P (S ≤ t) = 1− e−t/6 where t ≥ 0

andP (W ≤ t) = 1− 2

3e−t/6 where t ≥ 0.

(3)

We calculate that P (W > 2) = ρe−µ(1−ρ)2 = 23e

−1/3 ≈ 0.477688 from the solutionin part (2) above.

(4)

The assumption that a car immediately leave the station if there are two cars impliesthat the queue is not longer than two. The stationary equations are then

λp0 − µp1 = 0

λp1 − µp2 = 0

p0 + p1 + p2 = 1

With ρ = λ/µ we find thatp1 = ρp0

p2 = ρ2p0

p0 =1

1 + ρ+ ρ2

Page 16: Notes on queuing theory - HiOA · Notes on queuing theory T. M. Jonassen torejo@hio.no Department of Computer Science Faculty of Technology, Art and Design ... queuing discipline

16 T. M. Jonassen

As ρ = 2/3 we obtain

p0 =1

1 + ρ+ ρ2=

1

1 + 23 + 4

5

=9

9 + 6 + 4=

9

19

Hencep1 = ρp0 =

2

3· 9

19=

6

19and p2 = ρp1 =

2

3· 6

19=

4

19

Hencep1 = ρp0 =

2

3· 9

19=

6

19and p2 = ρp1 =

2

3· 6

19=

4

19

Furthermore

E(L) = 0 · p0 + 1 · p1 + 2 · p2 = 0 · 9

19+ 1 · 6

19+ 2 · 4

19=

14

19≈ 0.736842

and

σ2(L) =

2∑n=0

(n− E(L))2pn =

(14

19

)29

19+

(1− 14

19

)26

19+

(2− 14

19

)24

19

=222

361≈ 0.614958

(5)

We haveE(S) =

1

λE(L) and E(W ) = E(S)− 1

µ

If we use minutes as time unit, we obtain

E(S) =1

λE(L) = 3 · 14

19=

42

19≈ 2.21053

andE(W ) = E(S)− 1

µ=

42

19− 2 =

4

19≈ 0.21053

The M/M/n modelThe M/M/n-model is similar to the M/M/1-model, and we can use the same strat-egy for finding the stationary solution. However, the computations are a little harder.However, I have carried out the computations in detail.

We consider a service where the incoming rate of objects is exponentially dis-tributed with mean value 1/λ, and the processing unit consists of n identical units inparallel each with exponentially distributed service times with mean 1/µ. We assumethat the incoming objects are served in order of arrival.

Page 17: Notes on queuing theory - HiOA · Notes on queuing theory T. M. Jonassen torejo@hio.no Department of Computer Science Faculty of Technology, Art and Design ... queuing discipline

Lecture note: Queues 17

As in the M/M/1-model we will assume that the average incoming amount ofwork is less than the system’s capacity. Hence we assume that

ρ =λ

nµ< 1

Note thatλ

µ= nρ < n

Just as for the M/M/1-model, we could find an infinite set of ordinary differentialequations giving us the time dependent solution of the distribution of the number ofobjects in the system, however, we will move directly to the equations for the stationarysolution for the distribution of the number of objects in the system.

Let pk denote the probability that there are k object total in the system, that is,k = kq + ks, where kq is the number of objects waiting in queue, and ks is the numberof objects in service. Clearly we must have

∞∑k=0

pk = 1

We note, that since the system has n parallel service channels we must be a littlecareful in when we set up the stationary equations. The flow diagram for the M/M/nmodel is given in figure 5. This diagram now gives us that the first n equations aregiven by

−λp0 + µp1 = 0

λp0 − (µ+ λ)p1 + 2µp2 = 0

λp1 − (2µ+ λ)p2 + 3µp3 = 0

...λpk−1 − (kµ+ λ)pk + (k + 1)µpk+1 = 0

where k = 1, 2, . . . , n− 1 in the last equation above, while for k ≥ n we find

λpk−1 − (nµ+ λ)pk + nµpk+1 = 0

0 1 n− 1 n k − 1 k

λ λ λ λ λ

µ 2µ nµ nµ nµ

Figure 5: The flow diagram for the M/M/n model.

This means that first n equations describes the situation where there will be free(idle) processing units in the system, while the equations for k ≥ n describe the sit-uation where there is no longer free processing units for new arriving objects, and wehave the possibility that there will be a queue of waiting objects.

Page 18: Notes on queuing theory - HiOA · Notes on queuing theory T. M. Jonassen torejo@hio.no Department of Computer Science Faculty of Technology, Art and Design ... queuing discipline

18 T. M. Jonassen

We will first find the solutions for pk, k = 0, 1, 2, . . . , n in terms of p0. Divisionby µ in these equations gives us

−λµp0 + p1 = 0

λ

µp0 − (1 +

λ

µ)p1 + 2p2 = 0

λ

µp1 − (2 +

λ

µ)p2 + 3p3 = 0

...λ

µpk−1 − (k +

λ

µ)pk + (k + 1)pk+1 = 0

for k = 1, 2, . . . , n− 1, and using that λ/µ = nρ we have

p1 = nρp0

2p2 = (1 + nρ)p1 − nρp0

3p3 = (2 + nρ)p2 − nρp1

...(k + 1)pk+1 = (k + nρ)pk − nρpk−1

We will now use the same approach as for the M/M/1-model, that is, solving theseequations by iteration. We have p1 = nρp0 from the first equation. Hence

2p2 = (1 + nρ)p1 − nρp0 = (1 + nρ)nρp0 − nρp0 = (nρ)2p0

so

p2 =(nρ)2p0

2=

(nρ)2p02!

The third equation gives, by using already known solutions for p1 and p2 that

3p3 = (2 + nρ)p2 − nρp1 = (2 + nρ)(nρ)2p0

2− (nρ)2p0 =

(nρ)3p02

so

p3 =(nρ)3p02 · 3

=(nρ)3p0

3!

By proceeding in this was, or using finite induction, we conclude that

pk =(nρ)kp0k!

for k = 0, 1, 2, . . . , n

The equations for k ≥ n are given by

λpk−1 − (nµ+ λ)pk + nµpk+1 = 0

Page 19: Notes on queuing theory - HiOA · Notes on queuing theory T. M. Jonassen torejo@hio.no Department of Computer Science Faculty of Technology, Art and Design ... queuing discipline

Lecture note: Queues 19

so with the above notation these equations read

pk+1 = (1 + ρ)pk − ρpk−1 for k = n, n+ 1, n+ 2, . . .

Note that

pn−1

pn=

(nρ)n−1p0

(n−1)!

(nρ)np0

n!

=11 · 1nρn

=1

ρso pn−1 =

pnρ

Hence, with k = n we find

pn+1 = (1 + ρ)pn − ρpn−1 = pn + ρpn − ρ

ρpn = ρpn

It turns out that we get simpler expressions if we express the solutions of

pk+1 = (1 + ρ)pk − ρpk−1 for k = n, n+ 1, n+ 2, . . .

in terms of pn. By reindexing the above set of equations by k = n + i, the equationstakes the form

pn+i+1 = (1 + ρ)pn+i − ρpn+i−1 where i = 0, 1, 2, 3, . . .

For i = 0 (k = n) we found above that

pn+1 = ρpn

For i = 1 we find

pn+2 = pn+1 + ρpn+1 − ρpn = ρpn + ρ2pn − ρpn = ρ2pn

and by induction we conclude that

pn+i = ρipn = ρi(nρ)n

n!p0 for i = 0, 1, 2, 3, . . .

The sum over all the probabilities is equal to 1 so we find by splitting the sum intwo parts that

1 =

∞∑k=0

pk =

n−1∑k=0

pk+

∞∑k=n

pk =

n−1∑k=0

pk+

∞∑i=0

pn+i =

n−1∑k=0

(nρ)k

k!p0+

∞∑i=0

ρi(nρ)n

n!p0

We find

1 = p0

(n−1∑k=0

(nρ)k

k!+

(nρ)n

n!

∞∑i=0

ρi

)

= p0

(n−1∑k=0

(nρ)k

k!+

(nρ)n

n!

1

1− ρ

)

Page 20: Notes on queuing theory - HiOA · Notes on queuing theory T. M. Jonassen torejo@hio.no Department of Computer Science Faculty of Technology, Art and Design ... queuing discipline

20 T. M. Jonassen

concluding that

p0 =

(n−1∑k=0

(nρ)k

k!+

(nρ)n

n!(1− ρ)

)−1

Hence we have derived the probability distribution for k objects in theM/M/n-model:

pk =(nρ)k

k!

(n−1∑k=0

(nρ)k

k!+

(nρ)n

n!(1− ρ)

)−1

for k = 0, 1, 2, . . . , n

pn+i = ρipn = ρi(nρ)n

n!

(n−1∑k=0

(nρ)k

k!+

(nρ)n

n!(1− ρ)

)−1

for i = 1, 2, 3, . . . (k > n)

Metrics for the M/M/n-model

We has split the sum of probabilities of pk into a finite, and an infinite part by

1 =

∞∑k=0

pk =

n−1∑k=0

pk +

∞∑k=n

pk

Here the last sum, the infinite one, can be interpreted as the probability PW of whenobjects has to wait in the system (by the PASTA property), that is

PW =∞∑

k=n

pk and 1− PW =n−1∑k=0

pk

We call the quantity PW the delay probability. We can find PW as follows:

PW =∞∑i=0

pn+1 =(nρ)n

n!p0

∞∑i=0

ρi =pn

1− ρ

=(nρ)n

n!

1

1− ρ

(n−1∑k=0

(nρ)k

k!+

(nρ)n

n!· 1

1− ρ

)−1

=(nρ)n

n!

1

1− ρ

(1∑n−1

k=0(nρ)k

k! + (nρ)n

n! · 11−ρ

)

=(nρ)n

n!

(1

(1− ρ)∑n−1

k=0(nρ)k

k! + (nρ)n

n!

)

=(nρ)n

n!

((1− ρ)

n−1∑k=0

(nρ)k

k!+

(nρ)n

n!

)−1

Page 21: Notes on queuing theory - HiOA · Notes on queuing theory T. M. Jonassen torejo@hio.no Department of Computer Science Faculty of Technology, Art and Design ... queuing discipline

Lecture note: Queues 21

Note then that we have the following two expressions for PW :

PW =pn

1− ρ

PW =(nρ)n

n!

((1− ρ)

n−1∑k=0

(nρ)k

k!+

(nρ)n

n!

)−1

We can use the above, and the formula for the mean of a geometrically distributedrandom variable, to find the mean queue length.

E(Lq) =∞∑i=0

ipn+i =∞∑i=0

iρipn = pn

∞∑i=0

iρi

=pn

1− ρ

∞∑i=0

i(1− ρ)ρi = PW

∞∑i=0

i(1− ρ)ρi

= PWρ

1− ρ

Little’s law on queue length and waiting time, E(Lq) = λE(W ), now gives a formulafor the mean waiting time:

E(W ) =1

λPW

ρ

1− ρ=

1

λPW

λnµ

1− ρ=

PW

nµ(1− ρ)

The following calculation gives us an alternative expression for E(W ):

E(W )− 1

nµE(Lq)

=PW

nµ(1− ρ)− 1

ρPW

1− ρ

=PW

nµ(1− ρ)(1− ρ) =

PW

Hence

E(W ) =PW

nµ+E(Lq)

The occupation rate per server is ρ = λ/nµ < 1, so we get the following expressionfor the mean number of objects in the system:

E(L) = E(Lq) + nρ = E(Lq) +λ

µ

Little’s law applied to the mean number of objects in the system and the mean

Page 22: Notes on queuing theory - HiOA · Notes on queuing theory T. M. Jonassen torejo@hio.no Department of Computer Science Faculty of Technology, Art and Design ... queuing discipline

22 T. M. Jonassen

sojourn time, E(L) = λE(S), gives

E(S) =1

λE(L) =

1

λ

(E(Lq) +

λ

µ

)=

1

λE(Lq) +

1

µ

= E(W ) +1

µ

as it should be, as the sojourn time is the sum of the waiting time and the service time.

To add up the results we have derived in this section we now have the following listof folmulas for the M/M/n-model:

PW =pn

1− ρ

PW =(nρ)n

n!

((1− ρ)

n−1∑k=0

(nρ)k

k!+

(nρ)n

n!

)−1

E(Lq) =ρPW

1− ρ

E(W ) =PW

nµ(1− ρ)

E(W ) =PW

nµ+E(Lq)

E(L) =ρPW

1− ρ+ nρ

E(S) =PW

nµ(1− ρ)+

1

µ

A computational formula for the delay probability PW

The terms (nρ)n/n! in the formulas for the delay probability PW , are likely for producenumerical problems in calculations. A well known trick to avoid this is to define thefunction ψ(n, x) where n is a non-negative integer and x > 0 is a real number. Letψ(0, x) = 1 and let

ψ(n, x) =xn

n!∑ni=0

xi

i!

Page 23: Notes on queuing theory - HiOA · Notes on queuing theory T. M. Jonassen torejo@hio.no Department of Computer Science Faculty of Technology, Art and Design ... queuing discipline

Lecture note: Queues 23

We can now rewrite this expression for ψ as follows:

ψ(n, x) =xn

n!∑n−1i=0

xi

i! +xn

n!

=

xn

n!∑n−1i=0

xi

i!

1 +xn

n!∑n−1i=0

xi

i!

=

xn · xn−1

(n−1)!∑n−2i=0

xi

i! +xn−1

(n−1)!

1 +xn · xn−1

(n−1)!∑n−2i=0

xi

i! +xn−1

(n−1)!

=xnψ(n− 1, x)

1 + xnψ(n− 1, x)

=xψ(n− 1, x)

n+ xψ(n− 1, x)

Hence we have the following simple recursion formula for ψ

ψ(n, x) =xψ(n− 1, x)

n+ xψ(n− 1, x)

We found the following expression for the delay probability PW :

PW =(nρ)n

n!

((1− ρ)

n−1∑k=0

(nρ)k

k!+

(nρ)n

n!

)−1

Rewriting this formula we find that

PW =(nρ)n

n!

(1− ρ)∑n−1

k=0(nρ)k

k! + (nρ)n

n!

=

nρn

(nρ)n−1

(n−1)!

(1− ρ)∑n−1

k=0(nρ)k

k! + nρn

(nρ)n−1

(n−1)!

=

ρ(nρ)n−1

(n−1)!∑n−1k=0

(nρ)k

k!

1− ρ+ ρ(nρ)n−1

(n−1)!∑n−1k=0

(nρ)k

k!

=ρψ(n− 1, nρ)

1− ρ+ ρψ(n− 1, nρ)

Hence we have the following formula for PW :

PW =ρψ(n− 1, nρ)

1− ρ+ ρψ(n− 1, nρ)

where we can compute ψ(n− 1, nρ) by the recursive formula

ψ(n, x) =xψ(n− 1, x)

n+ xψ(n− 1, x)

found above. It can be shown by techniques from numerical analysis that this recursionis numerically stable.

Example 4. We use the following Mathematica program to compute the functionψ(n, x):

Page 24: Notes on queuing theory - HiOA · Notes on queuing theory T. M. Jonassen torejo@hio.no Department of Computer Science Faculty of Technology, Art and Design ... queuing discipline

24 T. M. Jonassen

psi[0,x_]=1;psi[n_,x_]:=psi[n,x]=x*psi[n-1,x]/(n+x*psi[n-1,x]);

Note the construction in the beginning of line 2 of the program above. This will causeMathematica to build up a table of previous computed function values, and will speedup the computations considerable.

Example 5. The following example shows the numerical values for theM/M/n-modelmetrics, where both λ and µ are kept fixed, and only the number of processing units isincreases. In other words, one buys more of the same type of hardware.

n λ µ ρ E(L) E(S) E(Lq) E(W ) PW

4 10 2.51 0.996016 251.778 25.1778 247.794 24.7794 0.9911755 10 2.51 0.796813 6.13302 0.613302 2.14896 0.214896 0.5479846 10 2.51 0.664011 4.53917 0.453917 0.555107 0.0555107 0.2808847 10 2.51 0.569152 4.15961 0.415961 0.175543 0.0175543 0.1328868 10 2.51 0.498008 4.04149 0.404149 0.0574302 0.00574302 0.05788979 10 2.51 0.442674 4.0025 0.40025 0.0184395 0.00184395 0.023215410 10 2.51 0.398406 3.98975 0.398975 0.00568426 0.000568426 0.00858323

Example 6. The following example shows the numerical values for theM/M/n-modelmetrics, where both λ is kept fixed togeher with the number of processing units. Inother words, one buys newer and more expencive type of hardware.

n λ µ ρ E(L) E(S) E(Lq) E(W ) PW

4 10 2.55 0.980392 51.7642 5.17642 47.8426 4.78426 0.9568534 10 2.59 0.965251 29.5285 2.95285 25.6675 2.56675 0.9240314 10 2.63 0.95057 20.9683 2.09683 17.166 1.7166 0.892634 10 2.67 0.93633 16.4302 1.64302 12.6849 1.26849 0.8625754 10 2.71 0.922509 13.6162 1.36162 9.92612 0.992612 0.8337944 10 2.75 0.909091 11.6986 1.16986 8.06222 0.806222 0.8062224 10 2.79 0.896057 10.3066 1.03066 6.72239 0.672239 0.7797974 10 2.83 0.883392 9.24918 0.924918 5.71561 0.571561 0.7544614 10 2.87 0.87108 8.41783 0.841783 4.93351 0.493351 0.7301594 10 2.91 0.859107 7.74643 0.774643 4.31 0.431 0.7068414 10 2.95 0.847458 7.19237 0.719237 3.80254 0.380254 0.684457

Example 7. This example simply contains the complete Mathematica code to generatethe results in the two preceeding examples. I have used a 1-D input style.

psi[0,x_]=1;psi[n_,x_]:=psi[n,x]=x*psi[n-1,x]/(n+x*psi[n-1,x]);rho[n_,lambda_,mu_]:=lambda/(n*mu);pw[n_,lambda_,mu_]:=(rho[n,lambda,mu]

*psi[n-1,n*rho[n,lambda,mu]])/(1 -rho[n,lambda,mu]+

Page 25: Notes on queuing theory - HiOA · Notes on queuing theory T. M. Jonassen torejo@hio.no Department of Computer Science Faculty of Technology, Art and Design ... queuing discipline

Lecture note: Queues 25

rho[n,lambda,mu]*psi[n-1,n*rho[n,lambda,mu]]);lq[n_,lambda_,mu_]:=rho[n,lambda,mu]*pw[n,lambda,mu]/(1-rho[n,lambda,mu]);

w[n_,lambda_,mu_]:=pw[n,lambda,mu]/(n*mu*(1-rho[n,lambda,mu]));

l[n_,lambda_,mu_]:=lq[n,lambda,mu]+n*rho[n,lambda,mu];s[n_,lambda_,mu_]:=w[n,lambda,mu]+(1/mu);aa[n_,lambda_,mu_]:={n,lambda,mu,rho[n,lambda,mu],l[n,lambda,mu],s[n,lambda,mu],lq[n,lambda,mu],w[n,lambda,mu],pw[n,lambda,mu]};

and the two tables by

Table[aa[i,10,2.51],{i,4,10}]

and

Table[aa[4,10,2.31+0.2*i/5],{i,6,16}]