Event-Driven Programming - PowerPoint PPT Presentation

About This Presentation
Title:

Event-Driven Programming

Description:

Discuss the difference between standard programming styles and event-driven programming ... Discuss the benefits and drawbacks of each approach. 7. What Is An Event? ... – PowerPoint PPT presentation

Number of Views:22
Avg rating:3.0/5.0
Slides: 26
Provided by: valued85
Category:

less

Transcript and Presenter's Notes

Title: Event-Driven Programming


1
Event-Driven Programming
  • Vivek Pai
  • Dec 5, 2002

2
GedankenBits
  • 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/overhead

3
Extra Project
  • We need to agree on it
  • One-page proposal
  • Idea, implementation, measurement
  • Report (10 pages) due on Deans Date
  • Max boost of 2/3 of a letter grade

4
Project 6
  • Several goals
  • Performance improvement via caching
  • Dynamic adjustment to load
  • Master/slave or symmetric programming
  • Due on Deans Date
  • Extra credit 4 points (20 base)

5
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

6
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

7
What Is An Event?
  • Some kind of notification
  • Interrupts
  • Signals
  • Polling (via poll/select/etc)
  • Callback (via function pointer)
  • Similarities?

8
Reactive Environments
  • Windowing systems
  • Network-aware programs
  • Drivers of all sorts

9
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

10
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

11
Threads Versus Events
  • One stack versus many stacks
  • What happens on blocking operations
  • Parallelism
  • Shared variables
  • State

12
Lets 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

13
Really Reducing States
  • Take all major pieces of program
  • Add extra tags to state
  • What do tags look like?
  • Position
  • Count

14
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

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

17
The Real Structure
  • While (1)
  • Get event
  • Dispatch event
  • Or, while loop in library
  • Event handlers in main program

18
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

19
Select( ) System Call
  • int 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)

20
(No Transcript)
21
Select Description
  • DESCRIPTION
  • 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.

22
Blocking Steps
Disk Blocking
Read File Send Data
Accept Conn
Read Request
Find File
Send Header
end
Network Blocking
23
Overcoming Disk Blocking States
Read File Send Data
Accept Conn
Read Request
Find File
Send Header
end
Helper
Helper
24
New Architecture - AMPED
Asymmetric Multiple Process Event Driven
Read File Send Data
Accept Conn
Read Request
Find File
Send Header
Event Dispatcher
  • Helpers are threads or processes

25
Caches in Flash Web Server
Read File Send Data
Accept Conn
Read Request
Find File
Send Header
end
Pathname Translation Cache
Mapped File Cache
Response Header Cache
Helper
Helper
Write a Comment
User Comments (0)
About PowerShow.com