1 / 23

Event-Driven Programming

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?

saad
Download Presentation

Event-Driven Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Event-Driven Programming Vivek Pai Dec 4, 2001

  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. A Random Aside • What do these companies have in common • VA Linux, Penguin Computing • RLX Technologies, Fibercycle • HP, Compaq • Dell, IBM

  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. 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. 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. 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. What Is An Event? • Some kind of notification • Interrupts • Signals • Polling (via poll/select/etc) • Callback (via function pointer) • Similarities?

  9. “Reactive” Environments • Windowing systems • Network-aware programs • Drivers of all sorts

  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. 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. Threads Versus Events • One stack versus many stacks • What happens on blocking operations • Parallelism • Shared variables • State

  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. Really Reducing States • Take all major pieces of program • Add extra tags to state • What do tags look like? • Position • Count #

  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. Remember This Diagram? Accept Conn Read Request Find File Send Header Read File Send Data end

  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. The Real Structure While (1) Get event Dispatch event • Or, while loop in library • Event handlers in main program

  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. Blocking Steps Disk Blocking Accept Conn Read Request Find File Send Header Read File Send Data end Network Blocking

  21. Overcoming Disk Blocking States Accept Conn Read Request Find File Send Header Read File Send Data end Helper Helper

  22. Helper 1 Helper 2 Helper N New Architecture - AMPED Asymmetric Multiple Process Event Driven Helpers are threads or processes Accept Conn Read Request Find File Send Header Read File Send Data Event Dispatcher

  23. Caches in Flash Web Server Accept Conn Read Request Find File Send Header Read File Send Data end Pathname Translation Cache Response Header Cache Mapped File Cache Helper Helper

More Related