Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

Queuing Theory

Queuing Theory
• Queuing theory is the mathematics of
waiting lines.

Queuing Theory • It is extremely useful in predicting and


evaluating system performance.
• Queuing theory has been used for
operations research. Traditional queuing
theory problems refer to customers visiting
a store, analogous to requests arriving at a
device.

Long Term Averages Assumptions


• Independent arrivals
• Queuing theory provides long term
• Exponential distributions
average values.
• Customers do not leave or change
• It does not predict when the next event will
queues.
occur.
• Large queues do not discourage
• Input data should be measured over an
customers.
extended period of time.
• We assume arrival times and service
times are random. Many assumptions are not always true, but
queuing theory gives good results anyway

Queuing Model Interesting Values


• Arrival rate (λ) — the average rate at
Q which customers arrive.
• Service time (s) — the average time
W required to service one customer.
λ • Number waiting (W) — the average
S number of customers waiting.
• Number in the system (Q) — the average
Tw total number of customers in the system.

Tq

1
Queuing Theory

More Interesting Values Arrival Rate


• The arrival rate, λ, is the average rate new
• Time in the system (Tq) the average customers arrive measured in arrivals per
time each customer is in the system, time period. Common units are
both waiting and being serviced. access/second
• Time waiting (Tw) the average time each • The inter-arrival time, a, is the average
customer waits in the queue. time between customer arrivals. It is
Tq = Tw + s measured in time per customer. A
common unit would be seconds/access.

a=1/λ

Random Values Exponential Distribution


• We assume that most of the events we are • Many of the random values are
interested in occur randomly. exponentially distributed.
– Time of a request to a device Frequency of Occurrence = e-t
– Time to service a request
– Time user makes a request • There are many small values and a few
• Although events are random, we may large values.
know the average value of the times and • The inter-arrival time of customers is
their distribution. naturally exponentially distributed.
• If you flip a coin, you will get heads 50% of
the time.

Exponential Distribution

1 Poisson Arrival Rate


0.9

0.8 If customers are arriving at the exponentially


0.7 distributed rate λ, then the probability that
0.6
there will be k customers after time t is:

(λt ) k −λt
0.5

0.4

0.3
Pk (t ) = e
0.2

0.1 k!
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

2
Queuing Theory

Math Notes Poisson Example


• A networked printer usually gets 15 print
jobs every hour. The printer has to be
0! = 1! = 1 turned off for 10 minutes for maintenance.
What is the probability that nobody will
X0 = 1 want to use the printer during that time?

X1 = X

Poisson Solution Expected Number of Arrivals


• A networked printer usually gets 15 print
jobs every hour. The printer has to be If customers are arriving at the exponentially
turned off for 10 minutes for maintenance. distributed rate λ, how many customers
What is the probability that nobody will should you expect to arrive in time t?
want to use the printer during that time?
• The arrival rate is 15/60 = 0.25 jobs/min. Expected = λ * t
(0.25 * 10) 0 −0.25*10 For the printer problem with an arrival
P0 (10) = e = 0.082
0! rate λ = 0.25, in 10 minutes we should
expect 2.5 jobs to arrive

Queuing Models Common Models


Queuing systems are usually described by
three values separated by slashes • The simplest queuing model is M/M/1
where both the arrival time and service
time are exponentially distributed.
Arrival distribution / service distribution / # of servers
• The M/D/1 model has exponentially
distributed arrival times but fixed service
where: time.
• M = Markovian or exponentially distributed • The M/M/n model has multiple servers.
• D = Deterministic or constant.
• G = General or binomial distribution

3
Queuing Theory

Why is there Queuing? Utilization


• The arrivals come at random times. • Utilization (represented by the Greek letter
• Sometimes arrivals are far apart. rho, ρ) is the fraction of time the server is
Sometimes many customers arrive at busy.
almost the same time. When more • Utilization is always between zero and one
customers arrive in a short period of time
than can be serviced, queues form. 0≤ρ≤1
• If the arrival rate was not random, queues • If a bank teller spends 6 hours out of an 8
would not be created. hour day counting money, her utilization is
6/8 = 0.75

Calculating Utilization Little’s Formula


• Utilization can be calculated from the • The number in the system is equal to the
arrival rate and the service time. arrival rate times the average time a

ρ = λ*s
customer spends in the system.

Q = λ * Tq
• This is also true for just the queue.
It is important that the units of both the arrival rate W = λ * Tw
and the service time be identical. It may be
necessary to convert these values to common units.

M/M/1 Formulas Application of Little’s Formula


