event-driven programming

23
Event-Driven Programming Vivek Pai Dec 4, 2001

Upload: saad

Post on 07-Jan-2016

43 views

Category:

Documents


0 download

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

Page 1: Event-Driven Programming

Event-Driven Programming

Vivek PaiDec 4, 2001

Page 2: Event-Driven Programming

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?

Page 3: Event-Driven Programming

3

A Random AsideA Random Aside

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

Page 4: Event-Driven Programming

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

Page 5: Event-Driven Programming

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)

Page 6: Event-Driven Programming

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

Page 7: Event-Driven Programming

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

Page 8: Event-Driven Programming

8

What Is An Event?What Is An Event?

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

Similarities?

Page 9: Event-Driven Programming

9

“Reactive” Environments“Reactive” Environments

Windowing systemsNetwork-aware programsDrivers of all sorts

Page 10: Event-Driven Programming

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

Page 11: Event-Driven Programming

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

Page 12: Event-Driven Programming

12

Threads Versus EventsThreads Versus Events

One stack versus many stacksWhat happens on blocking operationsParallelismShared variablesState

Page 13: Event-Driven Programming

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

Page 14: Event-Driven Programming

14

Really Reducing StatesReally Reducing States

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

PositionCount #

Page 15: Event-Driven Programming

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

Page 16: Event-Driven Programming

16

Remember This Diagram?Remember This Diagram?

Read File

Send Data

Accept

Conn

Read

Request

Find

File

Send

Headerend

Page 17: Event-Driven Programming

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

Page 18: Event-Driven Programming

18

The Real StructureThe Real Structure

While (1)Get eventDispatch event

Or, while loop in libraryEvent handlers in main program

Page 19: Event-Driven Programming

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

Page 20: Event-Driven Programming

20

Blocking StepsBlocking Steps

Read File

Send Data

Accept

Conn

Read

Request

Find

File

Send

Headerend

Network Blocking

Disk Blocking

Page 21: Event-Driven Programming

21

Overcoming Disk Blocking States

Overcoming Disk Blocking States

Read File

Send Data

Accept

Conn

Read

Request

Find

File

Send

Headerend

Helper Helper

Page 22: Event-Driven Programming

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

Page 23: Event-Driven Programming

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