MAS programmes: Stochastic Models and Forecasting

7 Queues and the M/G/1 model

7.1 A classification of queueing models We shall consider a class of queueing models, in which it is assumed that there is a single queue plus server and that, unless otherwise specified, customers are dealt with on a first come first served basis. The queueing process may be classified according to

1. the distribution of customer inter-arrival times, usually assumed i.i.d. — customers arrive according to a renewal process;

2. the distribution of service times, assumed i.i.d.;

3. the number of servers, assumed to work in parallel.

In Markovian queueing models, the inter-arrival times and service times are exponentially distributed. When either the inter-arrival times or the service times are not exponentially distributed then the corresponding model is not a continuous time . A queueing model of the type being considered here may be represented in the following way, using what is known as Kendall’s notation:

inter-arrival time distribution/service time distribution/number of servers where for the inter-arrival and the service time distributions the following notation is used: M for an (Markovian, memoryless) Ek for a gamma distribution of order k (ν = k, integer, Erlangian) D of fixed length (deterministic) GI or G for an arbitrary distribution (general independent, general)

The queueing systems that we have considered previously, using this notation, are M/M/1 (the simple single-server queueing system), M/M/c, M/M/∞ (the immigration-death process) and M/G/∞ (an infinite server queueing system with Poisson arrivals). For the most general form of the model being considered here, the GI/G/c, the traffic intensity ρ is defined by mean service time ρ = . c × mean customer inter-arrival time Using the results of , ρ may also be characterized as the ratio of the average rate at which customers arrive to the average rate at which customers can be dealt with. The system will settle down to equilibrium if and only if ρ < 1.

1 7.2 The embedded Markov chain for the M/G/1 model Non-Markov models are much harder to analyze than Markov ones. We shall give an introduc- tion to the analysis of the M/G/1 model, which is relatively easy to deal with. It is a model where it is still assumed that customers arrive according to a Poisson process, but the assump- tion of exponentially distributed service times is dropped. The assumption of exponentially distributed service times is often clearly far from the truth, whereas the assumption of Poisson arrivals may more often be a plausible approximation to what actually occurs. Let λ be the customer arrival rate and F the distribution function of the service time distribution. Instead of working directly with {X(t): t ≥ 0}, a right continuous process, where X(t) is the number of customers in the system at time t, we shall restrict attention to those instants of time at which customers depart, their service times just having been completed. Let Q0 be the number of customers in the system at time 0, the customers being labelled 1, 2,...,Q0, in the order of their position within the system. If Q0 6= 0, assume that the first customer’s service time is just starting. Further customers who arrive after time 0 are labelled Q0 + 1,Q0 + 2,..., in order of arrival. Define Qn, n ≥ 1, to be the number of customers in the system just after the service of the n-th customer is completed. Let Rn, n ≥ 1 denote the number of customers who arrive during the service time of the n-th customer. For n ≥ 0,   Qn − 1 + Rn+1 if Qn ≥ 1 Q = , (1) n+1  Rn+1 if Qn = 0 where the −1 on the right-hand side of Equation (1) arises from the departure of the (n+1)-th customer.

X(t) 6 3

2 t t

1 t t

0 t - t

Qn: 2 1 0 1 2 Rn: 0 0 1 2 n : 0 1 2 3 4

The distribution of Rn+1 is independent of the history of the process before the start of the (n + 1)-th customer’s service, and, in particular, is independent of Q0,Q1,...,Qn. Hence

2 {Qn} constitutes a Markov chain in discrete time, the Markov chain embedded in the queueing process. We study the behaviour of the queueing process through the embedded Markov chain. Note also that {Rn} is a sequence of i.i.d. r.v.s.

Conditional upon the service time Y of the (n + 1)-th customer being y, the number of customers who arrive during its service time has a with parameter λy. Thus (λy)r P(R = r|Y = y) = e−λy r ≥ 0. n+1 r! But Y has the d.f. F , so that, unconditionally, the distribution of the number of customer arrivals during the service time is given by

Z ∞ r −λy (λy) P(Rn+1 = r) = e dF (y) 0 r!

≡ kr r ≥ 0, (2) say. Using Equations (1) and (2), we can write down the transition matrix P for the Markov chain {Qn}. The state space is the set of all non-negative integers, and the transition proba- bilities are: p0j = P(Rn+1 = j) = kj j ≥ 0, and, for i ≥ 1, ½ 0 j < i − 1 pij = . P(Rn+1 = j − i + 1) = kj−i+1 j ≥ i − 1 Thus   k0 k1 k2 k3 ...    k0 k1 k2 k3 ...    P =  0 k0 k1 k2 ...  .    0 0 k0 k1 ...  ......

{Qn} is an irreducible, aperiodic Markov chain. If µS is the mean of the service time distribu- tion, the traffic intensity ρ is given by µ ρ = S = µ λ. 1/λ S We shall show analytically that a stationary distribution exists if and only if ρ < 1.

