queues and Busy Cycle Analysis John C.S. Lui Department of Computer Science & Engineering The Chinese University of Hong Kong www.cse.cuhk.edu.hk/ cslui John C.S. Lui (CUHK) Computer Systems Performance Evaluation 1 / 36
Outline Outline 1 Renewal Theory 2 John C.S. Lui (CUHK) Computer Systems Performance Evaluation 2 / 36
Renewal Theory Another notation for transform Given a discrete r.v G with g i = Prob[ g = i] 1 G(Z ) = i=0 g iz i 2 E[Z G] = i=0 Z i Prob[ g = i] = i=0 Z i g i Therefore,E[Z G] = G(Z ) Given a continuous r.v X with f X (x) 1 F X (s) = x=0 f X (x)e sx dx 2 E[e s X ] = x=0 e sx f X (x)dx John C.S. Lui (CUHK) Computer Systems Performance Evaluation 4 / 36
Renewal Theory Residual Life A 1 A 2 A 3 A n-1 A n X... X 0 Y! 1! 2! 3! n-1! n time Interarrival time of bus is exponential w/ rate λ while hippie arrives at an arbitrary instant in time Question: How long must the hippie wait, on the average, till the bus comes along? John C.S. Lui (CUHK) Computer Systems Performance Evaluation 5 / 36
Renewal Theory Answer Answer 1 : Because the average interarrival time is 1 λ, therefore 1 2λ Answer 2 : Because of memoryless, it has to wait 1 λ General Result: Particularly, r 1 = x 2 2 x f X (x)dx = kxf (x)dx = f Y (y) = 1 F(y) xf (x)dx 0 F (s) = 1 F (s) r n = m 1 m n+1 (n + 1)m 1 0 xf (x) xf (x)dx John C.S. Lui (CUHK) Computer Systems Performance Evaluation 6 / 36
Renewal Theory Derivation P[x < X x + dx] = f X (x)dx = kxf (x)dx x=0 f X (x)dx = k x=0 xf (x)dx 1 = km 1 Therefore, f Y (y) =? f X (x) = 1 m 1 xf (x) P[Y y X = x] = y ( x ) ( ) dy xf (x) P[y < Y y + dy, x < X x + dx] = dx x m 1 John C.S. Lui (CUHK) Computer Systems Performance Evaluation 7 / 36
Renewal Theory continue: f Y (y)dy = = x=y x=y P[y < Y y + dy, x < X x + dx] ( dy x )(xf (x) m 1 )dx = 1 F(y) dy m 1 f Y (y) = 1 F(y) since f (y) = df(y) m 1 dy = 1 F (s) sm 1 John C.S. Lui (CUHK) Computer Systems Performance Evaluation 8 / 36
A(t) = 1 e λt t 0 a(t) = λe λt t 0 b(t) = general Describe the state [N(t), X o (t)] N(t): The no. of customers present at time t X o (t): Service time already received by the customer in service at time t (or remaining service time). Rather than using this approach, we use the method of the imbedded Markov Chain John C.S. Lui (CUHK) Computer Systems Performance Evaluation 10 / 36
Imbedded Markov Chain [N(t), X o (t)] Select the "departure" points, we therefore eliminate X o (t) Now N(t) is the no. of customers left behind by a departure customer. 1 For Poisson arrival: P k (t) = R k (t) for all time t. Therefore, p k = r k. 2 If in any system (even it s non-markovian) where N(t) makes discontinuous changes in size(plus or minus)one, then r k = d k = Prob[departure leaves k customers behind] Therefore, for, p k = d k = r k John C.S. Lui (CUHK) Computer Systems Performance Evaluation 11 / 36
α 1 α j-i+1 α 3 i-2 i-1 i α 2 i+1 i+2 j α 0 α k = Prob[k arrivals during the service of a customer] α k = P[ṽ = k] = 0 P = α 0 α 1 α 2 α 3 α 0 α 1 α 2 α 3 0 α 0 α 1 α 2 0 0 α 0 α 1 0 0 0 α 0.. P[ṽ = k x = x]b(x)dx =... 0 (λx) k e λx b(x)dx k! π = πp and π i = 1. Question: why not πq = 0, π i = 1? John C.S. Lui (CUHK) Computer Systems Performance Evaluation 12 / 36
The mean queue length We have two cases. Case 1: q n+1 = q n 1 + v n+1 for q n > 0 C n C n+1 q n q n+1 server t C n C n+1 queue v n+1 t C n C n+1 John C.S. Lui (CUHK) Computer Systems Performance Evaluation 13 / 36
Case 2: q n+1 = v n+1 for q n = 0 C n C n+1 q n =0 q n+1 server t C n C n+1 queue v n+1 t C n C n+1 { 1 for k = 1, 2,... Let k = 0 for k = 0 q n+1 = q n qn + v n+1 John C.S. Lui (CUHK) Computer Systems Performance Evaluation 14 / 36
E[q n+1 ] = E[q n ] E[ qn ] + E[v n+1 ] Take the limit as n, E[ q] = E[ q] E[ q ] + E[ṽ] We get, E[ q ] = E[ṽ] = average no. of arrivals in a service time On the other hand, E[ q ] = k P[ q = k] k=0 = 0 P[ q = 0] + 1 P[ q = 1] + = P[ q > 0] Therefore E[ q ] = P[ q > 0]. Since we are dealing with single server, it is also equal to P[busy system]=ρ = λ/mu = λ x. Therefore, E[ṽ] = ρ John C.S. Lui (CUHK) Computer Systems Performance Evaluation 15 / 36
Since we have q n+1 = q n qn + v n+1 q 2 n+1 = q 2 n + 2 q n + v 2 n+1 2q n qn + 2q n v n+1 2 qn v n+1 Note that : ( qn ) 2 = qn and q n qn = q n lim n E[q2 n+1 ] = lim n {E[q2 n] + E[ 2 q n ] + E[v 2 n+1 ] 2E[q n ] + 2E[q n v n+1 ] 2E[ qn v n+1 ]} 0 = E[ q ] + E[ṽ 2 ] 2E[ q] + 2E[ q]e[ṽ] 2E[ q ]E[ṽ] E[ q] = ρ + E[ṽ 2 ] E[ṽ] 2(1 ρ) Now the remaining question is how to find E[ṽ 2 ]. John C.S. Lui (CUHK) Computer Systems Performance Evaluation 16 / 36
Let V (Z ) = k=0 P[ṽ = k]z k V (Z ) = = = = k=0 0 0 0 0 (λx) k e λx b(x)dxz k k! ( ) e λx (λxz ) k b(x)dx k! k=0 e λx e λxz b(x)dx e (λ λz )x b(x)dx Look at B (s) = 0 e sx b(x)dx. Therefore, V (Z ) = B (λ λz ) John C.S. Lui (CUHK) Computer Systems Performance Evaluation 17 / 36
From this, we can get E[ṽ], E[ṽ 2 ],... dv (Z ) dz = db (λ λz ) dz dv (Z ) dz = db (λ λz ) d(λ λz ) = λ db (y) dy Z =1 = λ db (y) dy d(λ λz ) dz y=0 = +λ x = ρ John C.S. Lui (CUHK) Computer Systems Performance Evaluation 18 / 36
d 2 V (Z ) dz 2 = v 2 v, since V (Z ) = B (λ λz ) d 2 V (Z ) dz 2 = d (y) dz [ λdb dy ] = λ d 2 B (y) dy 2 d 2 V (Z ) dz 2 Z =1 = λ 2 db2 (y) dy 2 y=0 = λ 2 B (2) (0) dy dz Go back, since v 2 v = λ 2 x 2 v 2 = v + λ 2 x 2 E[ q] = ρ + E[ṽ 2 ] E[ṽ] 2(1 ρ) E[ q] = ρ + λ2 x 2 2(1 ρ) = ρ + (1 + ρ2 C2 b ) 2(1 ρ) This is the famous Pollaczek - Khinchin Mean Value Formula. John C.S. Lui (CUHK) Computer Systems Performance Evaluation 19 / 36
For M/M/1, b(x) = µe µx, x = 1 µ ; x 2 = 2 µ 2 q = ρ + λ2 x 2 2(1 ρ) = ρ + 2 λ2 µ 2 2(1 ρ) = ρ + 2 ρ2 2(1 ρ) ρ q = 1 ρ = N in M/M/1 For M/D/1, x = x; x 2 = x 2 q = ρ + ρ 2 1 2(1 ρ) = ρ 1 ρ ρ 2 2(1 ρ) It s less than M/M/1! For M/H 2 /1, let b(x) = 1 4 λe λx + 3 4 (2λ)e 2λx ; x = 5 8λ ; x 2 = 56 64λ 2 q = ρ + 56 64 2(1 ρ) where ρ = λ x = 5 ; q = 1.79 8 John C.S. Lui (CUHK) Computer Systems Performance Evaluation 20 / 36
Distribution of Number in the System q n+1 = q n qn + v n+1 Z q n+1 = Z qn q n +v n+1 E[Z q n+1 ] = E[Z qn q n +v n+1 ] = E[Z qn q n Z v n+1 ] Taking limit as n Q(Z ) = E[Z q q ] E[Z v ] = E[Z q q ]V (Z ) (1) E[Z q q ] = Z 0 0 Prob[q = 0] + Z k 1 Prob[q = k] k=1 = Z 0 Prob[q = 0] + 1 [Q(Z ) P[q = 0]] Z = Prob[q = 0] + 1 [Q(Z ) P[q = 0]] Z John C.S. Lui (CUHK) Computer Systems Performance Evaluation 21 / 36
Continue Putting them together, we have: Q(Z ) = V (Z )(Prob[q = 0] + 1 [Q(Z ) P[q = 0]]) Z But P[q = 0] = 1 ρ, we have: Q(Z ) = V (Z )[ (1 ρ)(1 1 Z ) 1 V (Z ) Z This is the famous P-K Transform equation. ] = B (1 ρ)(1 Z ) (λ λz )[ B (λ λz ) Z ] John C.S. Lui (CUHK) Computer Systems Performance Evaluation 22 / 36
Example Q(Z ) = B (1 ρ)(1 Z ) (λ λz ) B (λ λz ) Z For M/M/1 : B (s) = µ s + µ µ (1 ρ)(1 Z ) Q(Z ) = ( ) µ λ λz + µ [ (λ λz +µ) ] Z = 1 ρ 1 ρz = (1 ρ) 1 ρz Therefore, This is the same as P[ q = k] = (1 ρ)ρ k k 0 P[Ñ = k] = (1 ρ)ρk John C.S. Lui (CUHK) Computer Systems Performance Evaluation 23 / 36
Continue Q(Z ) = B (1 ρ)(1 Z ) (λ λz ) B (λ λz ) Z For M/H 2 /1 : B (s) = 1 λ 4 s + λ + 3 2λ 4 s + 2λ = 7λs + 8λ 2 4(s + λ)(s + 2λ) (1 ρ)(1 z)[8 + 7(1 z)] Q(Z ) = 8 + 7(1 z) 4z(2 z)(3 z) 7 (1 ρ)[1 15 = z] [ ] 1 3 4 [1 2 5 z][1 2 = (1 ρ) 3z] 1 2 5 z + 4 1 2 3 z Where ρ = λ x = 5 8 P k = Prob[ q = k] = 3 32 ( ) 2 k + 9 5 32 ( ) 2 k k = 0, 1, 2, 3 John C.S. Lui (CUHK) Computer Systems Performance Evaluation 24 / 36
We know q n+1 = q n qn + v n+1. From the r.v. equation, we derived: q = ρ + λ2 x 2 2(1 ρ) = ρ + ρ2 (1 + C2 b ) 2(1 ρ), (1) where C 2 b = σ2 b x 2 Q(Z ) = V (Z ) (1 ρ)(1 1 Z ) 1 V (Z ) Z = B (λ λz )(1 ρ)(1 Z ) B (λ λz ) Z because V (Z ) = B (λ λz ) Q(Z ) = S (λ λz ) = B (1 ρ)(1 Z ) (λ λz ) B (λ λz ) Z W s(1 ρ) (s) = s λ + λb (s) (2) (3) John C.S. Lui (CUHK) Computer Systems Performance Evaluation 25 / 36
Distribution of Waiting Time C n x n C n C n x n w n C n C n v n C n q n V (z) = B (λ λz) Q(z) = S (λ λz) S (λ λz ) = B (1 ρ)(1 Z ) (λ λz ) B (λ λz ) Z Let s = λ λz, then z = 1 s λ S (s) = B s(1 ρ) (s) s λ + λb (s) What is W (s)? John C.S. Lui (CUHK) Computer Systems Performance Evaluation 26 / 36
For M/M/1, S (s) = B s(1 ρ) (s) s λ + λb (s) µ = [ s + µ ][ s(1 ρ) s λ + λ µ ] s(1 ρ) = [µ][ s 2 + sµ sλ ] = = sµ(1 ρ) s[s + µ λ] µ(1 ρ) s + µ(1 ρ) s+µ = µ(1 ρ) s + µ λ s(y) = µ(1 ρ)e µ(1 ρ)y y 0 S(y) = 1 e µ(1 ρ)y y 0 B (s) = µ s + µ John C.S. Lui (CUHK) Computer Systems Performance Evaluation 27 / 36
W (s) = = s(1 ρ) s λ + λ µ = s+µ s(1 ρ)(s + µ) s[s + µ λ] = (1 ρ) + s(1 ρ)(s + µ) s 2 + sµ sλ = (1 ρ)(s + µ) s + µ λ λ(1 ρ) λ(1 ρ) = (1 ρ) + s + µ λ s + µ(1 ρ) w(y) = (1 ρ)µ 0 (y) + λ(1 ρ)e µ(1 ρ)y y 0 W (y) = 1 ρe µ(1 ρ)y y 0 1 1 ρ John C.S. Lui (CUHK) Computer Systems Performance Evaluation 28 / 36
Let U(t) =the unfinished work in the system at time t U(t) x 1 x 2 x 3 Y 1 I 1 x 4 x 5 x 6 Y 2 I 2 Y 3 C 1 C 2 C 3 C 4 C 5 C 6 S Q C 1 C 2 C 3 C 4 C 5 C 6 C 1 C 2 C 3 C 4 C 5 C 6 Y i are the i th busy period; I i is the i th idle period. The function U(t) is INDEPENDENT of the order of service!!! The only requirement to this statement hold is the server remains busy where there is job. John C.S. Lui (CUHK) Computer Systems Performance Evaluation 29 / 36
For A(t) = P[t n t] = 1 e λt t 0 B (x) P[X n x] Let F(y) = P[I n y] = idle-period distribution G(y) = P[Y n y] = busy-period distribution F(y) = 1 e λt t 0 G(y) is not that trivial! Well, thanks to Takacs, he came to the rescue. John C.S. Lui (CUHK) Computer Systems Performance Evaluation 30 / 36
The Busy Period The busy period is independent of order of service Each sub-busy period behaves statistically in a fashion identical to the major busy period. John C.S. Lui (CUHK) Computer Systems Performance Evaluation 31 / 36
The duration of busy period Y, is the sum of 1 + ṽ random variables where Y = x 1 + Xṽ + + X 1 where x 1 is the service time of C 1, Xṽ is the (ṽ + 1) th sub-busy period and ṽ is the r.v. of the number of arrival during the service of C 1. Let G(y) = P[Y y] and G (s) = 0 e sy dg(y) = E[e sy ] E[e sy x 1 = x, ṽ = k] = E[e s(x+x k+1+x k + +X 2 ) ] = E[e sx ]E[e sx k+1 ]E[e sx k ] E[e sx 2 ] = e sx [G (s)] k E[e sy x 1 = x] = E[e sy x 1 = x, ṽ = k]p[ṽ = k] k=0 John C.S. Lui (CUHK) Computer Systems Performance Evaluation 32 / 36
Therefore, we have E[e sy x 1 = x] = E[e sy ] = G (s) = k=0 e sx [G (s)] k (λx)k e λx k! = e x[s+λ λg (s)] = 0 0 E[e sy x 1 = x]db(x) e x[s+λ λg (s)] db(x) G (s) = B [s + λ λg (s)] John C.S. Lui (CUHK) Computer Systems Performance Evaluation 33 / 36
G (s) = B [s + λ λg (s)] Since, g k = E[Y k ] = ( 1) k G (k) (0) and x k = ( 1) k B (k) (0) g 1 = ( 1)G (1) (0) = B (1) (0) d ds [s + λ λg (s)] s=0 = B (1) (0)[1 λg (1) (0)] g 1 = x(1 + λg 1 ) Therefore g 1 = x 1 p where ρ = λ x The average length of busy period for is equal to the average time a customer spends in an M/M/1 system g 2 = G (2) (s) s=0 = d ds [B (1) [s + λ λg (s)][1 λg (1) (s)] s=0 = B (2) (0)[1 λg (1) (0)] 2 + B (1) (0)[ λg (2) (0)] = x 2 (1 ρ) 3 John C.S. Lui (CUHK) Computer Systems Performance Evaluation 34 / 36
The number of customers served in a busy period Let N bp = r.v. of no. of customers served in a busy period. f n = Prob[N bp = n] F(Z ) = E[Z N bp ] = f n Z n n=1 E[Z N bp ṽ = k] = E[Z 1+M k +M k 1 + +M 1 ] (where M i = no. of customers served in the i th sub-busy period) E[Z N bp ṽ = k] = E[Z ]E[Z M k ] E[Z M 1 ] = E[Z ](E[Z M i ]) k = Z [F(Z )] k John C.S. Lui (CUHK) Computer Systems Performance Evaluation 35 / 36
Continue F(Z ) = = E[Z N bp ṽ = k]p[ṽ = k] k=0 Z [F(Z )] k P[ṽ = k] k=0 = ZV [F(Z )] F(Z ) = ZB (λ λf(z )) John C.S. Lui (CUHK) Computer Systems Performance Evaluation 36 / 36