Midterm Exam Review - National University of …Midterm Exam Review Richard T. B. Ma School of...

Preview:

Citation preview

Midterm Exam Review

Richard T. B. Ma

School of Computing

National University of Singapore

CS 5229 (2012): Advanced Compute Networks

Mark Distribution Comparison

0

0.05

0.1

0.15

0.2

0.25

0.3

0.35

0-9 10--19 20-29 30-39 40-49 50-59 60-69 70-79

Last Year (mean=32)

This Year (mean=40)

Last Year’s Grade Distribution

0

0.05

0.1

0.15

0.2

0.25

A+ A A- B+ B B- C+ C D

Last Year's

Grade

Distribution

Problem 1A

SoC admits 40 students in the PhD program every year. On average, SoC has 160 students at any time. Suppose 20% of them will eventually stay only 2 years and graduate with a master’s degree. The remaining 80% will graduate with a PhD degree. For this 80%, what is the average number of years they expect to spend in SoC?

𝜆 = 40, 𝐿 = 160; Little’s Law ⇒ E 𝑊 =𝐿

𝜆= 4 (𝑦𝑟𝑠)

E 𝑊 = 20% ∗ 2 + 80% ∗ 𝑥 = 4 ⇒ 𝑥 = 4.5 (𝑦𝑟𝑠)

E 𝑊 = E 𝑊|𝑊 = 2 P 𝑊 = 2 + E 𝑊|𝑊 ≠ 2 P 𝑊 ≠ 2

Problem 1B

Suppose the inter-arrival times of the A1 buses are i.i.d. random variable 𝑇 (minutes) with P 𝑇 = 5 = 0.25 and P 𝑇 = 10 = 0.75. If you arrive at a random time, what is the probability that you need to wait for longer than 7 minutes?

Illustration: Deterministic Case

Often, we use 𝑇𝑒 ≝ 𝑅 to denote the equilibrium inter-arrival time

P(𝑇𝑒 > 𝑎) = P(𝑅 > 𝑎) = 𝜆E 𝑇 − 𝑎 +

Suppose 𝑇𝑖 = 𝐴 for all 𝑖 some constant 𝐴

P 𝑇𝑒 > 𝑎 = 𝜆E 𝑇 − 𝑎 + =𝐴 − 𝑎 +

𝐴

𝐴 − 𝑎 𝑎 𝒕𝒊 𝒕𝒊+𝟏

Problem 1B

Suppose the inter-arrival times of the A1 buses are i.i.d. random variable 𝑇 (minutes) with P 𝑇 = 5 = 0.25 and P 𝑇 = 10 = 0.75. If you arrive at a random time, what is the probability that you need to wait for longer than 7 minutes?

P 𝑇𝑒 > 𝑎 = 𝜆E 𝑇 − 𝑎 +

or P 𝑇𝑒 > 7 = 𝜆E 𝑇 − 7 +

RCL : Applications

𝑅′ 𝑡 = −1; 𝑅 𝑡𝑖− − 𝑅 𝑡𝑖

+ = −𝑇𝑖

By RCL, (if {𝑇𝑖: 𝑖 = 1, ⋯ } are i.i.d. r.v.s as 𝑇)

𝑋′ = −1 = 𝜆𝐽 = 𝜆 lim𝑛→∞

1

𝑛 −𝑇𝑖

𝑛

𝑖=1= −𝜆E 𝑇

Average inter-arrival time is 𝐄 𝑻 =𝟏

𝝀

𝒙 𝒕 = 𝑹(𝒕)

𝑻𝟏 𝑻𝟐 𝑻𝟑 𝑻𝟒 𝑻𝟓 Time 𝑡

Problem 1B

Suppose the inter-arrival times of the A1 buses are i.i.d. random variable 𝑇 (minutes) with P 𝑇 = 5 = 0.25 and P 𝑇 = 10 = 0.75. If you arrive at a random time, what is the probability that you need to wait for longer than 7 minutes?

P 𝑇𝑒 > 7 = 𝜆E 𝑇 − 7 + =E 𝑇 − 7 +

E 𝑇= 9/35

