Operational Analysis

32
Operational Analysis L. Grewe

description

Operational Analysis. L. Grewe. Operational Analysis. Relationships that do not require any assumptions about the distribution of service times or inter-arrival times. Identified originally by Buzen (1976) and later extended by Denning and Buzen (1978). We touch only some techniques/results - PowerPoint PPT Presentation

Transcript of Operational Analysis

Page 1: Operational Analysis

Operational Analysis

L. Grewe

Page 2: Operational Analysis

2

Operational Analysis

• Relationships that do not require any assumptions about the distribution of service times or inter-arrival times.

• Identified originally by Buzen (1976) and later extended by Denning and Buzen (1978).

• We touch only some techniques/results– In particular, bottleneck Analysis

• More details see linked reading

Page 3: Operational Analysis

Under the Hood (An example FSM)

CPU

File I/OI/O request

start (arrival rate λ) exit

(throughput λ until somecenter saturates)

Memory cache

network

Page 4: Operational Analysis

4

Operational Analysis: Resource Demand of a Request

CPU

Disk

Network

VCPU visits for SCPU units of resource time per visit

VNet visits for SNet units of resource time per visit

VDisk visits for SDisk units of resource time per visit

Memory

VMem visits for SMem units of resource time per visit

Page 5: Operational Analysis

5

Operational Quantities• T: observation interval Ai: # arrivals to device i• Bi: busy time of device i Ci: # completions at device i• i = 0 denotes system

i rate arrival TAi

iX Throughput TCi

i UnUtilizatio TBi

iS timeservice Meani

iCB

Page 6: Operational Analysis

6

Utilization Law

• The law is independent of any assumption on arrival/service process• Example: Suppose processes 125 pks/sec, and each pkt takes 2 ms.

What is utilization?

i UnUtilizatio TBi

i

iiCB

TC

iiSX

Page 7: Operational Analysis

7

Forced Flow Law

• Assume each request visits device i Vi times

iX Throughput TCi

TC

CCi 0

0

XVi

Page 8: Operational Analysis

8

Bottleneck Device

• Define Di = Vi Si as the total demand of a request on device i

• The device with the highest Di has the highest utilization, and thus is called the bottleneck

i UnUtilizatio iiSX

iiXSV

iiSXV

Page 9: Operational Analysis

9

Bottleneck vs System Throughput

1 UnUtilizatio iii SXV

max

1DX

Page 10: Operational Analysis

10

Example 1

• A request may need– 10 ms CPU execution time– 1 Mbytes network bw– 1 Mbytes file access where

• 50% hit in memory cache

• Suppose network bw is 100 Mbps, disk I/O rate is 1 ms per 8 Kbytes (assuming the program reads 8 KB each time)

• Where is the bottleneck?

Page 11: Operational Analysis

11

Example 1 (cont.)

• CPU: – DCPU=

• Network: – DNet =

• Disk I/O: – Ddisk =Disk I/O and network are more likely to be bottlenecks; single CPU thread canbe enough

10 ms ( e.q. 100 requests/s)

1 Mbytes / 100 Mbps = 80 ms (e.q., 12.5 requests/s)

0.5 * 1 ms * 1M/8K = 62.5 ms (e.q. = 16 requests/s)

Page 12: Operational Analysis

12

Example 1 (cont.)

• Suppose arrival/process rate is 12 requests per second, what is the response time from the disk– Utilization of disk = 12*0.5*125*1ms= 75%– Using M/M/1 (not operational law): Response

time per request block: = 1 ms /(1-0.75) = 4 ms

– If not cached, request 125 disk blocks: = 4 ms * 125 = 500 ms

– There is another way to derive R = S/(1-U)

Page 13: Operational Analysis

13

Background: Little’s Law (1961)

• For any system with no or (low) loss.

• Assume – mean arrival rate , mean time

at device R, and mean number of requests at device Q

• Then relationship between Q, , and R:

R, Q

RQ Example: Yale College admits 1500 students each year, and mean time a student stays is 4 years, how many students are enrolled?

Page 14: Operational Analysis

14

Little’s Law

time

arrival

1

2

3

A

t

tA A

AreaR tAreaQ

RQ

Page 15: Operational Analysis

15

Deriving Relationship Between R, U, and S

• Assume flow balanced (arrival=throughput)