7.3 The stationary distribution for the embedded Markov chain

The stationary distribution for {Qn} is denoted by {πj : j ≥ 0}. If it exists, the stationary distribution is the unique solution of the equations X∞ πj = πipij j ≥ 0, i=0

3 which in the present case reduce to Xj+1 πj = π0kj + πikj−i+1 j ≥ 0, (3) i=1 together with the normalization condition X∞ πj = 1. j=0 Introduce the p.g.f.s X∞ j Π(z) = πjz , j=0 X∞ j K(z) = kjz . j=0

j (The latter is the p.g.f. of Rn+1.) Multiplying Equation (3) by z and summing over j, X∞ Xj+1 j Π(z) = π0K(z) + z πikj−i+1 j=0 i=1 X∞ X∞ i j−i = π0K(z) + πiz kj−i+1z i=1 j=i−1 K(z) = π K(z) + (Π(z) − π ) . 0 0 z Rearranging this equation, we obtain π (1 − z)K(z) Π(z) = 0 . (4) K(z) − z

P∞ To obtain the value of π0, we use the normalization condition j=0 πj = 1, which implies that Π(1) = 1. At the same time, we shall obtain an expression for the mean µQ of the stationary 0 distribution, using the fact that µQ = Π (1). Writing z = 1 − h in Equation (4) and expanding in powers of h, π h[1 − K0(1)h + o(h)] 1 − µ h + o(h) = 0 Q 0 1 00 2 2 1 − K (1)h + 2 K (1)h + o(h ) − 1 + h · ¸ π K00(1) = 0 1 − K0(1)h − h + o(h) . (5) 1 − K0(1) 2[1 − K0(1)] Equating constant terms and coefficients of h in Equation (5) we find that

0 π0 = 1 − K (1) (6)

4 and K00(1) µ = K0(1) + . (7) Q 2[1 − K0(1)] Now £ ¤ K(z) = E zRn+1 £ £ ¤¤ = E E zRn+1 |Y = E[eλY (z−1)] = f ∗(λ(1 − z)), (8) where f ∗ is the of the service time distribution. Differentiating Equation (8), K0(z) = −λf ∗0(λ(1 − z)), and, setting z = 1, we obtain

0 ∗0 K (1) = −λf (0) = λµS = ρ, (9) which is the mean number of customer arrivals during a service time and also the traffic intensity. Differentiating Equation (8) a second time, we obtain K00(z) = λ2f ∗00(λ(1 − z)), and, setting z = 1, 00 2 ∗00 2 2 2 2 2 K (1) = λ f (0) = λ (µS + σS) = ρ (1 + CS), (10) 2 where σS and CS are the variance and coefficient of variation of the service time distribution, respectively, CS = σS/µS. Substituting from Equation (9) into Equation (6), we obtain

π0 = 1 − ρ. (11)

For π0 to be a probability and for Equation (4) properly to specify a probability distribution we must have π0 > 0. Hence a stationary distribution exists for {Qn} if and only if ρ < 1. In equilibrium, the probability that a departing customer leaves the queue empty is 1 − ρ. Substituting from Equations (8) and (11) into Equation (4), we obtain the p.g.f. of the stationary distribution, (1 − ρ)(1 − z)f ∗(λ(1 − z)) Π(z) = . (12) f ∗(λ(1 − z)) − z Substituting from Equations (9) and (10) into Equation (7), we obtain an expression for the mean of the stationary distribution: ρ2(1 + C2) µ = ρ + S . (13) Q 2(1 − ρ)

• Recall that the stationary distribution {πj} is the stationary distribution for the em- bedded Markov chain that represents numbers of customers left behind in the system by departing customers. It turns out that this distribution is also an equilibrium distribution for the queueing process {X(t): t ≥ 0}, i.e., as t → ∞,

P(X(t) = j) → πj j ≥ 0. This same distribution is also the equilibrium distribution for the number of customers found ahead of them in the system by arriving customers.

5 7.4 The sojourn time distribution and the Pollaczek-Khinchin for- mulae

Next we consider the distribution of a customer’s sojourn time in equilibrium. If Wn is the n-th customer’s sojourn time then Qn is the number of customers who arrive during this sojourn time. Since customers arrive in a Poisson process with rate λ, using the same kind of argument that was used to derive Equation (8), we obtain £ ¤ Π(z) = E zQn £ £ ¤¤ Qn = E E z |Wn = E[eλWn(z−1)] = W ∗(λ(1 − z)), (14) where W ∗ is the Laplace transform of a customer’s sojourn time in equilibrium. Substituting from Equation (12) into Equation (14) and putting s = λ(1 − z), we obtain

(1 − ρ)sf ∗(s) W ∗(s) = . (15) λf ∗(s) − λ + s