E 𝑇 = 5P 𝑇 = 5 + 10P 𝑇 = 10 = 35/4

E 𝑇 − 7 + = 5 − 7 +P 𝑇 = 5 + 10 − 7 +P 𝑇 = 10 = 3P 𝑇 = 10 = 9/4

Problem 2A

For a single server queueing system, the arrival rate is 𝜆 = 5 customers per minute. Mean sojourn time of the customers is E[𝑊] = 15 seconds.

A. If the system is a FIFO M/M/1 queueing system, on average, how often is the server idle?

𝜋0 = 1 − 𝜌; for M/M/1, E 𝑊 =1

𝜆

𝜌

1−𝜌 or E 𝐿 =

𝜌

1−𝜌

Use the same time unit:

E 𝑊 =1

𝜆

𝜌

1 − 𝜌=

1

5

𝜌

1 − 𝜌=

1

4𝑚𝑖𝑛𝑠 ⇒

𝜌

1 − 𝜌=

5

4

4𝜌 = 5 − 5𝜌 ⇒ 𝜌 = 5/9 ⇒ 𝜋0 = 1 − 𝜌 = 4/9

Problem 2B

For a single server queueing system, the arrival rate is 𝜆 = 5 customers per minute. Mean sojourn time of the customers is E[𝑊] = 15 seconds.

B. If the system is a LIFO M/M/1 queueing system, on average, how often is the server idle?

Workload curve does not change under work-conserving disciplines.

𝑾𝟏

𝑾𝟐

𝑳(𝒕) Arrival curve 𝑵(𝒕)

Time 𝑡 𝒕𝟏 𝒕𝟐 𝒕𝟏𝒅 𝒕𝟐

𝒅

Departure curve 𝑵𝒅(𝒕)

Workload Curve

𝑽(𝒕)

𝑺𝟏

𝑺𝟑

𝑺𝟐

Problem 2B

For a single server queueing system, the arrival rate is 𝜆 = 5 customers per minute. Mean sojourn time of the customers is E[𝑊] = 15 seconds.

B. If the system is a LIFO M/M/1 queueing system, on average, how often is the server idle?

Workload curve does not change under work-conserving disciplines.

𝜋0 = 1 − 𝜌 = 1 − P 𝑉 > 0 = P 𝑉 = 0 , which should be the same as under FIFO M/M/1.

Problem 2C

For a single server queueing system, the arrival rate is 𝜆 = 5 customers per minute. Mean sojourn time of the customers is E[𝑊] = 15 seconds.

C. If the system is a LIFO G/G/1 system and the average queue size of the system is 𝐸[𝑄] = 1. On average, how often is the server idle?

By Little’s Law, E 𝐿 = 𝜆E 𝑊 = 5 ∗1

4

Denote 𝐴 = 𝐿 − 𝑄 as the # of customers in service

M/M/1 Model: E 𝑄

Average # of customers waiting in the queue

E 𝑄 = 𝑖 − 1 𝜋𝑖

𝑖=1

= 𝑖 − 1 𝜋𝑖

𝑖=0

+ 𝜋0

= 𝑖𝜋𝑖

𝑖=0

− 1 + 𝜋0 =𝜌

1 − 𝜌− 1 + 1 − 𝜌 =

𝜌2

1 − 𝜌

What is the value of E[𝐿 − 𝑄] ?

Average amount of time spent in “system”: E[𝑊], E[𝐷] ? How about E 𝑊 − E[𝐷] ?

Problem 2C

For a single server queueing system, the arrival rate is 𝜆 = 5 customers per minute. Mean sojourn time of the customers is E[𝑊] = 15 seconds.

C. If the system is a LIFO G/G/1 system and the average queue size of the system is 𝐸[𝑄] = 1. On average, how often is the server idle?

By Little’s Law, E 𝐿 = 𝜆E 𝑊 = 5/4

Denote 𝐴 = 𝐿 − 𝑄 as the # of customers in service 𝜌 = E 𝐴 = E 𝐿 − 𝑄 = E 𝐿 − E 𝑄 = 5/4 − 1 = 1/4

