Download presentation
Presentation is loading. Please wait.
Published byNyah Pile Modified over 9 years ago
1
Event-Driven Programming Vivek Pai Dec 4, 2001
2
2 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? How many albums does the Wu Tang Clan have? What is Ginger?
3
3 A Random Aside What do these companies have in common VA Linux, Penguin Computing RLX Technologies, Fibercycle HP, Compaq Dell, IBM
4
4 Mechanics Project 3 grading in progress Project 4 grading in progress All feedback questions answered One mail dropped – extra project proposals Speaking of which We need to agree on a one-page proposal
5
5 Project 5 Tyranny of the majority Several goals Performance improvement via caching Dynamic adjustment to load Master/slave or symmetric programming Probably due on Dean’s Date Extra credit: 6 points (15 base)
6
6 Another Random Aside You may want to read Flash: An Efficient and Portable Web Server Available from my home page Caveat: far more complicated than Project 5
7
7 Official 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
8 What Is An Event? Some kind of notification Interrupts Signals Polling (via poll/select/etc) Callback (via function pointer) Similarities?
9
9 “Reactive” Environments Windowing systems Network-aware programs Drivers of all sorts
10
10 Traditional Environments One thing going on at a time Finish that thing, go on to next Any step can block indefinitely Resumption from blocking is simple – OS provided
11
11 What Goes On In A Web Browser? Drawing the current page Inline images Translating machine names to IP addresses Launching connections Sending requests Getting piecemeal responses, drawing images User clicking to next link
12
12 Threads Versus Events One stack versus many stacks What happens on blocking operations Parallelism Shared variables State
13
13 Let’s Think Of States How many possible states are there? Take all pieces of information Decide valid range for all pieces Enumerate Can we reduce states? Some combinations invalid Still, lots of states
14
14 Really Reducing States Take all major pieces of program Add extra tags to state What do tags look like? Position Count #
15
15 State Examples If-then-else 3 states: start, then-clause, else-clause For loop 1 state + count Why do we care? Resuming at the right state
16
16 Remember This Diagram? Read File Send Data Accept Conn Read Request Find File Send Header end
17
17 Structure of Event-Driven Programs Lots of state machines Maintaining information about each one Some way of moving through states As few restrictions as possible on timing
18
18 The Real Structure While (1) Get event Dispatch event Or, while loop in library Event handlers in main program
19
19 Delays Are delays possible? Interrupt handlers – generally not Otherwise? Depends on event rate How to avoid delays? More events – asynchronous operations What happens if no async support? Fake it
20
20 Blocking Steps Read File Send Data Accept Conn Read Request Find File Send Header end Network Blocking Disk Blocking
21
21 Overcoming Disk Blocking States Read File Send Data Accept Conn Read Request Find File Send Header end Helper
22
22 New 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 1Helper 2Helper N
23
23 Caches in Flash Web Server Read File Send Data Accept Conn Read Request Find File Send Header end Pathname Translation Cache Helper Mapped File Cache Response Header Cache
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.