Vous êtes sur la page 1sur 12

I.

3 Queueing Systems
For some MPs direct analytical solutions to the system of equations p Q = 0 can be obtained Example: the M/M/1 queue (exponentially distributed inter-arrival and services times (means 1 , 1 respectively), innite capacity FIFO queue, one server) Note: Kendall notation: A/S/c/K

SIMULATION AND MODELLING


Tony Field and Jeremy Bradley {ajf,jb}@doc.ic.ac.uk

A: Arrival process, i.e. inter-arrival time distribution (M = Markov, D = Deterministic, G = General etc.) S: Service process (as above) c: Number of servers K: Queue capacity (jobs in the rst c slots are in service), default

The M/M/1 queue is an example of a birth-death process; in general the arrival (birth) and service (death) rates can be state-dependent (see problem sheet) The CTMC:
0

The balance equations p0 ( + )p n = = p1 pn1 + pn+1 , n>0

Spot the solution by inspection...

...

p1

= =

p0

p0

where =

For state 1: ( + )p 1 p2 = = p0 + p2 p1 = 2 p0

because p0 = p1 (above)
3 4

By inspection, we thus hypothesise:


n

pn = p0 , n 0

p0 is found from the normalising equation:


pn =
n=0 n=0

n p0 = 1

To prove that this is a solution, substitute it into the balance equations and verify that lhs=rhs: Trivially so for n = 0 For n > 1 ( + )n p0 + = = = And the solution is unique
5

Rearranging... p0 =

n=0

=1

n1 p0 + n+1 p0 + +

Important: the sum only converges if < 1 i.e. < ; hence the case = has no solution (the system is unstable) Putting this together, we obtain: pn = (1 ) n , n0

Performance Measures for the M/M/1 Queue


Throughput, We can use the above result to determine the throughput : = = = p0 0 + (1 p0 )

Mean queue length, N Recall the denition of the mean queue length:

N=
n=0

npn

The n in the summation is ddly, but notice that: nn = d n d

Server utilisation, U The server is idle when n = 0; busy otherwise U = = = 1 p0 = 1 (1 ) = = S


7

Hence: N =

n=0

1 Pr{ The server is idle }

npn = (1 ) d d

nn
n=0

(1 )

n
n=0

Mean Response ( Waiting) Time, W Recall: the mean response time is the mean time that a job spends in the system (queueing time + service time) The easiest way to nd W is to use Littles Law N = W = W Thus W = = = N/ (1 ) 1

Mean Queueing Time The time spent waiting to go into service (WQ say) is easily computed once we know W : WQ = W 1 =

Note: If a customer is removed from the queue before it goes into service then Littles Law applied to WQ delivers the mean number of customers waiting to be served: NQ = = WQ 2 1

10

Some Examples
2 2 2 3 5 8 4 5 10 4 10 12 2 2 2 3 5 8 U 1/2 2/5 1/5 3/4 1/2 2/3 N 1 2/3 1/4 3 1 2 W 1/2 1/3 1/8 1 1/5 1/4

Queueing Networks
What happens when we combine several queues and servers to form a network? Lets study the simplest arrangement of two centres:
1 2

Note: the arrival rate (throughput) is the same for both queues Lets proceed as before - the state this time is the population of both queue 1 (n1 say) and queue 2 (n2 say), i.e. a pair (n1 , n2 ) The queue length vector random variable is (N1 , N2 ) and well write pn1 ,n2 = P (N1 = n1 , N2 = n2 ) at equilibrium

11

12

Because the state is a pair (of queue populations) the state transition diagram is now two dimensional:
2 1 2 1,0 0,0 1 2 0,1 2 1 2 2

We can, however, come up with four equations which cover all states and transitions. For n1 , n2 > 0: p 0 ,0 ( + 1 ) pn1 ,0 ( + 2 ) p0,n2 ( + 1 + 2 ) pn1 ,n2 = = = = 2 p 0 ,1 pn1 1,0 + 2 pn1 ,1 1 p1,n2 1 + 2 p0,n2 +1 pn1 1,n2 + 1 pn1 +1,n2 1 + 2 pn1 ,n2 +1

2,0

1,1

0,2

13

14

One way to proceed is to guess a solution! Lets try:


1 n2 pn1 ,n2 = n 1 2 p0,0

So it is a solution, and its unique! We nd p0,0 again using the fact the probabilities sum to 1: pn1 ,n2 =
n1 , n2 n1 , n2 0 n1 , n2 n1 , n2 0
1 n2 n 1 2 p0,0 = 1

where 1 = /1 , 2 = /2 We can test it by substitution into the balance equations:


0 0 1 2 p0,0

= = = =