E 𝐴 = E 𝐴|𝑉 > 0 P 𝑉 > 0 + E 𝐴|𝑉 = 0 P 𝑉 = 0 = 1P 𝑉 > 0 + 0P 𝑉 = 0 = 𝜌 ⇒ 𝜋0 = 1 − 𝜌 = 3/4

Problem 3A

Consider a LIFO single server queueing system. Denote 𝑡𝑖 and 𝑡𝑖

𝑑 as the arrival and departure time of the 𝑖th customer to a system. Let 𝑉(𝑡) denote the workload of the system at time 𝑡.

A. Assume 𝑡1 = 1, 𝑡1𝑑 = 4, 𝑡2 = 2, 𝑡2

𝑑 = 7, 𝑡3 = 3, and 𝑡3𝑑 = 6. Draw the function of 𝑉(𝑡) for 𝑡 ∈ [0,10].

𝑾𝟏

𝑾𝟐

𝑳(𝒕) Arrival curve 𝑵(𝒕)

Time 𝑡 𝒕𝟏 𝒕𝟐 𝒕𝟏𝒅 𝒕𝟐

𝒅

Departure curve 𝑵𝒅(𝒕)

Workload Curve

𝑽(𝒕)

𝑺𝟏

𝑺𝟑

𝑺𝟐

Problem 3A

Consider a LIFO single server queueing system. Denote 𝑡𝑖 and 𝑡𝑖

𝑑 as the arrival and departure time of the 𝑖th customer to a system. Let 𝑉(𝑡) denote the workload of the system at time 𝑡.

A. Assume 𝑡1 = 1, 𝑡1𝑑 = 4, 𝑡2 = 2, 𝑡2

𝑑 = 7, 𝑡3 = 3, and 𝑡3𝑑 = 6. Draw the function of 𝑉(𝑡) for 𝑡 ∈ [0,10].

Workload depends only on arrival & service times

𝑆1 = 𝑡1𝑑 − 𝑡1 = 3 ( C1 enters service at 𝑡1 = 1)

Upon the 1st customer’s departure at 𝑡1𝑑 = 4, the

3rd customer has arrived. 𝑆3 = 𝑡3𝑑 − 𝑡1

𝑑 = 6 − 4 = 2

𝑆2 = 𝑡2𝑑 − 𝑡3

𝑑 = 7 − 6 = 1

Problem 3A

Consider a LIFO single server queueing system. Denote 𝑡𝑖 and 𝑡𝑖

𝑑 as the arrival and departure time of the 𝑖th customer to a system. Let 𝑉(𝑡) denote the workload of the system at time 𝑡.

𝑡1 = 1, 𝑡2 = 2, 𝑡3 = 3

𝑆1 = 3, 𝑆2 = 1, 𝑆3 = 2

𝑽(𝒕)

𝑺𝟏

𝑺𝟑 𝑺𝟐

𝟏 𝟐 𝟑 𝟕

𝟑

𝟒

𝟏

𝟐

Problem 3B

Consider a LIFO single server queueing system. Denote 𝑡𝑖 and 𝑡𝑖

𝑑 as the arrival and departure time of the 𝑖th customer to a system. Let 𝑉(𝑡) denote the workload of the system at time 𝑡.

B. Apply Rate Conservation Law to the function 𝑥(𝑡) = 𝑉(𝑡) and show your result.

RCL: 𝑋′ ≝ lim𝑡→∞

1

𝑡 𝑥′ 𝑠 𝑑𝑠

𝑡

0= 𝜆𝐽 ≝ 𝜆 lim

𝑛→∞

1

𝑛 𝐽𝑘

𝑛𝑘=1

Left hand side:

𝑥′ 𝑠 = −1 𝑖𝑓 𝑉 𝑡 > 0

0 𝑖𝑓 𝑉 𝑡 = 0⇒ 𝑋′ ≝ lim

𝑡→∞

1

𝑡 𝑥′ 𝑠 𝑑𝑠

𝑡

0

= −𝜌

𝑾𝟏

𝑾𝟐

𝑳(𝒕) Arrival curve 𝑵(𝒕)

