Вы находитесь на странице: 1из 11

Suggested Books: Probability, Markov Chains, Queues and Simulation William Stewart Princeton University Press, 2009

SIMULATION AND MODELLING


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

Discrete-event System Simulation J. Banks, J.S. Carson and B.L. Nelson Prentice Hall International, 1994 Simulation Modeling and Analysis A.M. Law and W.D. Kelton McGraw Hill, 2000

A Compositional Approach to Performance Modelling (rst three chapters) J. Hillston Cambridge University Press, 1996. On-line at: http://www.doc.ic.ac.uk/ jb/teaching/336/1994hillston-thesis.ps.gz Probability and Statistics with Reliability, Queuing and Computer Science Applications K. Trivedi Wiley, 2001

Course Overview
This course is about using models to understand performance aspects of real-world systems A model represents abstractly the dynamical behaviour of a system It then becomes a tool for reasoning about (the performance of) a system Models have many uses, e.g.: To understand the behaviour of an existing system To predict the eect of changes, rewrites or upgrades to a system To study new or imaginary systems

There are many application areas, e.g. Computer architecture Networks/distributed systems Software performance engineering Telecommunications Manufacturing Healthcare Transport Bioinformatics Environmental science/engineering

This course...
Were going to focus on state transition systems, with continuous time and discrete states The state space will either be nite, or countably innite:

...

...

In general, a transition (event) might target several states probabilistically

...
States have holding times Transitions correspond to "events"

Here, states have holding times (random variables) and transitions may occur probabilistically
5 6

These models can variously be solved: Analytically Numerically By simulation Broadly, these are in decreasing order of eciency and increasing order of generality
System

Syllabus Part I
I.1 Fundamental Laws I.2 Markov Processes I.3 Queueing Systems I.4 Simulation
Discrete-event Simulation Random number generation Distribution sampling Output analysis

Syllabus PART II
II.1 Stochastic Petri Nets II.2 Stochastic Process Algebras II.3 Fluid Approximations

Analytical Model
(closed form expressions)

Numerical Model
(linear system of equations)

Simulation Model
(program for generating sample paths)

Direct calculation

Linear solver

Program execution and measurement

Performance Measures

Motivation: Some Modelling Problems


Example 1: A Simple TP server
A TP system accepts and processes a stream of transactions, mediated through a (large) buer:

Example 2: Job Scheduling


Consider an operating system scheduler where the job sizes (X ) have a high (squared) coecient of variation (e.g. a heavy-tailed distribution):
...

...
Transactions arrive randomly at some specied rate The TP server is capable of servicing transactions at a given service rate Q: If both the arrival rate and service rate are doubled, what happens to the mean response time?
9

V AR(X ) 50 E (X )2 Rank the following in order of mean processing time per job: 10
2 CX =

Round Robin (preemptive) First-Come-First-Served Shortest Job First (non-preemptive) Shortest Remaining Processing Time (preemptive)
10

Example 3: Heathrow Terminal 4


There are ve security scanners (X-ray) between the check-in and departures area at Terminal 4 One of them is broken:
DEPATURES LOUNGE

Example 4: A central server


Jobs are submitted to a central server
Completions

2
Arrivals

Disk 1

3
BROKEN

Disk2

. . .

Around 0.5 customers pass through the terminal each second and it takes just under 8 seconds on average to scan each passenger The average delay is 30 minutes(!) Q: How long would it take on average if all 5 scanners were working?
11

On average, each submitted job makes 121 visits to the CPU, has 70 disk 1 accesses and 50 disk 2 accesses The mean service times are 5ms for the CPU, 30ms for disk 1 and 27ms for disk 2 Q: How would the system response time change if we replace the CPU with one twice as fast?
12

Example 5: A manufacturing system


A factory has 5 assembly areas
1 0

There are three job types, numbered 0, 1 and 2, which occur with probability 0.3, 0.5 and 0.2 respectively Jobs arrive at the rate of 4/hr and visit the stations in the order: 0 1 2 2, 0, 1, 4 3, 0, 2 1, 4, 0, 3, 2

Queue

The mean time for each job type at each station in visit order is
3 4

0 1 2

0.50, 0.60, 0.85, 0.50 1.10, 0.80, 0.75 1.10, 0.25, 0.70, 0.90, 1.00

Type 0 jobs

Queue

Q: If you were to invest in one extra machine, where would you put it?
13 14

I.1. Fundamental Laws


Consider the following:
Arrivals System Completions

Some Direct Measures


The Arrival Rate is = A/T The average inter-arrival time is 1 = T /A The Throughput is = C/T If the system includes a resource whose total busy time is B then, The Utilisation of the resource is U = B/T The average Service Time of each job at the resource is S = B/C The service rate is = 1/S = C/B Now some Fundamental Laws (or Operational Laws)...

Lets assume we observe the system for time T and let The number of arrivals be A The number of completions be C From these we can dene a number of useful performance measures and establish relationships between them

15

16

The Utilisation Law


Since U = B/T = C/T B/C we have:

