I/O Models. Kartik Gopalan

Similar documents
CONCURRENCY MODEL. UNIX Programming 2014 Fall by Euiseong Seo

COMP/ELEC 429/556 Introduction to Computer Networks

Εργαστήριο 9 I/O Multiplexing

Concurrent Programming. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

CS118 Discussion Week 2. Taqi

Any of the descriptors in the set {1, 4} have an exception condition pending

ISA 563: Fundamentals of Systems Programming

CONCURRENT PROGRAMMING. Lecture 5

Concurrent Servers Dec 2, 2009"

call connect call read call connect ret connect call fgets Client 2 blocks waiting to complete its connection request until after lunch!

Assignment 2 Group 5 Simon Gerber Systems Group Dept. Computer Science ETH Zurich - Switzerland

NETWORK AND SYSTEM PROGRAMMING. I/O Multiplexing: select and poll function

Network Programming TDC 561

CS118 Discussion 1A, Week 3. Zengwen Yuan Dodd Hall 78, Friday 10:00 11:50 a.m.

Three Basic Mechanisms for Creating Concurrent Flows. Systemprogrammering 2009 Föreläsning 10 Concurrent Servers. Process-Based Concurrent Server

UNIT III - APPLICATION DEVELOPMENT. TCP Echo Server

CSC209H Lecture 10. Dan Zingaro. March 18, 2015

Chapter 8: I/O functions & socket options

Network programming(ii) Lenuta Alboaie

Today: VM wrap-up Select (if time) Course wrap-up Final Evaluations

CISC2200 Threads Spring 2015

Concurrent Programming April 21, 2005

Global Employee Location Server

Project 1: A Web Server Called Liso

Iterative Servers The course that gives CMU its Zip! Iterative servers process one request at a time. Concurrent Servers

Concurrent Programming November 28, 2007

Network Games Part II. Architecture of Network Game

CSE 333 Lecture non-blocking I/O and select

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

Group-A Assignment No. 6

CS631 - Advanced Programming in the UNIX Environment Interprocess Communication II

ECE 650 Systems Programming & Engineering. Spring 2018

CSE 43: Computer Networks Structure, Threading, and Blocking. Kevin Webb Swarthmore College September 14, 2017

Concurrent Programming

CSE 333 Lecture fork, pthread_create, select

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song

Exception-Less System Calls for Event-Driven Servers

Redes de Computadores (RCOMP)

socketservertcl a Tcl extension for using SCM_RIGHTS By Shannon Noe - FlightAware

Example Questions for Midterm EE122, Fall 2008 EECS Berkeley

Redesde Computadores(RCOMP)

December 8, epoll: asynchronous I/O on Linux. Pierre-Marie de Rodat. Synchronous/asynch. epoll vs select and poll

Version Control with Git and What is there in Project 1 PALLABI GHOSH COMPUTER NETWORKS RECITATION 1

Concurrent Programming

Servers: Concurrency and Performance. Jeff Chase Duke University

Asynchronous Events on Linux

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files. Compiler vs.

Concurrent Programming

G Honors Operating Systems

Lecture 5 Overview! Last Lecture! This Lecture! Next Lecture! I/O multiplexing! Source: Chapter 6 of Stevens book!

Sockets and Parallel Computing. CS439: Principles of Computer Systems April 11, 2018

ECE 650 Systems Programming & Engineering. Spring 2018

I/O Multiplexing. Dec 2009

Announcement (1) Due date for PA3 is changed (~ next week) PA4 will also be started in the next class. Not submitted. Not scored

CSC209 Review. Yeah! We made it!

10. I/O System Library

CS 43: Computer Networks. 07: Concurrency and Non-blocking I/O Sep 17, 2018

Concurrent Programming

Architecture and Design of Distributed Dependable Systems TI-ARDI. POSA2: Reactor Architectural Pattern

Operating Systems. Review ENCE 360

PROCESSES AND THREADS THREADING MODELS. CS124 Operating Systems Winter , Lecture 8

A Socket Example. Haris Andrianakis & Angelos Stavrou George Mason University

Introduction to Socket Programming

CS4514 HELP Session 3. Concurrent Server (in APP) Using Go-Back-N (in DLL)

Motivation of VPN! Overview! VPN addressing and routing! Two basic techniques for VPN! ! How to guarantee privacy of network traffic?!

Overview. Last Lecture. This Lecture. Daemon processes and advanced I/O functions

Concurrent Programming

Concurrent Server Design Multiple- vs. Single-Thread

Embedded Systems Programming

serverbase.txt (1) Server Client1 (3) (2) Client2 Child Process1 Child Process2 Note: each child process keeps a separate copy of the DB.

Interprocess Communication Mechanisms

Interprocess Communication Mechanisms

Overview. Administrative. * HW 2 Grades. * HW 3 Due. Topics: * What are Threads? * Motivating Example : Async. Read() * POSIX Threads

Problem Set: Processes

Inter-process Communication using Pipes

Topics for this Week

Ports under 1024 are often considered special, and usually require special OS privileges to use.

Concurrent Programming is Hard! Concurrent Programming. Reminder: Iterative Echo Server. The human mind tends to be sequential

The Reactor An Object-Oriented Wrapper for Event-Driven Port Monitoring and Service Demultiplexing (Part 1 of 2)

CS 33. More Network Programming. CS33 Intro to Computer Systems XXXI 1 Copyright 2017 Thomas W. Doeppner. All rights reserved.

33. Event-based Concurrency

Contents. PA1 review and introduction to PA2. IPC (Inter-Process Communication) Exercise. I/O redirection Pipes FIFOs