Time 𝑡 𝒕𝟏 𝒕𝟐 𝒕𝟏𝒅 𝒕𝟐

𝒅

Departure curve 𝑵𝒅(𝒕)

Workload Curve

𝑽(𝒕)

𝑺𝟏

𝑺𝟑

𝑺𝟐

RCL : Applications

𝑅′ 𝑡 = −1; 𝑅 𝑡𝑖− − 𝑅 𝑡𝑖

+ = −𝑇𝑖

By RCL, (if {𝑇𝑖: 𝑖 = 1, ⋯ } are i.i.d. r.v.s as 𝑇)

𝑋′ = −1 = 𝜆𝐽 = 𝜆 lim𝑛→∞

1

𝑛 −𝑇𝑖

𝑛

𝑖=1= −𝜆E 𝑇

Average inter-arrival time is 𝐸 𝑇 =1

𝜆

𝒙 𝒕 = 𝑹(𝒕)

𝑻𝟏 𝑻𝟐 𝑻𝟑 𝑻𝟒 𝑻𝟓 Time 𝑡

Problem 3B

Consider a LIFO single server queueing system. Denote 𝑡𝑖 and 𝑡𝑖

𝑑 as the arrival and departure time of the 𝑖th customer to a system. Let 𝑉(𝑡) denote the workload of the system at time 𝑡.

B. Apply Rate Conservation Law to the function 𝑥(𝑡) = 𝑉(𝑡) and show your result.

RCL: 𝑋′ ≝ lim𝑡→∞

1

𝑡 𝑥′ 𝑠 𝑑𝑠

𝑡

0= 𝜆𝐽 ≝ 𝜆 lim

𝑛→∞

1

𝑛 𝐽𝑘

𝑛𝑘=1

Right hand side: for each jump 𝐽𝑘

−𝐽𝑘 = 𝑥 𝑡𝑘+ − 𝑥 𝑡𝑘

− = 𝑉 𝑡𝑘+ − 𝑉 𝑡𝑘

− = 𝑆𝑘

⇒ 𝜆𝐽 = −𝜆E 𝑆

𝑾𝟏

𝑾𝟐

𝑳(𝒕) Arrival curve 𝑵(𝒕)

Time 𝑡 𝒕𝟏 𝒕𝟐 𝒕𝟏𝒅 𝒕𝟐

𝒅

Departure curve 𝑵𝒅(𝒕)

Workload Curve

𝑽(𝒕)

𝑺𝟏

𝑺𝟑

𝑺𝟐

Problem 3B

Consider a LIFO single server queueing system. Denote 𝑡𝑖 and 𝑡𝑖

𝑑 as the arrival and departure time of the 𝑖th customer to a system. Let 𝑉(𝑡) denote the workload of the system at time 𝑡.

B. Apply Rate Conservation Law to the function 𝑥(𝑡) = 𝑉(𝑡) and show your result.

RCL: 𝑋′ ≝ lim𝑡→∞

1

𝑡 𝑥′ 𝑠 𝑑𝑠

𝑡

0= 𝜆𝐽 ≝ 𝜆 lim

𝑛→∞

1

𝑛 𝐽𝑘

𝑛𝑘=1

𝑋′ = −𝜌 = 𝜆𝐽 = −𝜆E 𝑆 ⇒ 𝜌 = 𝜆E 𝑆

How About Workload E 𝑉 ?

Brumelle’s formula: E 𝑉 = 𝜆E 𝑆𝐷 +𝜆

2E 𝑆2

More generally, (under FIFO G/G/1),

E 𝑉 = 𝜆E 𝑆 E 𝐷 + 𝜆E 𝑆E 𝑆2

2E[𝑆]

= 𝝀𝐄 𝑺 E 𝐷 +E 𝑆2

2E[𝑆]≝ 𝝆 E 𝐷 + E 𝑅𝑠

E 𝑉 = E 𝑉|𝑉 = 0 𝑃 𝑉 = 0 + E 𝑉|𝑉 > 0 𝑃 𝑉 > 0

M/M/1 Discouraged Arrival

Poisson dist. of # of customers E[𝐿] =𝛼

𝜇

