DOC PREVIEW
Princeton COS 318 - Event-Driven Programming

This preview shows page 1-2-24-25 out of 25 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 25 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 25 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 25 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 25 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 25 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Event-Driven ProgrammingGedankenBitsExtra ProjectProject 6Another Random AsideOfficial GoalsWhat Is An Event?“Reactive” EnvironmentsTraditional EnvironmentsWhat Goes On In A Web Browser?Threads Versus EventsLet’s Think Of StatesReally Reducing StatesState ExamplesRemember This Diagram?Structure of Event-Driven ProgramsThe Real StructureDelaysSelect( ) System CallPowerPoint PresentationSelect DescriptionBlocking StepsOvercoming Disk Blocking StatesNew Architecture - AMPEDCaches in Flash Web ServerEvent-Driven ProgrammingVivek PaiDec 5, 20022GedankenBitsGedankenBitsWhat does a raw bit cost?IDE40GB: $100120GB: $18032MB USB Pen: $38FireWire: 60GB: $205120GB: $280USB:40GB: $140120GB: $218What does a managed bit cost?NAS320GB: $3400 (Dell)7.5TB: $300K (Zambeel)What does a person cost?$100K salary + $50K benefits/overhead3Extra ProjectExtra ProjectWe need to agree on itOne-page proposalIdea, implementation, measurementReport (~10 pages) due on Dean’s DateMax boost of 2/3 of a letter grade4Project 6Project 6Several goalsPerformance improvement via cachingDynamic adjustment to loadMaster/slave or symmetric programmingDue on Dean’s DateExtra credit: 4 points (20 base)5Another Random AsideAnother 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 56Official 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 approach7What Is An Event?What Is An Event?Some kind of notificationInterruptsSignalsPolling (via poll/select/etc)Callback (via function pointer)Similarities?8“Reactive” Environments“Reactive” EnvironmentsWindowing systemsNetwork-aware programsDrivers of all sorts9Traditional EnvironmentsTraditional 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 provided10What Goes On In A Web Browser?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 link11Threads Versus EventsThreads Versus EventsOne stack versus many stacksWhat happens on blocking operationsParallelismShared variablesState12Let’s Think Of StatesLet’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 states13Really Reducing StatesReally Reducing StatesTake all major pieces of programAdd extra tags to stateWhat do tags look like?PositionCount #14State ExamplesState ExamplesIf-then-else3 states: start, then-clause, else-clauseFor loop1 state + countWhy do we care?Resuming at the right state15Remember This Diagram?Remember This Diagram?Read FileSend DataAcceptConnReadRequestFindFileSendHeaderend16Structure of Event-Driven ProgramsStructure 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 timing17The Real StructureThe Real StructureWhile (1)Get eventDispatch eventOr, while loop in libraryEvent handlers in main program18DelaysDelays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 it19Select( ) System CallSelect( ) System Callint select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);FD_SET(fd, &fdset);FD_CLR(fd, &fdset);FD_ISSET(fd, &fdset);FD_ZERO(&fdset);2021Select DescriptionSelect DescriptionDESCRIPTION Select() examines the I/O descriptor sets whose addresses are passed in readfds, writefds, and exceptfds to see if some of their descriptors are ready for reading, are ready for writing, or have an exceptional condition pending, respectively. The only exceptional condition detectable is out-of-band data received on a socket. The first nfds descriptors are checked in each set; i.e., the descriptors from 0 through nfds-1 in the descriptor sets are examined. On return, select() replaces the given descriptor sets with subsets consisting of those descriptors that are ready for the requested operation. Select() returns the total number of ready descriptors in all the sets. The descriptor sets are stored as bit fields in arrays of integers. The following macros are provided for manipulating such descriptor sets: FD_ZERO(&fdset) initializes a descriptor set fdset to the null set. FD_SET(fd, &fdset) includes a particular descriptor fd in fdset. FD_CLR(fd, &fdset) removes fd from fdset. FD_ISSET(fd, &fdset) is non- zero if fd is a member of fdset, zero otherwise. The behavior of these macros is undefined if a descriptor value is less than zero or greater than or equal to FD_SETSIZE, which is normally at least equal to the maximum number of descriptors supported by the system.22Blocking StepsBlocking StepsRead FileSend DataAcceptConnReadRequestFindFileSendHeaderendNetwork BlockingDisk Blocking23Overcoming Disk Blocking StatesOvercoming Disk Blocking StatesRead FileSend DataAcceptConnReadRequestFindFileSendHeaderendHelper Helper24New Architecture - AMPEDNew Architecture - AMPEDHelpers are threads or processesRead FileSend DataAcceptConnReadRequestFindFileSendHeaderEvent DispatcherAsymmetric Multiple Process Event DrivenHelper 1 Helper 2 Helper N25Caches in Flash Web ServerCaches in Flash Web ServerRead FileSend DataAcceptConnReadRequestFindFileSendHeaderendPathnameTranslationCacheHelper


View Full Document

Princeton COS 318 - Event-Driven Programming

Documents in this Course
Overview

Overview

25 pages

Deadlocks

Deadlocks

25 pages

lectute 2

lectute 2

28 pages

Lecturel

Lecturel

24 pages

Real mode

Real mode

49 pages

Lecture 2

Lecture 2

54 pages

lecture 5

lecture 5

27 pages

Load more
Download Event-Driven Programming
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Event-Driven Programming and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Event-Driven Programming 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?