Comparing and Measuring Network Event Dispatch Mechanisms in Virtual Hosts

Delayline A Wide-Area Network Emulation Tool

Prepared by Prof. Hui Jiang Process. Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University

Introduction to Asynchronous Programming Fall 2014

Project 3. Reliable Data Transfer over UDP. NTU CSIE Computer Networks 2011 Spring

Process. Prepared by Prof. Hui Jiang Dept. of EECS, York Univ. 1. Process in Memory (I) PROCESS. Process. How OS manages CPU usage? No.

Network Programming in C: The Berkeley Sockets API. Networked Systems 3 Laboratory Sessions

Lecture #23 Concurrent Programming

Pipes and FIFOs. Woo-Yeong Jeong Computer Systems Laboratory Sungkyunkwan University

Inter-Process Communication. Disclaimer: some slides are adopted from the book authors slides with permission 1

Inter-process communication (IPC)

Computer Systems Laboratory Sungkyunkwan University

3.1 Introduction. Computers perform operations concurrently

Lecture 24. Thursday, November 19 CS 375 UNIX System Programming - Lecture 24 1

Concurrent Server Using Selective Repeat Data Link Layer

Client Server Computing

Processes. Process Concept

Transcription:

I/O Models Kartik Gopalan

Types of Concurrency True Concurrency (multiple processes or threads) Multi-processor machines Child processes/threads execute in parallel. Multi-process (forking) servers If one child server blocks, another executes Multi-threaded servers If one thread blocks, another executes. Only if threads supported by kernel Apparent Concurrency Single process does multiplexing among multiple clients. E.g. I/O multiplexing with select(). Multi-threaded Server (again!) If threads implemented at user level. 2

True Concurrency: Forking Concurrent Servers Listening Server Child Server 1 Client 1 Child Server 2 Client 2 3

Apparent Concurrency Non-Forking Concurrent Server Concurrent Server select() listenfd Sockets fd1 fd2 fd3 fd4 fd5 Remote Clients C1 C2 C3 C4 C5 4

I/O Models Blocking I/O Non-blocking I/O I/O multiplexing select() Signal driven I/O Asynchronous I/O 5

Two steps in data reception User Level System Call Interface User Buffer 2. Copy Kernel Level 1.Data Arrival (local) Kernel Buffer 1. Data Arrival (network) Overheads: Context switching, Data copying 6

Blocking I/O Time Application read( ) / recv( ) System call Operating system No data ready Wait for data Process blocks data ready Copy data Copy data to user Read data Return ok Copy complete 7

Non-Blocking I/O (polling) Application read()/recv() System call Operating system No data ready EWOULDBLOCK Time read()/recv() System call No data ready EWOULDBLOCK read()/recv() System call data ready Copy data Process blocks Copy data to user Read data Return ok Copy complete 8

I/O Multiplexing Concurrent Server select() listen socket descriptor Sockets or Files descriptors fd1 fd2 fd3 fd4 fd5 Or Pipe descriptors Remote Clients Or files Or pipes C1 C2 F3 F4 P5 9

I/O Multiplexing Application Operating system select() on multiple fds System call No data ready Time Process blocks read()/recv() Return readable System call data ready Copy data Wait for data on any fd Process blocks Copy data to user Read data Return ok Copy complete 10

Signal driven I/O Application Operating system Time Establish SIGIO Signal handler Process continues System call return No data ready Wait for data Signal Handler read()/recv() Deliver SIGIO System call data ready Copy data Process blocks Copy data to user Read data Return ok Copy complete 11

Asynchronous I/O Application aio_read() System call return Operating system No data ready Time Wait for data Process continues data ready Copy data Copy data to user Signal handler Read data Deliver signal specified in aio_read() Copy complete 12

I/O Multiplexing Example of Event-oriented programming

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, multiple socket descriptors When I/O on any one descriptor can result in blocking 14

Non-forking concurrent server Concurrent Server select() listen socket Files/ Sockets fd1 fd2 fd3 fd4 fd5 Clients C1 C2 C3 C4 C5 15

select() call Allows a process to wait for an event to occur on any one of its descriptors. Types of event ready for read ready for write Exception condition 16

select() call int select( int maxfdp1, /* max. fd + 1 */ fd_set *readfds, /* read ready? */ fd_set *writefds, /* write ready? */ fd_set *exceptfds, /* exceptions? */ struct timeval *timeout); struct timeval { long tv_sec; /* seconds */ long tv_usec; /* microseconds */ } 17

struct fd_set Set of descriptors that we want to wait on for events. Typically holds 256 descriptor states. Manipulation macros void FD_ZERO(fd_set *fds) void FD_SET (int fd, fd_set *fds) void FD_CLR (int fd, fd_set *fds) int FD_ISSET(int fd, fd_set *fds) 18

Non-forking Concurrent Server fdset rdset, wrset; int listenfd, connfd1, connfd2; int maxfdp1; Connection establishment etc. /* initialize */ FD_ZERO(&rdset); FD_ZERO(&wrset); 19

for( ;; ) { FD_SET(connfd1, &rdset); FD_SET(connfd2, &wrset); FD_SET(listenfd, &rdset); maxfdp1 = max(connfd1, connfd2, listenfd) + 1; /* wait for some event */ Select(maxfdp1, &rdset, &wrset, NULL, NULL); } if( FD_ISSET(connfd1, &rdset) ) { Read data from connfd1 } if( FD_ISSET(connfd2, &wrset) ) { Write data to connfd2 } if( FD_ISSET(listenfd, &rdset) { Process a new connection } 20