s ρ • Multiplying the formulas on the left by λ
Tq = Q= gives the formula on the right.
1− ρ 1− ρ
λs ρ
sρ ρ
2 λTq = = =Q
Tw = W= 1− ρ 1− ρ
1− ρ 1− ρ

4
Queuing Theory

20 Solution Process
1. Determine what quantities you need to
18

16

14
know.
12 2. Identify the server
3. Identify the queued items
Tq

10

6
4. Identify the queuing model
4
5. Determine the service time
2

0
6. Determine the arrival rate
7. Calculate ρ
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Utilization

8. Calculate the desired values

Example Solution
• Determine what quantities you need to know.
• Consider a disk drive that can complete an – The average request time is Tq
average request in 10 ms. The time to – The number of queued jobs is W
complete a request is exponentially • Identify the server
distributed. Over a period of 30 minutes, – The disk drive is the server
117,000 requests were made to the disk.
• Identify the queued items
How long did it take to complete the
– Disk requests
average request?
What is the average number of queued • Identify the queuing model
requests? – M/M/1

Solution (cont.) Solution (cont.)


• Determine the service time • Time to complete the average request
™S = 10 ms = 0.01 sec / request
• Determine the arrival rate s 0.01
TQ = = = 28.6ms
™λ = 117,000 request / (30 min * 60 sec/min) = 1 − ρ 1 − 0.65
65 requests / sec
• Calculate ρ The average length of the queue
™ρ = λ*s = 0.01 sec/request * 65 req/sec = 0.65
ρ2 0.65 2
W= = = 1.21
1 − ρ 1 − 0.65

5
Queuing Theory

Number in the System Queue Size Probabilities


The probability that there are exactly N jobs
• The value Q represents the average
in the system is given by
number of jobs in the system, both waiting
and being served. Prob[Q = N ] = (1 − ρ ) ρ N
• There are not always Q jobs in the system. Summing the probabilities for individual
Sometimes there are more, sometimes cases gives the probability of N or less
less. Q is the average. customers in the system
N
prob[Q ≤ N ] = ∑ (1 − ρ ) ρ i
i =0

Large Queue Probabilities Example Continued


• The probability that there are more than N
customers in the system is the sum of the • In the previous example, what is the
probabilities from N-1 to ∞. probability that a request does not get
• Remembering that the sum of all queued?
probabilities is one, the probability that • A job can get serviced immediately if there
there are more than N customers in the are only zero or one jobs in the system.
system is:
P[Q = 0or1] = (1 − ρ ) * ρ 0 + (1 − ρ ) * ρ 1 = 0.35 + .2275 = 0.58
N
prob[Q > N ] = 1 − ∑ (1 − ρ ) ρ i
i =0

Accuracy and Significant Digits Constant Service Time


• Just because my calculator displays a 10
digit number does not mean the answer is • In some systems the service time is
accurate to 10 digits. always a constant. The M/D/1 model is
• Your answer can only be as accurate as used for constant service time.
your input data. If your data has three • There is less randomness in the system.
significant digits, your answer cannot have • The wait time will be less.
more than three digits.
• Always use as much accuracy as possible
in these calculations and round off only at
the end.

6
Queuing Theory

M/D/1 Formulas M/D/1 Example

s(2 − ρ ) ρ2 • An ATM network sends 53 byte packets


Tq = Q= +ρ over a 155 Mb/sec line. It always takes
2(1 − ρ ) 2(1 − ρ ) 2.74 ms to send a packet. Each second
145,000 packets are sent. How long does
a packet wait to be sent?
sρ ρ2
Tw = W=
2(1 − ρ ) 2(1 − ρ )

M/D/1 Solution M/D/1 Solution


• Determine the service time
• Determine what quantities you need to
2.74x10-6 seconds
know.
• Determine the arrival rate
The average time spent in the queue, Tw.
145,000 packets/second
• Identify the server
• Calculate ρ
The transmission line.
ρ = 145,000 * 2.74x10-6 = 0.3973
• Identify the queued items
• Calculate the desired values
Packets (not bits or bytes)
• Identify the queuing model sρ 2.75 *10 −6 * 0.3973
Tw = = = 9.03 *10 −7 sec
2(1 − ρ ) 2(1 − 0.3973)
M/D/1

Multiple Servers Multiple Servers


• Customers arrive and join a single queue.
S • Whenever any of the servers is idle, it
serves the first customer on the single
queue.
λ
S • All of the servers must be identical. Any
customer can be served by any server.
• When there are N servers, the model is
S M/M/N

7
Queuing Theory

Multiple Server Utilization Intermediate Value K