Utilization: 𝝆 = 1 − 𝜋0 = 1 − 𝑒−

𝛼

𝜇 = 𝝀𝐄 𝑺 =𝜆

𝜇

Effective arrival rate: 𝜆 = 𝜇 1 − 𝑒−𝛼/𝜇

Mean sojourn time: E 𝑊 =E 𝐿

𝜆=

𝛼

𝜇2 1−𝑒−𝛼/𝜇

0 1 2 n-1 n n+1

a a/2 a/𝒏 a/(𝒏 +1)

m m m m

a/3 a/(𝒏 -1)

m m

Problem 4A

Let 𝑋 and 𝑌 be two independent exponential random variables with E[𝑋] = 𝑚𝑥 and E[𝑌] = 𝑚𝑦. What is the probability P 𝑋 > 𝑌 ?

𝜆𝑥 = 1/𝑚𝑥; 𝜆𝑦 = 1/𝑚𝑦

P 𝑋 > 𝑌 = P 𝑋 > 𝑌|𝑌 = 𝑦 𝑓𝑌 𝑦∞

0

𝑑𝑦

= P 𝑋 > 𝑦 𝜆𝑦𝑒−𝜆𝑦𝑦∞

0

𝑑𝑦 = 𝑒−𝜆𝑥𝑦 𝜆𝑦𝑒−𝜆𝑦𝑦∞

0

𝑑𝑦

= 𝜆𝑦 𝑒− 𝜆𝑥+𝜆𝑦 𝑦∞

0

𝑑𝑦 = 𝜆𝑦 −1

𝜆𝑥 + 𝜆𝑦𝑒− 𝜆𝑥+𝜆𝑦 𝑦

0

=𝜆𝑦

𝜆𝑥 + 𝜆𝑦=

1/𝑚𝑦

1/𝑚𝑥 + 1/𝑚𝑦=

𝑚𝑥

𝑚𝑥 + 𝑚𝑦

Problem 4B

Consider an M/M/1 system with arrival rate 𝜆 and service rate 𝜇. If I obverse the system at a random time, what is the probability that the next event is an arrival? Express it using 𝜆 and 𝜇.

Let 𝑋 be the amount of waiting time till the next arrival happens

Let Y be the amount of waiting time till the next departure happens

The question becomes

𝑃 𝑋 < 𝑌 =?

Birth-Death Process

State-transition matrix:

𝑸 =

−𝜆 𝜆 0 ⋯𝜇 −(𝜆 + 𝜇) 𝜆 ⋯0 𝜇 −(𝜆 + 𝜇) ⋯⋮ ⋮ ⋮ ⋱

𝑞𝑖𝑗: rate from state 𝑖 to state 𝑗

𝑞𝑖𝑖 = − 𝑞𝑖𝑗𝑗≠𝑖 : rate of going out of state 𝑖

0 1 2 n-1 n n+1

l l l l

m m m m

l l

m m

Problem 4B

Consider an M/M/1 system with arrival rate 𝜆 and service rate 𝜇. If I obverse the system at a random time, what is the probability that the next event is an arrival? Express it in terms of 𝜆 and 𝜇.

If I observe an empty system, with probability 1, the next event is an arrival, i.e., P 𝑋 < 𝑌|𝐿 = 0 = 1

If I observe a busy system, by memeoryless, 𝑋 and 𝑌 are exponential with rate 𝜆 and 𝜇

Arrival before departure probability

P 𝑋 < 𝑌|𝐿 > 0 =𝜆𝑥

𝜆𝑥 + 𝜆𝑦=

𝜆

𝜆 + 𝜇

Problem 4B

Consider an M/M/1 system with arrival rate 𝜆 and service rate 𝜇. If I obverse the system at a random time, what is the probability that the next event is an arrival? Express it in terms of 𝜆 and 𝜇.

P 𝑋 < 𝑌= P 𝑋 < 𝑌|𝐿 = 0 P 𝐿 = 0+ P 𝑋 < 𝑌|𝐿 > 0 P 𝐿 > 0

= P 𝑋 < 𝑌|𝐿 = 0 1 − 𝜌 + P 𝑋 < 𝑌|𝐿 > 0 𝜌