We may find an expression for a customer’s mean sojourn time in equilibrium, µW , by noting that E[Qn] = E[E[Qn|Wn]] = E[λWn] = λE[Wn], so that, in equilibrium, µQ = λµW , which is essentially a restatement of Little’s Theorem as applied to the M/G/1 queue. Substi- tuting into Equation (13), we find that · ¸ 1 ρ2(1 + C2) µ = ρ + S . W λ 2(1 − ρ)

Equivalently, · ¸ ρ(1 + C2) µ = µ 1 + S . (16) W S 2(1 − ρ) Equations (13) and (16) constitute the Pollaczek-Khinchin formulae. Note how the mean sojourn time depends not only on the mean service time but also on the coefficient of variation of the service time distribution — the mean sojourn time can be reduced by reducing the variability in the service times, even if the mean service time remains unchanged.

We have obtained the Pollaczek-Khinchin formulae in a rigorous way, but an alternative, heuristic derivation of the formula is helpful in providing insight into how the formula arises. Assume the system is in equilibrium and let W denote the sojourn time of an arriving customer. If there are no customers in the system ahead of the arriving customer then his expected sojourn time is equal to its expected service time, µS. If there are j customers in the system ahead of the arriving customer, where j ≥ 1, then the expected sojourn time is the

6 sum of the expected residual service time of the customer currently being served plus the sum of j further expected service times, including that of the arriving customer. Now we assume that the expected residual service time of the customer currently being served is equal to the expected excess life at a randomly chosen time t of the item currently in use in a renewal process whose lifetime distribution is the same as the service time distribution for our queue. From the results of Section 5.6, the expected excess life is given by 1 µ (1 + C2) . 2 S S Thus   µS j = 0 E[W |j] = .  1 2 µSj + 2 µS(1 + CS) j ≥ 1 Hence, unconditionally, X∞ µW = E[W |j]πj j=0 X∞ 1 = µ jπ + π µ + (1 − π ) µ (1 + C2) S j 0 S 0 2 S S j=0 ρ = µ µ + (1 − ρ)µ + µ (1 + C2) . S Q S 2 S S

Now by Little’s Theorem, µQ = λµW . Hence, substituting for µQ in the above equation, and recalling that µSλ = ρ, we obtain ρ µ = ρµ + (1 − ρ)µ + µ (1 + C2) , W W S 2 S S which simplifies to the Pollaczek-Khinchin formula of equation (16).

7.5 The busy period distribution The same argument that was used in Section 6.4 to find the server’s busy period distribution for the simple M/M/1 queueing system can be extended to the more general case of the M/G/1 queueing system, simply replacing the exponential service time distribution by a more general one with arbitrary distribution function F . The length B of the busy period initiated by an arriving customer is the sum of the first service time Y and the lengths of the busy periods generated by all the customers who arrive during the first service time. Let the r.v. M denote the number of customers who arrive during the first service time. Let b∗(s) denote the Laplace transform of B. The Laplace transform of B conditional upon the values of M and Y is given by

E[e−sB|M = m, Y = y] = e−sy[b∗(s)]m .

7 Hence, unconditionally, b∗(s) = E[e−sB] Z ∞ = E[e−sB|Y = y)] dF (y) 0 Z ∞ X∞ = E[e−sB|M = m, Y = y]P(M = m|Y = y) dF (y) 0 m=0 Z ∞ X∞ (λy)m = e−sy[b∗(s)]me−λy dF (y) m! 0 m=0 Z ∞ = e−(λ+s)yeλyb∗(s)dF (y) 0 Z ∞ = e−(λ+s−λb∗(s))ydF (y) 0

= f ∗(λ + s − λb∗(s)) . Thus b∗(s) satisfies the equation b∗(s) = f ∗(λ + s − λb∗(s)) . (17) Differentiating Equation (17) we obtain b∗0(s) = f ∗0(λ + s − λb∗(s)) (1 − λb∗0(s)) . (18) Setting s = 0 in Equation (18) we obtain

−E[B] = −µS(1 + λE[B]) , so that µ µ E[B] = S = S . 1 − µSλ 1 − ρ Differentiating Equation (18), b∗00(s) = f ∗00(λ + s − λb∗(s)) (1 − λb∗0(s))2 − f ∗0(λ + s − λb∗(s)) λb∗00(s) , and setting s = 0, 2 2 2 2 2 E[B ] = (µS + σS) (1 + λE[B]) + µSλE[B ] , from which it follows that µ2 + σ2 E[B2] = S S . (1 − ρ)3 Hence µ2 + σ2 µ2 ρµ2 + σ2 var(B) = S S − S = S S (1 − ρ)3 (1 − ρ)2 (1 − ρ)3 and ρ + C2 C2 = S . B 1 − ρ 2 As for the M/M/1 queueing system, we see that the value of CB explodes as ρ ↑ 1.

8