• The server utilization for an N server • To make calculations easier, we first
system is: compute the value K.

ρ = λs / N ∑
N −1 ( λs ) i
i!
K= i =0


N ( λs ) i
This is the average utilization for all N
servers. i = 0 i!

K Calculation Multiple Servers Busy


• The first term (i = 0) is always 1
The probability that all servers are busy is
• Note that the value in the denominator is
equal to the numerator plus the last term. 1− K
C=
• Since the denominator is always larger
λsK
than the numerator, the value K must
always be less than 1.
1−
• The value K is an intermediate that
N
simplifies calculations. It has no intrinsic This is the probability that a new
meaning. customer will have to wait in the queue.

M/M/N formulas Example


Cs ρ • Assume that you have a printer that can
Tq = +s Q=C + λs print an average file in two minutes. Every
N (1 − ρ ) 1− ρ two and a half minutes a user sends
another file to the printer. How long does
it take before a user can get their output?
Cs ρ
Tw = W =C
N (1 − ρ ) 1− ρ

note: ρ = λs / N

8
Queuing Theory

Slow Printer Solution Slow Printer Solution


• Determine what quantities you need to • Determine the service time
know. Print a file in 2 minutes, s = 2 min
How long for job to exit the system, Tq • Determine the arrival rate
• Identify the server new file every 2.5 minutes. λ = 1/ 2.5 = 0.4
The printer • Calculate ρ
• Identify the queued items ρ = λ * s = 0.4 * 2 = 0.8
Print job • Calculate the desired values
• Identify the queuing model Tq = s / (1- ρ) = 2 / (1 - 0.8) = 10 min
M/M/1

Add a Second Printer Calculate K


• To speed things up you can buy another (λ s ) 0 (λ s ) 1
+

N −1 ( λs ) i
printer that is exactly the same as the one i! 0! 1!
you have. How long will it take for a user K= i =0
=
∑ (λs ) (λ s ) (λ s ) 2
N ( λs ) i 0 1
to get their files printed if you had two i = 0 i! + +
identical printers? 0! 1! 2!

• All values are the same, except the model


is M/M/2 and ρ = λ * s / 2 = 0.4 K = 0.849057

Calculate M/M/N Solution Faster Printer


• Another solution is to replace the existing
1− K printer with one that can print a file in an
C= = 0.22857 average of one minute. How long does it
λsK
1− take for a user to get their output with the
N faster printer?
Cs
Tq = + s = 2.57 min • M/M/1 queue with λ = 0.4 and s = 1.0
N (1 − ρ ) Tq = s / (1- ρ) = 1 / (1 - 0.4) = 1.67 min
A single fast printer is better, particularly at
Note that with twice as many printers this example runs
about 4X as fast. low utilization. 6X better than slow printer.

9
Queuing Theory

Multiple Arrival Streams Dividing Customer Streams


• Exponentially distributed arrival streams • An exponentially distributed arrival stream
can be merged. The total arrival rate is can be divided. The sum of the separated
the sum of the individual arrival rates. arrival rates must equal to original arrival
rate.
λa
λ/2
λa + λb
λ
λb λ/2

Linking Multiple Queues Multiple Queue Example


• Consider a network with a computer connected to
• The exit rate of a system is equal to the a router which is connected to a server. The
arrival rate. computer can send a packet in 12 ms while the
router can send it to the server in 7 ms. Programs
• The output from one queuing system can
on the computer generate 40 packets/second.
feed into another. The router receives a total of 100 packets/second.
• How long does it take for a packet to get to the
server?
λ λ
40 pkt/sec 100 pkt/sec

The time through the system is the sum of Computer


12 ms
Router
7 ms
Server

the time through each queuing component.

Multiple Queue Solution Multiple Queue Solution


• Determine what quantities you need to know • Determine the service time
Sum of Tq for both networks 12ms for the computer, 7 ms for the router
• Identify the servers • Determine the arrival rate
The computer transmitter and the router 40 pkt/sec for computer, 100 pkt/sec for router
• Identify the queued items • Calculate ρ
Packets ρ = 40*0.012 = 0.48 ρ =100*0.007 = 0.7
computer router

• Identify the queuing model • Calculate the desired values


both M/M/1 queues Tq =0.012/(1-0.48) = 0.0231 sec
computer

Tq =0.007/(1-0.7) = 0.0233 sec Total=46.4ms


router

10
Queuing Theory

Reusing a Server
• Consider a file server. Requests use the
network to get to the server, then use the
disk, then the network again to get back.
• The load on the network is doubled.

λ
λ Net Disk λ

λ

11

You might also like