⇒ P 𝑋 < 𝑌 = 1 1 − 𝜌 +𝜆

𝜆 + 𝜇𝜌 =

𝜇

𝜆 + 𝜇

Problem 5A

A discrete-time system with a FIFO queue and a single work-conserving server. 1) At each time slot, with probability 𝑝, one customer

arrives; with probability 1 − 𝑝, no customer arrives.

2) The system can hold at most two customers. Upon arrival, if a new customer finds that there are two existing customers in the system, it leaves the system immediately; otherwise, it will enter the system at the beginning of the next time slot.

3) At each time slot, if the server is busy, with probability 𝑞, the customer in service will finish and leave the system just before the beginning of the next time slot; with probability 1 − 𝑞, this customer will stay in the server and continue its service.

A. Draw the state transition diagram and write down the state transition matrix P.

When 1 customer in system, four events: a) 0 arrival, 0 departure; b) 1 arrival, 1 departure

c) 1 arrival, 0 departure; d) 0 arrival, 1 departure

Problem 5A

1 2 0

𝒑

𝟏 − 𝒑

𝒒

𝟏 − 𝒒

Problem 5A

𝑷 =

1 − 𝑝 𝑝 0

𝑞 1 − 𝑝 𝑝𝑞 + 1 − 𝑝 1 − 𝑞 𝑝 1 − 𝑞0 𝑞 1 − 𝑞

1 2

𝒒

𝒑 𝟏 − 𝒒

0

𝒒 𝟏 − 𝒑

𝒑

𝟏 − 𝒑

𝒑𝒒 + 𝟏 − 𝒑 𝟏 − 𝒒

𝟏 − 𝒒

Problem 5B

Calculate the expected # of customers E[𝐿]. Express E[𝐿] as a function of 𝑝 and 𝑞.

E 𝐿 = 0𝜋0 + 1𝜋1 + 2𝜋2 = 𝜋1 + 2𝜋2

𝑷 =

1 − 𝑝 𝑝 0

𝑞 1 − 𝑝 𝑝𝑞 + 1 − 𝑝 1 − 𝑞 𝑝 1 − 𝑞0 𝑞 1 − 𝑞

𝜋0, 𝜋1, 𝜋2 = 𝜋0, 𝜋1, 𝜋2 𝑷;

𝜋0 + 𝜋1 + 𝜋2 = 1

Problem 5B

𝑷 =

1 − 𝑝 𝑝 0

𝑞 1 − 𝑝 𝑝𝑞 + 1 − 𝑝 1 − 𝑞 𝑝 1 − 𝑞0 𝑞 1 − 𝑞

𝜋0, 𝜋1, 𝜋2 = 𝜋0, 𝜋1, 𝜋2 𝑷; 𝜋0 + 𝜋1 + 𝜋2 = 1

𝜋0 1 − 𝑝 + 𝜋1𝑞 1 − 𝑝 = 𝜋0 ⇒ 𝜋0 = 𝜋1𝑞 1 − 𝑝 /𝑝

𝜋1𝑝 1 − 𝑞 + 𝜋2 1 − 𝑞 = 𝜋2 ⇒ 𝜋2 = 𝜋1𝑝 1 − 𝑞 /𝑞

⇒𝑞 1 − 𝑝

𝑝+ 1 +

𝑝 1 − 𝑞

𝑞𝜋1 = 1

Problem 5B

Calculate the expected # of customers E[𝐿]. Express E[𝐿] as a function of 𝑝 and 𝑞.

E 𝐿 = 0𝜋0 + 1𝜋1 + 2𝜋2 = 𝜋1 + 2𝜋2

𝜋2 =𝑝 1 − 𝑞

𝑞𝜋1 =

𝑝 1 − 𝑞𝑞

𝑞 1 − 𝑝𝑝

+ 1 +𝑝 1 − 𝑞

𝑞

E 𝐿 =1 + 2

𝑝 1 − 𝑞𝑞

𝑞 1 − 𝑝𝑝 + 1 +

𝑝 1 − 𝑞𝑞