Littles Law
Suppose we plot (A C ) over the observation time (T ):
AC

U = S
Often we work with service rates rather than times, in which case we have U = / Importantly, note that U < 1 so we require = 1/S > Q: What if = ?
I/T

Total area= I

4 3 2 1 0

0 t1

t2

t3 t4 t5

t6

t7 t8

t9 t10 t11

time

Let the accumulated area be I (in request-seconds)

17

18

The average number of jobs in the system is N = I/T The average time each job spends in the system (the average waiting time) is W = I/C Since I/T = C/T I/C we have:

Littles Law can be applied to any system (and subsystem) in equilibrium, e.g.
Clients . . . Subservers

N = W
Note: Assumes (A C ) is zero at either end of the observation period, or that C is much larger than the residual populations at either end
CPU

19

20

The Response Time Law


The special case of a population of users in think/compute mode is ubiquitous and has its own law Let Z be the think time, i.e. the time between completion of one request and the submission of the next N is now the total population of users and the request submission rate The average total time for each cycle is W + Z , so from Littles Law, N = (W + Z ), or

The Forced Flow Law


Suppose the system in question comprises a number of resources that a job can visit during its time in the system Let Ck be the number of job completions at, resource k The average number of visits each job makes to resource k is then Vk = Ck /C Rearranging: Ck = Vk C so, dividing both sides by T , Ck /T = Vk C/T , i.e.

W = N/ Z
21

k = V k
where k is the throughput of resource k

22

The Flow Balance Assumption


It is often useful to assume that A = C in which case, A/T = C/T , i.e. = In particular, systems that are in equilibrium (or steady state) must satisfy this property in the long term Note: If the ow balance assumption does not hold in the long term (as time ), then the system is fundamentally unstable Motto: What goes in must come out!

I.2 Markov Processes


Markov Processes (MPs), a.k.a. Continuous Time Markov Chains (CTMCs), are a simple, but powerful, class of stochastic transition systems An MP is dened by a set, S , of states and a transition rate matrix (or generator matrix) Q of size |S | |S | The (i, j )th element of Q, qi,j , is the transition rate from state i to state j , 1 i, j |S | There are no self-loops (they dont eect transitions out of the state) so the diagional terms are unused By convention, we therefore dene qi,i = will be really useful later on
j S,j =i qi,j ,

which

23

24

Example: two machines share a sequential I/O device, but are otherwise independent Machine i issues I/O requests at rate ri and I/O requests from machine i are serviced at rate si , where i [1, 2]
r2 r1 s1

State Holding Times


Each qi,j is the (rate) parameter of an exponential distribution, i.e. if X exp(qi,j ) then F (x) f (x) = = P (X x) = 1 eqi,j x qi,j eqi,j x , x 0, qi,j 0

2
s1 s2

1. Both machines executing 2. Machine 1 doing I/O 3. Machine 2 doing I/O 4. Machine 1 doing I/O, machine 2 waiting 5. Machine 2 doing I/O, machine 1 waiting

1
s2 r2

item The exponential distribution is memoryless, in that the future is independent of the past, i.e. if X exp(r ) P (X t + s | X > t) = = = = 1 P (X > t + s & X > t)/P (X > t) 1 P (X > t + s)/P (X > t) 1 er(t+s) /ert = 1 ers P (X s ) s, t 0

r1

Q =

(r1 + r2 ) s1 s2 0 0

r1 (r2 + s1 ) 0 0 s2

r2 0 (r1 + s2 ) s1 0

0 r2 0 s1 0

0 0 r1 0 s2

25

26

In general there may be several possible transitions out of a state, each with an associated rate These race each other to be the rst to re The state holding time is thus the minimum of a set of exponentially distributed random variables; this is itself exponentially distributed: If Xi exp(ri ), 1 i n then P (( min Xi ) x) =
1 i n

The Markov Property


Because the state holding times are memoryless, the next transition is naturally determined exclusively by the current state: if S (t) S is the state of the process at time t then (the Markov Property) for t1 < t2 < ... < tn :

P (S (tn ) = sn | S (tn1 ) = sn1 , ..., S (t1 ) = s1 ) = P (S (tn ) = sn | S (tn1 ) = sn1 )

1 P (X1 > x & ... & Xn > x)


n

= i.e. min1in Xi exp(

1
i=1 n i=1 ri )

eri x = 1 e(r1 +...+rn )x

27

28

Steady-state Solution of a Markov Process


The plan... Let ps (t) = P (S (t) = s) be the probability of being in state s at time t Derive a set of linear equations that dene the steady state, or equilibrium, solution for ps (t) as t , i.e. ps , s S Now there are two approaches: Numerical: Solve the linear system numerically to obtain the steady state probabilities Analytical: Try to spot direct analytical solutions to the linear system (preferred, but only possible for certain systems) From the ps , s S , derive the performance measures of interest, again either numerically or analytically
29

