event-driven programming

Post on 07-Jan-2016

43 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

Event-Driven Programming. Vivek Pai Dec 4, 2001. GedankenEvents. Enron – bad news all around What are these numbers: $1B, $100B, $80B, $200M Korean facts Largest on-line game has 3M+ subscribers What’s the comparable figure for the US? What are the populations of the two countries? - PowerPoint PPT Presentation

TRANSCRIPT

Event-Driven Programming

Vivek PaiDec 4, 2001

2

GedankenEventsGedankenEvents

Enron – bad news all aroundWhat are these numbers: $1B, $100B, $80B, $200M

Korean factsLargest on-line game has 3M+ subscribersWhat’s the comparable figure for the US?What are the populations of the two countries?

How many albums does the Wu Tang Clan have?What is Ginger?

3

A Random AsideA Random Aside

What do these companies have in commonVA Linux, Penguin ComputingRLX Technologies, FibercycleHP, CompaqDell, IBM

4

MechanicsMechanics

Project 3 grading in progressProject 4 grading in progressAll feedback questions answeredOne mail dropped – extra project proposalsSpeaking of which

We need to agree on a one-page proposal

5

Project 5Project 5

Tyranny of the majoritySeveral goals

Performance improvement via cachingDynamic adjustment to loadMaster/slave or symmetric programming

Probably due on Dean’s DateExtra credit: 6 points (15 base)

6

Another Random AsideAnother Random Aside

You may want to readFlash: An Efficient and Portable Web ServerAvailable from my home page

Caveat: far more complicated than Project 5

7

Official GoalsOfficial Goals

Discuss the difference between standard programming styles and event-driven programming

Show the difference between structuring servers using processes and application-level multiplexing

Discuss the benefits and drawbacks of each approach

8

What Is An Event?What Is An Event?

Some kind of notificationInterruptsSignalsPolling (via poll/select/etc)Callback (via function pointer)

Similarities?

9

“Reactive” Environments“Reactive” Environments

Windowing systemsNetwork-aware programsDrivers of all sorts

10

Traditional EnvironmentsTraditional Environments

One thing going on at a timeFinish that thing, go on to nextAny step can block indefinitelyResumption from blocking is simple – OS

provided

11

What Goes On In A Web Browser?

What Goes On In A Web Browser?

Drawing the current pageInline images

Translating machine names to IP addressesLaunching connectionsSending requestsGetting piecemeal responses, drawing images

User clicking to next link

12

Threads Versus EventsThreads Versus Events

One stack versus many stacksWhat happens on blocking operationsParallelismShared variablesState

13

Let’s Think Of StatesLet’s Think Of States

How many possible states are there?Take all pieces of informationDecide valid range for all piecesEnumerate

Can we reduce states?Some combinations invalidStill, lots of states

14

Really Reducing StatesReally Reducing States

Take all major pieces of programAdd extra tags to stateWhat do tags look like?

PositionCount #

15

State ExamplesState Examples

If-then-else3 states: start, then-clause, else-clause

For loop1 state + count

Why do we care?Resuming at the right state

16

Remember This Diagram?Remember This Diagram?

Read File

Send Data

Accept

Conn

Read

Request

Find

File

Send

Headerend

17

Structure of Event-Driven Programs

Structure of Event-Driven Programs

Lots of state machinesMaintaining information about each oneSome way of moving through statesAs few restrictions as possible on timing

18

The Real StructureThe Real Structure

While (1)Get eventDispatch event

Or, while loop in libraryEvent handlers in main program

19

DelaysDelays

Are delays possible?Interrupt handlers – generally notOtherwise? Depends on event rate

How to avoid delays?More events – asynchronous operationsWhat happens if no async support?

Fake it

20

Blocking StepsBlocking Steps

Read File

Send Data

Accept

Conn

Read

Request

Find

File

Send

Headerend

Network Blocking

Disk Blocking

21

Overcoming Disk Blocking States

Overcoming Disk Blocking States

Read File

Send Data

Accept

Conn

Read

Request

Find

File

Send

Headerend

Helper Helper

22

New Architecture - AMPEDNew Architecture - AMPED

Helpers are threads or processes

Read File

Send Data

Accept

Conn

Read

Request

Find

File

Send

Header

Event Dispatcher

Asymmetric Multiple Process Event Driven

Helper 1 Helper 2 Helper N

23

Caches in Flash Web Server

Caches in Flash Web Server

Read File

Send Data

Accept

Conn

Read

Request

Find

File

Send

Headerend

Pathname

Translation

Cache

Helper Helper

Mapped

File

Cache

Response

Header

Cache

top related