by p0,0 ( + 1 )
1 by n 1 p 0 ,0 1 0 n 1 2

p 0 ,0

1 2 0 1 2 p0,0

Hence

1 n2 n 1 2

p 0 ,0
n1 1 0 2 1

=
n1 =0 n2 =0

p 0 ,0 +

1 1 2 n 1 2

+ 1

/ 1 + 2 2 = 1 +

p 0 ,0

1
1 n 1

1
2 n 2

=
n1 =0

n2 =0

and so on for the other cases (check them out!)

(1 1 )(1 2 )

15

16

Incredibly, we arrive at:


n2 1 pn1 ,n2 = (1 1 ) n 1 (1 2 ) 2 ,

In particular, the M/M/1 queue results apply to each node in isolation, hence, for example: n1 , n2 0 The utilisations are U1 = 1 and U2 = 2 The mean population of queue 2 is 2 1 2

So, the joint probability (of being in state (n1 , n2 ) is the product of the marginals (the probability of the rst queue being in state n1 and similarly the second) This is an example of the Product Form result which applies to an arbitrary Markovian queueing network An extraordinary consequence of this is that each queue now operates as if it were an M/M/1 queue with an independent Poisson arrival stream

The mean time spent in queue 1 is 1 2 The probability that queue 2 contains exactly 4 customers is p(N2 = 4) = (1 2 )4 2 and so on...
18

17

Arbitrary Networks
These wonderful properties generalise to arbitrary networks but we rst have to determine the throughputs at each node... Branches Where there is a branch, the trac (throughput) splits in proportion to the routing probabilities, e.g.
q q
1

Joins Where there is a join we sum the throughputs on each arc


1 2
. . .

i
i=1

q
1

OR

q q

. . . q
n

. . . q
n

This branching and joining is like the decomposition and superposition of Poisson processes (Remark: Even with external Poisson arrivals the internal arrival processes in a network are not Poisson, but the theory miraculously works as if they were!)
20

q
n

19

Trac Equations This leads to a set of linear trac equations: if the external arrival rate to node i is denoted i , we have for M nodes
i 1 q1,i i i i q i,1 i q i,2

Jacksons Product-Form Result Suppose the network has M nodes. Given the arrival rates at (throughputs of) each node the probability that the system is in the state (n1 , ..., nM ) at equilibrium is the product form

p(n1 , ..., nM )
MqM,i
Throughputs here and here must be the same at equilibrium

i q i,M

i=1

i (1 i )n i

In the steady state, for 1 i M i = = i + 1 q1,i + 2 q2,i + + M qM,i


M

where i =

i i

i +
j =1

j qji

So, the only thing thats hard is the calculation of the throughputs i , 1 i M
22

21

Performance Measures Each queue within a network can be treated in isolation once we have obtained the i , 1 i M The performance measures for the individual queues are precisely those for the M/M/1 queue, e.g. Ui Li Wi WQ i p(Ni = ni ) = = = = = i = i i

Global Measures
It is easy to show that the mean total population, L say, is the sum of the mean populations of each queue:
M

L=
i=1

Li

i 1 i 1 i i i 2 i and LQi = i i 1 i i n i (1 i )
23

But remember, Littles Law can be applied to any system at equilibrium, so it can be applied here to the whole network If is the total arrival rate (throughput) to the network, the mean total time spent in the network, W say, is W = L/ = 1
M

Li
i=1

24

I.IV (Discrete-Event) Simulation (DES)


In real-world systems, one event triggers another future event, indeed, possibly many others, e.g. A memory read may trigger data available A system I/O call may trigger I/O complete A network send may trigger a ACK/NACK and so on

Event scheduling
If we cant model a system as a CTMC we need to write a program to generate random sample paths through the underlying transition system Events are modelled explicitly as functions (or procedures/methods etc.) which when invoked: Transform the system state (variables in the code) Schedule zero or more future events
HISTORY FUTURE t = t2 t1 time E2 (t2) E1 (t1)

In MPs (CTMCs) time delays are memoryless so at any point in time the residual time to the ring of an event has the same distribution as the original ring time In general, to model the passage of time we must remember the time at which future events are due to occur

Current time (now = t1)

E1 schedules E2 at time t2 The interevent time can be computed in many ways, for example by sampling the interevent time distribution if this is known: t

Density function of t

25

26

The central data structure is the time line (the diary) notionally a time-ordered collection of (Event, time) pairs An event manager walks the time line invoking the associated event functions in time order Before invoking each event, the current time is advanced to the associated event time (asynchronous)
E1 t1
set time = t1 invoke E1

Example: A Single-server FIFO Queue


Consider a single-server queue but now with arbitrarily distributed inter-arrival and service times

...

Capacity N

E2 t2
set time = t2 invoke E2

E3 t3
set time = t3 invoke E3

E4 t4
set time = t4 invoke E4

E5 t5
set time = t5 invoke E5 etc.

The simplest model again identies a state with each queue population (0, 1, 2...):
arrival arrival

...

arrival

arrival

0
completion

1 ...
completion

N1
completion completion

We work exclusively in virtual time - time is just a double

27

28

Problem: there may be several arrivals between a service time commencing and it completing we must remember when the completion is due to occur Similarly, several completions may happen between arrivals
Schedule successive arrivals... 0 A 1 A 2 A 3 D 2 A Schedule departure 3 D State variable

For the single-server queue there are two events (Arrival and Completion) Code sketch (pop is the populaton state variable)... Arrival: pop++ ; if pop < n t = sample from inter-arrival time distribution schedule a new arrival at time t from now if pop == 1 t = sample from service time distribution schedule a new completion at time t from now

Schedule departure

x1 y1 y2 y3 z1 z2 y4

x2

xi = ? yi = ?

zi = ?

29

30

Continued... Completion: pop-- ; if pop == n-1 t = sample from inter-arrival time distribution schedule a new arrival at time t from now if pop > 0 t = sample from service time distribution schedule a new completion at time t from now

Descheduling
Suppose the queue above is emptied periodically by Clear events
arrival arrival

... arrival N1

arrival

0
clear

completion clear

completion

completion

...

clear clear

We kick start it by scheduling the rst arrival and terminate after a specied number of arrivals, or termination time

Gotcha: If a customer is in service at a Clear event, there is an outstanding Completion event; this must be removed (descheduled)... We therefore need to remember the current completion event, in case we need to remove it...

31

32

Clear: t = sample from inter-clear time distribution schedule next clear event at time t from now if pop > 0 deschedule the completion event pop = 0 ; During intialisation we must also prime the event set with the rst clear event BUG: The above code contains a model bug. What is it? (See problem sheet.)

Essential Ingredients of a DES


A DES is conceptually simple; we need: A priority queue (or similar) for the time line A representation for events, e.g. pairs or class instances A scheduler for adding new events to the time line A descheduler for cancelling unwanted events from the time line An execution loop that walks the time line invoking events in time order The current time (a Double?) Algorithms for sampling distributions (coming up soon...) We also need to be able to measure things, but thats just more code, right?!

33

34

Question: Is there an underlying stochastic model for discrete-event simulation that enables us to specify a simulation in a language/library-independent way? Answer: Yes the GSMP...

The Generalised Semi-Markov Process (GSMP)


A formal system for dening discrete-event simulations comprising: A set S of states (nite or countably innite) A set of events E = {e1 , ..., eN } E (s) the set of events scheduled to occur in state s S

p(s ; s, e) the probability that the next state is s when event e occurs in state s F (x; s , e , s, e) the distribution function used to set the clock for new event e when event e triggers a transition from s to s r (s, e) the rate at which the clock for event e E runs down in state s S0 , F0 the distribution functions used to assign the initial state and to set the clocks for all active events in that state.

35

36

Notice the subtle dierence between GSMP clocks and the (absolute) event times in a DES Clocks run down (to 0) at a state-dependent rate The event whose clock reaches 0 rst in any state triggers the next transition A clock setting function sets the clocks for new events that are scheduled during the transition The clocks of old events, i.e. that are active in both the old and new states, continue to run down Events that were active in the old state, but not the new, are cancelled (descheduled) Note: The above formulation only allows one event to trigger a transition, but this is easily generalised to a set of events
37

It is important to understand the concept of old, new and cancelled events, when event e triggers a transition from state s to s
Cancelled events (E(s){e})E(s) New events N(s; s, e ) = E(s)(E(s){e}) 11111 00000 0000000000000 1111111111111 00000 11111 00000 11111 000000000000 111111111111 0000000000000 1111111111111 00000 11111 000 111 000 111 00000 11111 000000000000 111111111111 0000000000000 1111111111111 000 111 000 111 00000 11111 000 111 000 111 00000 11111 000000000000 111111111111 0000000000000 1111111111111 000 111 000 11111 111 00000 000 111 000 111 00000 11111 000000000000 111111111111 0000000000000 1111111111111 000 111 000 111 00000 11111 000 111 000 111 00000 11111 000000000000 111111111111 0000000000000 1111111111111 000 111 000 111 000 111 000 111 000000000000 111111111111 0000000000000 1111111111111 000 111 000 111 000 111 000 111 000000000000 111111111111 0000000000000 1111111111111 000 111 000 111 000 111 000 111 000000000000 111111111111 0000000000000 1111111111111 000 111 000 111 000 111 000 111 000000000000 111111111111 0000000000000 1111111111111 000 111 000 111 000 111 000 111 000000000000 111111111111 0000000000000 1111111111111 000 111 000 111 000 111 000 111 000 111 000 111 000000000000 111111111111 0000000000000 1111111111111 000 111 000 111 000000000000 111111111111 0000000000000 1111111111111 000 111 000 111 E(s) E(s) Old events O(s; s, e ) = E(s) (E(s){e})

We talk of scheduling new events and descheduling cancelled events


38

Example: consider the transition from s to s via event e2 below


e1 s C1 C C3 2 e3 e2 s C3 C4 C5 e3 New (e 4 , e5 ) Old (e 3 ) Cancelled(e 1 ) e4 e5

Example 1: Particle arrivals


S E E (s 0) p(s + 1; s, arr ) p(s ; s, e) F (x; s + 1, arr, s, arr ) r (s, arr ) S0 (0) S0 (s > 0) F0 (x; arr, 0)

= = = = = = = = = =

{0, 1, 2...} {arr } {arr } 1, s 0 0, s, s 0, s = s + 1 Fa (x), s 0 1, s 0 1 0 Fa (x)


where arr = arrival

A GSMP denes a transition system, which we can partially specify diagramatically

arrival (set C a)

arrival (set C a)

arrival (set C a)

...

C a Clock for arrival event

39

40

Example 2: Single-server FIFO queue


S E E (0) E (0 < s < N ) E (N ) p(s + 1; s, arr ) p(s 1; s, com) F (x; s + 1, arr, s, arr ) F (x; s 1, com, s, com) F (x; 1, com, 0, arr ) F (x; N 1, arr, N, com) r (s, e) S0 (0) F0 (x; arr, 0) = = = = = = = = = = = = = = {0, 1, 2..., N } {arr, com} where arr = arrival, com = completion {arr } {arr, com} {com} 1, 0 s < N 1, 0 < s N all other probabilities are 0 Fa (x), 0 s < N 1 Fc (x), 1 < s N Fc (x) Fa (x) 1, 0 s N, e E (s) 1, S0 (s > 0) = 0 Fa (x)

0
Ca

arrival (set C a , C c )

arrival arrival (set C a ) (set C a ) ... N1 1 Ca Ca Cc Cc

arrival

N
Cc completion (set C a , C c )

...
completion Ca Cc completion (set C c ) completion (set C c )

Clock for arrival event Clock for completion event

41

42

Example 3: The single-server queue with clearance


S E E (0) E (0 < s < N ) E (N ) p(s + 1; s, arr ) p(s 1; s, com) p(0; s, clr ) = = = = = = = = {0, 1, 2..., N } {arr, com, clr } where, additionally clr = clear {arr, clr } {arr, com, clr } {com, clr } 1, 0 s < N 1, 0 < s N 1, 0 s N all other probabilities are 0

continued F (x; s + 1, arr, s, arr ) F (x; s 1, com, s, com) F (x; 1, com, 0, arr ) F (x; N 1, arr, N, com) F (x; 0, clr, s, clr ) F (x; 0, arr, N, clr ) r (s, e) S0 (0) S0 (s > 0) F0 (x; a, 0) F0 (x; r, 0) = = = = = = = = = = = Fa (x), 0 s < N 1 Fc (x), 1 < s N Fc (x) Fa (x) Fr (x), 0 s N Fa (x) 1, 0 s N, e E (s) 1 0 Fa (x) Fr (x)

43

44

0
Ca Cr

arrival (set C a , C c )

arrival arrival (set C a ) (set C a ) ... 1 N1 Ca Ca Cc Cr Cc Cr

arrival

N
Cc Cr completion (set C a , C c )

A sample path of a GSMP is a particular (random) traversal of the transition system (a simulation) To start it o, we use S0 to select an initial state s S ; for each event e E (s) use F0 (x; s, e) to initialise Ce A sample path is then generated by repeating the following steps: 1. Find tnext = min{Ce /r (s, e) | e E (s)} and let e be the winning event 2. Determine the next state s using p(.; s, e) 3. For each o O(s ; s, e), reduce Cn by tnext r (s, o) 4. For each n N (s ; s, e), set Cn using F (x; s , n, s, e) 5. Set s = s

clear (set C r )

completion

...
completion (set C c ) completion (set C c )

clear (set C r )

clear (set C r )
Ca Cc Cr Clock for arrival event Clock for completion event Clock for clear event

clear (set C r , C a )

45

46

Vous aimerez peut-être aussi