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:

Slides:



Advertisements
Similar presentations
Sockets Tutorial Ross Shaull cs146a What we imagine Network request… response… The packets that comprise your request are orderly.
Advertisements

CHAPTER 15 WEBPAGE OPTIMIZATION. LEARNING OBJECTIVES How to test your web-page performance How browser and server interactions impact performance What.
R4 Dynamically loading processes. Overview R4 is closely related to R3, much of what you have written for R3 applies to R4 In R3, we executed procedures.
Event-Driven Programming Vivek Pai Dec 4, GedankenEvents  Enron – bad news all around  What are these numbers: $1B, $100B, $80B, $200M  Korean.
I/O Multiplexing Road Map: 1. Motivation 2. Description of I/O multiplexing 3. Scenarios to use I/O multiplexing 4. I/O Models  Blocking I/O  Non-blocking.
Daemon Processes Long lived utility processes Often started at system boot and ended when system shuts down Run in the background with no controlling terminal.
Flash: An efficient and portable Web server Authors: Vivek S. Pai, Peter Druschel, Willy Zwaenepoel Presented at the Usenix Technical Conference, June.
Today’s topic Issues about sending structures with TCP. Server design alternatives: concurrent server and multiplexed server. I/O multiplexing.
Jump to first page Flash An efficient and portable Web server presented by Andreas Anagnostatos CSE 291 Feb. 2, 2000 Vivek S. Pai Peter Druschel Willy.
Advanced Sockets Amit Mondal TA, Intro to Networking Jan 22, 2009 Recital 3 Introduction to Networking Instructor: Prof. Aleksandar Kuzmanovic.
Page: 1 Director 1.0 TECHNION Department of Computer Science The Computer Communication Lab (236340) Summer 2002 Submitted by: David Schwartz Idan Zak.
Precept 3 COS 461. Concurrency is Useful Multi Processor/Core Multiple Inputs Don’t wait on slow devices.
Sockets and concurrency Spring 2010, Recitation 3 Your Awesome TAs.
Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.
Programming with Berkeley Sockets Presented by Chris GauthierDickey Written by Daniel Stutzbach (I think!) for CIS 432/532 Useful References: ● man pages.
1 Data Communications and Networking Socket Programming Part II: Design of Server Software Reference: Internetworking with TCP/IP, Volume III Client-Server.
1 Chapter 8 Virtual Memory Virtual memory is a storage allocation scheme in which secondary memory can be addressed as though it were part of main memory.
Elementary Data Types Scalar Data Types Numerical Data Types Other
Introduction to Project 1 Web Client and Server Jan 2006.
CSCI2413 Lecture 6 Operating Systems Memory Management 2 phones off (please)
Basic Networking & Interprocess Communication Vivek Pai Nov 27, 2001.
Select The select function determines the status of one or more sockets, waiting if necessary, to perform synchronous I/O. int select( int nfds, fd_set*
IP Multiplexing Ying Zhang EECS 489 W07.
Basics of Operating Systems March 4, 2001 Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard.
Apache Architecture. How do we measure performance? Benchmarks –Requests per Second –Bandwidth –Latency –Concurrency (Scalability)
File System. NET+OS 6 File System Architecture Design Goals File System Layer Design Storage Services Layer Design RAM Services Layer Design Flash Services.
Memory Management ◦ Operating Systems ◦ CS550. Paging and Segmentation  Non-contiguous memory allocation  Fragmentation is a serious problem with contiguous.
Data Structures Week 5 Further Data Structures The story so far  We understand the notion of an abstract data type.  Saw some fundamental operations.
Introduction to Processes CS Intoduction to Operating Systems.
Threads Many software packages are multi-threaded Web browser: one thread display images, another thread retrieves data from the network Word processor:
CHAPTER 3 TOP LEVEL VIEW OF COMPUTER FUNCTION AND INTERCONNECTION
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Threads and Processes.
Processes and Threads Processes have two characteristics: – Resource ownership - process includes a virtual address space to hold the process image – Scheduling/execution.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Socket Models Different ways to manage your connections.
Operating Systems Lecture 7 OS Potpourri Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing Liu School of Software.
Scalable Kernel Performance for Internet Servers under Realistic Loads. Gaurav Banga, etc... Western Research Lab : Research Report 1998/06 (Proceedings.
TELE 402 Lecture 4: I/O multi … 1 Overview Last Lecture –TCP socket and Client-Server example –Source: Chapters 4&5 of Stevens’ book This Lecture –I/O.
1 COMP/ELEC 429/556 Introduction to Computer Networks Creating a Network Application Some slides used with permissions from Edward W. Knightly, T. S. Eugene.
I/O Multiplexing. TCP Echo Client: I/O operation is sequential !! tcpcliserv/tcpcli01.c: lib/str_cli.c: TCP Client TCP Server stdin stdout fgets fputs.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming.  To allocate scarce memory.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Process-Concept.
I/O Multiplexing. What is I/O multiplexing? When an application needs to handle multiple I/O descriptors at the same time –E.g. file and socket descriptors,
Operating Systems CSE 411 CPU Management Sept Lecture 10 Instructor: Bhuvan Urgaonkar.
The Client-Server Model And the Socket API. Client-Server (1) The datagram service does not require cooperation between the peer applications but such.
Single Process, Concurrent, Connection-Oriented Servers (TCP) (Chapter 12)
University of Washington Exceptional Control Flow The Hardware/Software Interface CSE351 Winter 2013.
LAIO: Lazy Asynchronous I/O For Event Driven Servers Khaled Elmeleegy Alan L. Cox.
Threads versus Events CSE451 Andrew Whitaker. This Class Threads vs. events is an ongoing debate  So, neat-and-tidy answers aren’t necessarily available.
Pintos project 3: Virtual Memory Management
CSCI 156: Lab 11 Paging. Our Simple Architecture Logical memory space for a process consists of 16 pages of 4k bytes each. Your program thinks it has.
Socket Programming. Computer Science, FSU2 Interprocess Communication Within a single system – Pipes, FIFOs – Message Queues – Semaphores, Shared Memory.
File Systems - Part I CS Introduction to Operating Systems.
Lectures 8 & 9 Virtual Memory - Paging & Segmentation System Design.
ECE 456 Computer Architecture Lecture #9 – Input/Output Instructor: Dr. Honggang Wang Fall 2013.
University of Washington Roadmap 1 car *c = malloc(sizeof(car)); c->miles = 100; c->gals = 17; float mpg = get_mpg(c); free(c); Car c = new Car(); c.setMiles(100);
More Project 1 and HW 1 stuff! Athula Balachandran Wolfgang Richter
Introduction to threads
Threads vs. Events SEDA – An Event Model 5204 – Operating Systems.
Review: TCP Client-Server Interaction
CSCI 315 Operating Systems Design
Advanced Sockets Introduction to Networking
Socket Programming.
Lecture Topics: 11/1 General Operating System Concepts Processes
CSE451 Virtual Memory Paging Autumn 2002
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
Mr. M. D. Jamadar Assistant Professor
Threads CSE 2431: Introduction to Operating Systems
Chapter 13: I/O Systems “The two main jobs of a computer are I/O and [CPU] processing. In many cases, the main job is I/O, and the [CPU] processing is.
Presentation transcript:

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 Dean’s 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 Dean’s 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 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

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

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

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

24 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

25 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