ORF Electronic Commerce Spring 2009 April 15, 2009 Week 10 Capacity Analysis Deterministic Model –Assume: each HTTP request takes T r (request time) –and requests arrive at a know known time sequence: A s –What is service time per request, T s No conflicts: N(t) t First request 2nd request T r = 1/2 As: 0, 1, 2, 3, … (no conflicts) T s = 1/2
ORF Electronic Commerce Spring 2009 April 15, 2009 Week 10 Sequenced with conflict: Round Robin: –Reqest 1 arrives at 0, works ‘till 0.25., waits ‘till.5 works ‘till.75 then ends –Reqest 2 arrives at.25, works ‘till 0.5., waits ‘till.75 works ‘till 1.0 then ends T s = ( )/2 = 6/8 First-come-first-serve T r = 1/2 A s : 0,.25, 1., 1.25,… (same # requests, sequenced differently) T s = ( )/2 = 5/8 First request starts N(t) t 2nd request starts Round Robin
ORF Electronic Commerce Spring 2009 April 15, 2009 Week 10 Observations If server is handling a single page, then deterministic service times is reasonable, otherwise NOT The long term behavior depends on the arrival sequence, A s, AND the service rate, T s F-C-F-S is a lower bound on the round robin
ORF Electronic Commerce Spring 2009 April 15, 2009 Week 10 Probabilistic Model (F-C-F-S) Let inter arrival time and the service times be : –independent, identically distributed (iid) random variables having an exponential distribution (denoted by M ) –a r.v. X has an exponential density iff: f(x) = e - x x > 0 = 0 x < 0 So P rob { X 0 P rob { X > x } = e - x x > 0 E(X) = 1/ var(X) = 1/
ORF Electronic Commerce Spring 2009 April 15, 2009 Week 10 Assume server has been running for a while and reached steady state In steady state (prob. of being in state j, (j waiting to be served)) : P j j = P j+1 j+1 or P j+1 = P j ( j / j+1 ) (recursion relationship) Specifically: P 1 = ( 0 / 1 ) P 0 P 2 = ( 1 / 2 ) P 1 = ( 1 / 2 ) ( 0 / 1 ) P 0 … P n+1 = ( n / n+1 ) P n = (( n n )/ ( n+1 n... 1 )) P 0 Let’s let: C n = ( n-1 n )/ ( n n-1... 1 ), n = 1, 2, … Then the Steady State Probabilities are P n = C n P 0, n = 1, 2, … Arrival Rates Service rates States 12nn n 1 22 11 n+1
ORF Electronic Commerce Spring 2009 April 15, 2009 Week 10 What about P 0 ? –Since n P n = 1, then n C n P 0 = 1 P 0 + n C n P 0 = 1 P 0 [1+ n C n ] = 1 P 0 = 1 / [1+ n C n ] Now, the number of requests in the system, L L = 1 P 1 +2 P 2 +3 P = n (n P n ) Then the expected waiting time (likely time to be served),W = L / average arrival time
ORF Electronic Commerce Spring 2009 April 15, 2009 Week 10 Simple case: M/M/1/FCFS/ / Now suppose n = n = n = 1,2, 3, … then C n = ( n / n ) = ( ) n n = 1,2, 3, … let thenP 0 = 1 / (1 + n n ) = 1 / n n ) Now recall n x n = (1- x n+1 ) / (1- x ) for any x and if |x| < 1 n x n = 1/ (1- x ) We need to have or the system will blow up! So Thus P 0 = 1 / (1 / ( 1 and P n = n P 0 = n ( 1 n = 1,2, 3, …
ORF Electronic Commerce Spring 2009 April 15, 2009 Week 10 What about L (expected # of requests in queuing system) ? L = n n P n = n n (1 ) n = (1 ) n n n Now a little trick: Observe that n n = n n-1 So L = (1 ) n n n-1 Why bother? Because n n-1 should be familiar. In particular d/d ( n ) = n n-1 Thus L = (1 ) n d/d ( n ) = (1 ) d/d ( n ( n ) ) = (1 ) d/d ( n ( n ) ) but d/d ( n inf ( n ) is a geometric series = (1 ) d/d (1 ) -1, but d/d (1 ) -1 = -1(1 ) -2 ( -1 ) SoL = (1 ) -1 and we can show L = ( ) -1 and expected time in system W = L / = ( ) = ( ) -1
ORF Electronic Commerce Spring 2009 April 15, 2009 Week 10 More of M/M/1/FCFS/ / Queues L q = expected number of customers in line = 0 P 0 + n ( n 1) P n = n ( n P n ) - n ( P n ) = L P 0 ) = L = 2 ( )) L s = expected number of customers in service = 0 P 0 + n 1 P n = 1 - P 0 = 1 ) = = W q = expected time of customer spends in line = L q / = ( )) W s = expected time of customer spends in service = L s / =
ORF Electronic Commerce Spring 2009 April 15, 2009 Week 10 What about multiple processors: C n = ( n -1 n )/ ( n n-1... 1 ), n = 1, 2, … We again let n = for every n Now assume that there are s processors. So when n < s we have n = n and when n < s we have n = s So C n = n / ( n n-1... 1 ) we has s terms of n and n-s terms of s Hence C n = n / (n! n ) n < s = n / (s!)(s n-s ) n ) n > s If < s as before we can show : P n = 1/ ( n 0, s -1 {(1 / n! ) ( / ) n + (1 / s! ) ( / ) s )(1 - ( / (s )))}
ORF Electronic Commerce Spring 2009 April 15, 2009 Week 10 Finally: P n = P 0 ( n (n!) n < s = P 0 ( n ( (s!) s n-s ) n > s L = P 0 ( s ( s ) ( s! ((1- s ) 2 )) + W = P 0 ( s ( s ) (s!) (1- ( s ) 2 + ( 1 + ) Where L= s = # processors = arrival rates = processing rates
ORF Electronic Commerce Spring 2009 April 15, 2009 Week 10 Realistic Server Performance Consider one server connected to the internet Arrivals Departures Initial processing “Server” BrowserInternet Model each as a single server queue
ORF Electronic Commerce Spring 2009 April 15, 2009 Week 10 Realistic Server Performance, cont. Assume: –File sizes are exponentially distributed –Service rate of browser and Internet are exponentially distributed Parameters: –Arrival rate –Mean file size (5275 bytes) –Initialization time (independent of size) Server (T 1 = 1.5 Mbit/s, T 3 = 6Mbit/s ) Client (700Kbit/s) Arrivals Departures Initial processing “Server” BrowserInternet p 1-p Response Time Arrival Rate 35/sec
ORF Electronic Commerce Spring 2009 April 15, 2009 Week 10 More Complicated Model Load balancing strategies (above not very smart) Arrivals Departures Initial processing “Server” BrowserInternet p 1-p “Server” q 1-q