Linear Equations
Assume that the MP is irreducible: each state can be reached from every other S may be nite or may contain (countably) innitely many states Recall: if the time between transitions is exponentially distributed with some (rate) parameter r then the number of events, N , in time interval t is Poisson distributed: P (N = n) = Recall also the expansion rule: ex = 1 + x + x2 x3 + + ... 2! 3! (r t)n ert n!

30

From the above: P (N = 0) = ert = 1 r t + (r t) (r t) + ... 2! 3!


o(t) 2 3

Note that the probability of two or more rings in an interval (t, t + t) is o(t) In particular, given several possible event rings from a state i S (potentially dierent rates), e.g.
Event 1 qi,j Event 2 i j

o(h) is a quantity such that limh0 Thus: P (N = 0) =

o( h ) h

=0

1 r t + o(t)

k qi,k

P (Event 1 (only) res in (t, t + t)) Similarly: P (N = 1) = (r t) ert = r t + o(t) = P (Event 1 res once and Event 2 res zero times in (t, t + t)) = (qi,j t + o(t))(1 qi,k t + o(t)) = qi,j t + o(t)
31 32

However, P (Both Event 1 and Event 2 re in (t, t + t)) = (qi,j t + o(t))(qi,k t + o(t)) = o(t) Innitely many other multiple rings are possible (e.g. state m state n state i) but the probability of all such multiple rings occurring in (t, t + t) is o(t) The probability of there being no transitions out of state i in interval (t, t + t) is (1 qi,j t + o(t)) = 1
j S,j =i j S,j =i

Now lets put this all together... During an innitesimal interval (t, t + t) either nothing can happen or one event can trigger a transition or... ...any combination of multiple events can re, but each of these compound events happens with probability o(t). Thus: pi (t + t) = pi (t) 1
j S j S

qi,j t

qi,j t + o(t)

pj (t) qj,i t + o(t)

The probability of exactly one transition from state i to some other state j in the interval (t, t + t) is qi,j t + o(t) The probability of more than one transition is o(t)
33 34

Rearranging the above, pi (t + t) pi (t) = pi (t) t Thus, in the limit t 0, dpi (t) dt = pi (t)
j S,j =i

qi,j +

j S,j =i

j S,j =i

o(t) pj (t) qj,i + t

Theorem
For a nite irreducible CTMC there exists a limiting distribution p = limt p(t)

qi,j +
j S,j =i

pj (t) qj,i

For all i S , if there exists a limiting distribution such that, as t , pi (t) converges on the limit pi , (the equilibrium or steady state probability of being in state i) then: limt dpi (t) =0 dt pi
j S,j =i qi,j

j S,j =i

pj qj,i

These are called the (global) Balance Equations


35 36

Finite State Space


If S is nite so is the generator matrix Recall the denition of the diagonal element: qi,i = j S qi,j ; this represents the total rate out of state i (out minus sign) Furthermore, 1/qi,i is the mean state i holding time (see earlier) This enables us to write the balance equations in matrix form: let p(t) = (p1 (t), p2 (t), ..., pn (t)), where n = |S |. Then dp(t) = p(t)Q dt so that, at equilibrium, p Q = 0 where p = (p1 , p2 , ..., pn )

The equation p Q = 0 is just a nice way of packaging up the balance equations It also denes a linear system of equations that can be solved numerically to obtain the pi , i S For example, consider the q 0 ,0 . . . (p1 , ..., pn ) qi,0 . . . qn,0 This is precisely: pi product of p and column i of Q: ... q0,i ... q0,n ... qi,i ... qi,n = (0, ..., 0) ... qn,i ... qn,n =
j S,j =i

j S,j =i qi,j

pj qj,i , as above

37

38

Note that Q is singular (every row sums to 0) and so has no inverse (there is no unique solution) However... if we encode the normalising condition sS ps = 1 into Q then the irreducibility of the process means that Q becomes non-singular; there is then a unique solution for p Thus, pick a column, c, and set all its elements to 1 (giving Qc , say); likewise the cth element of the 0 vector (giving 1c ) Now use your favourite linear solver to solve p Qc = 1c : q0,0 q0,1 ... q0,c1 1 ... q0,n q1,0 q1,1 ... q1,c1 1 ... q1,n = (0, 0, ..., 0, 1, 0, ..., 0) p . . c1 . qn,0 qn,1 ... qn,c1 1 ... qn,n
39

Theorem
The generator matrix for an irreducible CTMC with n states has rank n 1.

Corollary
The normalised generator matrix for an irreducible CTMC with n states, in which each element of a chosen column is replaced by 1, has rank n and is thus non-singular (i.e. invertible).

40

Back to our example and picking column 5 (r 1 + r 2 ) r 1 r2 s (r 2 + s 1 ) 0 1 p s2 0 (r 1 + s 2 ) 0 0 s1 0 s2 0

for normalisation... 0 1 r2 1 0 1 = (0, 0, 0, 0, 1) s 1 1 0 1

For example, with r1 = 0.05, r2 = 0.1, s1 = 0.02, s2 = 0.05 we get: p = (0.0693, 0.0990, 0.1683, 0.4951, 0.1683) Note that
5 i=1

pi = 1

41

Вам также может понравиться