• Assume PASTA (Poisson arrival--memory-less arrival--sees time average), a new request sees Q ahead of it

• Assume FIFO

• According to utilization law, U = XS

XRRQ

XRSSQSSR

URSR USR 1

Page 16: Operational Analysis

16

Example 2

• A request may need– 150 ms CPU execution time (e.g., dynamic

content)– 1 Mbytes network bw– 1 Mbytes file access where

• 50% hit in memory cache

• Suppose network bw is 100 Mbps, disk I/O rate is 1 ms per 8 Kbytes (assuming the program reads 8 KB each time)

• Implication: multiple threads to use more CPUs, if available, to avoid CPU as bottleneck

Page 17: Operational Analysis

17

Interactive Response Time Law

• System setup– Closed system with N users– Each user sends in a request, after response, think

time, and then send next request

– Notation• Z = user think-time, R = Response time

– The total cycle time of a user request is R+ZIn duration T, #requests generated by each user: T/(R+Z) requests

Page 18: Operational Analysis

18

Interactive Response Time Law

• If N users and flow balanced:

req./T Toal#X Throughput System

TN ZR

T

ZRN

ZR XN

Page 19: Operational Analysis

19

Bottleneck Analysis

• Here D is the sum of Di

},min{)(max

1ZDN

DNX

},max{)( max ZNDDNR

Page 20: Operational Analysis

20

Proof

• We know

max

1DX DNR )(

},min{)(max

1ZDN

DNX },max{)( max ZNDDNR

ZR XN

Using interactive response time law:

ZNDR max

ZRNX

ZDNX

Page 21: Operational Analysis

In Practice: Common Bottlenecks

• No more File Descriptors• Sockets stuck in TIME_WAIT• High Memory Use (swapping)• CPU Overload• Interrupt (IRQ) Overload

[Aaron Bannert]

Page 22: Operational Analysis

22

Summary: Story So Far

• Avoid blocking (so that we can reach bottleneck throughput)– Introduce threads

• Limit unlimited thread overhead– Thread pool, async io

• Coordinating data access– synchronization (lock, synchronized)

• Coordinating behavior: avoid busy-wait– Wait/notify; FSM

• Extensibility/robustness– Language support/Design for interfaces

• System modeling– Queueing analysis, operational analysis

Page 23: Operational Analysis

23

Summary: Architecture

• Architectures– Multi threads– Asynchronous– Hybrid

• Assigned reading: SEDA

Page 24: Operational Analysis

24

Beyond Class: Complete Java Concurrency Framework

Executors— Executor— ExecutorService— ScheduledExecutorService— Callable— Future— ScheduledFuture— Delayed— CompletionService— ThreadPoolExecutor— ScheduledThreadPoolExecutor— AbstractExecutorService— Executors— FutureTask— ExecutorCompletionService

Queues— BlockingQueue— ConcurrentLinkedQueue— LinkedBlockingQueue— ArrayBlockingQueue— SynchronousQueue— PriorityBlockingQueue— DelayQueue

Concurrent Collections— ConcurrentMap— ConcurrentHashMap— CopyOnWriteArray{List,Set}Synchronizers— CountDownLatch— Semaphore— Exchanger— CyclicBarrierLocks: java.util.concurrent.locks— Lock— Condition— ReadWriteLock— AbstractQueuedSynchronizer— LockSupport— ReentrantLock— ReentrantReadWriteLockAtomics: java.util.concurrent.atomic— Atomic[Type]— Atomic[Type]Array— Atomic[Type]FieldUpdater— Atomic{Markable,Stampable}Reference

See jcf slides for a tutorial.

Page 25: Operational Analysis

25

Beyond Class: Design Patterns

• We have seen Java as an example

• C++ and C# can be quite similar. For C++ and general design patterns:– http://www.cs.wustl.edu/~schmidt/PDF/OOCP-

tutorial4.pdf – http://www.stal.de/Downloads/ADC2004/pra03.pdf

Page 26: Operational Analysis

26

Backup Slides

Page 27: Operational Analysis

Asynchronous Multi-Process Event Driven (AMPED)

• Like Single PED, but use helper processes/threads for – disk I/O (avoid unnecessary blocking) or – CPU bottleneck (when DCPU becomes bottleneck)

AcceptConn

ReadRequest

FindFile

SendHeader

Read FileSend Data

Event Dispatcher

Helper 1 Helper 1 Helper 1

Page 28: Operational Analysis

Should You Abandon Threads?• No: important for high-end servers (e.g. databases).

• But, avoid threads wherever possible:– Use events, not threads, for GUIs,

distributed systems, low-end servers.– Only use threads where true CPU

concurrency is needed.– Where threads needed, isolate usage

in threaded application kernel: keepmost of code single-threaded.

Threaded Kernel

Event-Driven Handlers

[Ousterhout 1995]

Page 29: Operational Analysis

Another view• Events obscure control flow

– For programmers and tools

Threads Eventsthread_main(int sock) { struct session s; accept_conn(sock, &s); read_request(&s); pin_cache(&s); write_response(&s); unpin(&s);}

pin_cache(struct session *s) { pin(&s); if( !in_cache(&s) ) read_file(&s);}

AcceptHandler(event e) { struct session *s = new_session(e); RequestHandler.enqueue(s);}RequestHandler(struct session *s) { …; CacheHandler.enqueue(s);}CacheHandler(struct session *s) { pin(s); if( !in_cache(s) ) ReadFileHandler.enqueue(s); else ResponseHandler.enqueue(s);}. . . ExitHandlerr(struct session *s) { …; unpin(&s); free_session(s); }

AcceptConn.

WriteResponse

ReadFile

ReadRequest

PinCache

Web Server

Exit

[von Behren]

Page 30: Operational Analysis

Control Flow

AcceptConn.

WriteResponse

ReadFile

ReadRequest

PinCache

Web Server

Exit

Threads Eventsthread_main(int sock) { struct session s; accept_conn(sock, &s); read_request(&s); pin_cache(&s); write_response(&s); unpin(&s);}

pin_cache(struct session *s) { pin(&s); if( !in_cache(&s) ) read_file(&s);}

CacheHandler(struct session *s) { pin(s); if( !in_cache(s) ) ReadFileHandler.enqueue(s); else ResponseHandler.enqueue(s);}RequestHandler(struct session *s) { …; CacheHandler.enqueue(s);}. . . ExitHandlerr(struct session *s) { …; unpin(&s); free_session(s); }AcceptHandler(event e) { struct session *s = new_session(e); RequestHandler.enqueue(s); }

• Events obscure control flow– For programmers and tools

[von Behren]

Page 31: Operational Analysis

Exceptions• Exceptions complicate control flow

– Harder to understand program flow– Cause bugs in cleanup code

AcceptConn.

WriteResponse

ReadFile

ReadRequest

PinCache

Web Server

Exit

Threads Eventsthread_main(int sock) { struct session s; accept_conn(sock, &s); if( !read_request(&s) ) return; pin_cache(&s); write_response(&s); unpin(&s);}

pin_cache(struct session *s) { pin(&s); if( !in_cache(&s) ) read_file(&s);}

CacheHandler(struct session *s) { pin(s); if( !in_cache(s) ) ReadFileHandler.enqueue(s); else ResponseHandler.enqueue(s);}RequestHandler(struct session *s) { …; if( error ) return; CacheHandler.enqueue(s);}. . . ExitHandlerr(struct session *s) { …; unpin(&s); free_session(s); }AcceptHandler(event e) { struct session *s = new_session(e); RequestHandler.enqueue(s); } [von Behren]

Page 32: Operational Analysis

State Management

Threads Eventsthread_main(int sock) { struct session s; accept_conn(sock, &s); if( !read_request(&s) ) return; pin_cache(&s); write_response(&s); unpin(&s);}

pin_cache(struct session *s) { pin(&s); if( !in_cache(&s) ) read_file(&s);}

CacheHandler(struct session *s) { pin(s); if( !in_cache(s) ) ReadFileHandler.enqueue(s); else ResponseHandler.enqueue(s);}RequestHandler(struct session *s) { …; if( error ) return; CacheHandler.enqueue(s);}. . . ExitHandlerr(struct session *s) { …; unpin(&s); free_session(s); }AcceptHandler(event e) { struct session *s = new_session(e); RequestHandler.enqueue(s); }

AcceptConn.

WriteResponse

ReadFile

ReadRequest

PinCache

Web Server

Exit

• Events require manual state management• Hard to know when to free

– Use GC or risk bugs

[von Behren]