Socket Models Different ways to manage your connections.

Slides:



Advertisements
Similar presentations
Nonblocking I/O Blocking vs. non-blocking I/O
Advertisements

IEG4180 Tutorial 3 Shaoquan Zhang. Announcement The deadline of the project 1 is extended to 11pm, 12/02/2011 Follow the requirement of the marking scheme.
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.
Today’s topic Issues about sending structures with TCP. Server design alternatives: concurrent server and multiplexed server. I/O multiplexing.
Computer Networks Sockets. Sockets and the OS F An end-point for Internet connection –What the application “plugs into” –OS provides Application Programming.
Interrupts What is an interrupt? What does an interrupt do to the “flow of control” Interrupts used to overlap computation & I/O – Examples would be console.
Advanced Sockets Amit Mondal TA, Intro to Networking Jan 22, 2009 Recital 3 Introduction to Networking Instructor: Prof. Aleksandar Kuzmanovic.
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.
I/O Hardware n Incredible variety of I/O devices n Common concepts: – Port – connection point to the computer – Bus (daisy chain or shared direct access)
3.5 Interprocess Communication Many operating systems provide mechanisms for interprocess communication (IPC) –Processes must communicate with one another.
Computer Science Scalability of Linux Event-Dispatch Mechanisms Abhishek Chandra University of Massachusetts Amherst David Mosberger Hewlett Packard Labs.
1 Data Communications and Networking Socket Programming Part II: Design of Server Software Reference: Internetworking with TCP/IP, Volume III Client-Server.
3.5 Interprocess Communication
1 School of Computing Science Simon Fraser University CMPT 300: Operating Systems I Ch 4: Threads Dr. Mohamed Hefeeda.
Threads CSCI 444/544 Operating Systems Fall 2008.
1 Nonblocking I/O Nonblocking reads and writes Buffers enabling overlapped nonblocking I/O Nonblocking connect.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Objectives Thread definitions and relationship to process Multithreading.
Lecture 8 UDP Sockets & I/O Multiplexing
I/O Systems CSCI 444/544 Operating Systems Fall 2008.
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*
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
IP Multiplexing Ying Zhang EECS 489 W07.
SEDA: An Architecture for Well-Conditioned, Scalable Internet Services
Windows audio architecture Win MM Application DirectSound Application SysAudio.SYS Kmixer.SYS WinMM.DLLDSound.DLL Device Drive Container USB Device Driver.
Socket Programming References: redKlyde ’ s tutorial set Winsock2 for games (gamedev.net)
Programming Network Servers Topic 6, Chapters 21, 22 Network Programming Kansas State University at Salina.
Discussion Week 8 TA: Kyle Dewey. Overview Exams Interrupt priority Direct memory access (DMA) Different kinds of I/O calls Caching What I/O looks like.
Chapter 13: I/O Systems Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Jan 2, 2005 Chapter 13: I/O Systems I/O Hardware.
Hardware Definitions –Port: Point of connection –Bus: Interface Daisy Chain (A=>B=>…=>X) Shared Direct Device Access –Controller: Device Electronics –Registers:
I/O Systems I/O Hardware Application I/O Interface
Operating Systems Recitation 9, May 19-20, Iterative server Handle one connection request at a time. Connection requests stored in queue associated.
Windows Network Programming ms-help://MS.MSDNQTR.2004JAN.1033/winsock/winsock/windows_sockets_start_page_2.htm 井民全.
Nonblocking I/O Blocking vs. non-blocking I/O Nonblocking input, output, accept, and connect Readings –UNP Ch16 1.
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.
Sockets in C. 2 References Manual Pages %torch man –s 3socket … Socket, bind, listen, etc. %torch man –s 3c select Resources section of website.
1 I/O Multiplexing We often need to be able to monitor multiple descriptors:We often need to be able to monitor multiple descriptors: –a generic TCP client.
CSCE 515: Computer Network Programming Select Wenyuan Xu Department of Computer Science and Engineering.
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.
CE Operating Systems Lecture 13 Linux/Unix interprocess communication.
Synchronization Methods in Message Passing Model.
Lecture 8 Page 1 CS 111 Online Other Important Synchronization Primitives Semaphores Mutexes Monitors.
Events in General. Agenda Post/wait technique I/O multiplexing Asynchronous I/O Signal-driven I/O Database events Publish/subscribe model Local vs. distributed.
Single Process, Concurrent, Connection-Oriented Servers (TCP) (Chapter 12)
Silberschatz, Galvin and Gagne  Operating System Concepts Six Step Process to Perform DMA Transfer.
Silberschatz, Galvin and Gagne ©2009 Edited by Khoury, 2015 Operating System Concepts – 9 th Edition, Chapter 13: I/O Systems.
Threads versus Events CSE451 Andrew Whitaker. This Class Threads vs. events is an ongoing debate  So, neat-and-tidy answers aren’t necessarily available.
Socket Programming. Computer Science, FSU2 Interprocess Communication Within a single system – Pipes, FIFOs – Message Queues – Semaphores, Shared Memory.
I/O Multiplexing Chap 6. I/O Models  Blocking I/O Model  Nonblocking I/O Model  I/O Multiplexing Model  Signal Driven I/O Model  Asynchronous I/O.
Silberschatz, Galvin, and Gagne  Applied Operating System Concepts Module 12: I/O Systems I/O hardwared Application I/O Interface Kernel I/O.
Operating System Concepts
SPL/2010 Reactor Design Pattern 1. SPL/2010 Overview ● blocking sockets - impact on server scalability. ● non-blocking IO in Java - java.niopackage ●
Lecturer 3: Processes multithreaded Operating System Concepts Process Concept Process Scheduling Operation on Processes Cooperating Processes Interprocess.
@Yuan Xue CS 283Computer Networks Spring 2013 Instructor: Yuan Xue.
More Project 1 and HW 1 stuff! Athula Balachandran Wolfgang Richter
Chapter 13: I/O Systems.
Client-Server Communication
Module 12: I/O Systems I/O hardware Application I/O Interface
Operating Systems Review ENCE 360.
Chapter 4: Multithreaded Programming
CSCI 315 Operating Systems Design
Lecture 4 Socket Programming Issues
I/O Systems I/O Hardware Application I/O Interface
Operating System Concepts
13: I/O Systems I/O hardwared Application I/O Interface
CS703 - Advanced Operating Systems
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
I/O Multiplexing We often need to be able to monitor multiple descriptors: a generic TCP client (like telnet) need to be able to handle unexpected situations,
Module 12: I/O Systems I/O hardwared Application I/O Interface
Presentation transcript:

Socket Models Different ways to manage your connections

Agenda Modes Modes Blocking/Non-Blocking Blocking/Non-Blocking Models Models Blocking Blocking Select Variations Select Variations Select Select WSAAsyncSelect WSAAsyncSelect WSAEventSelect WSAEventSelect Overlapped I/O Overlapped I/O I/O Completion Port I/O Completion Port

Socket Modes To Block or Not to Block

Blocking Mode The default The default Easy to implement Easy to implement A call to send() or recv() only returns when calling conditions met. A call to send() or recv() only returns when calling conditions met.

Non-Blocking Must set with I/O control Must set with I/O control Ioctlsocket(sock,FIONBIO,true); Ioctlsocket(sock,FIONBIO,true); Nothing blocks (i.e., send, recv, close,…) Nothing blocks (i.e., send, recv, close,…) Returns WSAEWOULDBLOCK if not immediately successful Returns WSAEWOULDBLOCK if not immediately successful Essentially turns into a polling model Essentially turns into a polling model You must handle spinning by sleeping You must handle spinning by sleeping Only use in a non-thread environment Only use in a non-thread environment

Modes vs. Model Modes can be used with any Model Modes can be used with any Model Models cover several general issues Models cover several general issues How you discover when a socket is ready How you discover when a socket is ready Has data (recv) Has data (recv) Has room for data (send) Has room for data (send) How data is copied from Kernel to your buffer How data is copied from Kernel to your buffer Number of threads Number of threads

I/O Models BlockingSelect Overlapped I/O Completion Port

Blocking Easy Implementation Easy Implementation X-Platform X-Platform No event notification to avoid blocking necessitates multiple threads. No event notification to avoid blocking necessitates multiple threads. 2 Threads for each socket else starve 2 Threads for each socket else starve Send thread Send thread Receive thread Receive thread Poor scaling performance due to # of threads Poor scaling performance due to # of threads Good enough for most game clients Good enough for most game clients Socket calls are blocking by default Socket calls are blocking by default

Select Working with multiple sockets Tell me when you’re ready select (…) select (…) File Descriptor Sets (FD_SET) File Descriptor Sets (FD_SET) Read: sockets to check for pending data Read: sockets to check for pending data Write: sockets to check for writable Write: sockets to check for writable OOB: same as read for OOB data OOB: same as read for OOB data Macros FD_CLR(), FD_ISSET(), FD_SET(), FD_ZERO() Macros FD_CLR(), FD_ISSET(), FD_SET(), FD_ZERO() Always clear and set your FD_SET prior to select (even if using same descriptors). Always clear and set your FD_SET prior to select (even if using same descriptors). Limited to 64 sockets by winsock.h but can be overridden. Limited to 64 sockets by winsock.h but can be overridden. X-Platform X-Platform Additional limitations by O/S Additional limitations by O/S Only checks state. Still need to process the data with blocking call which won’t block because you’ve just been told it’s ready. Only checks state. Still need to process the data with blocking call which won’t block because you’ve just been told it’s ready. WSAAsyncSelect (…) WSAAsyncSelect (…) Notified via window message Notified via window message Windows only Windows only WSAEventSelect (…) WSAEventSelect (…) Notified via Event Object i.e., a signal Notified via Event Object i.e., a signal Windows only Windows only These methods provide asynchronous notification, not async data transfer as does overlapped model These methods provide asynchronous notification, not async data transfer as does overlapped model

Overlapped I/O Tell me when data is in my buffer. Async data transfer Async data transfer Scales very well Scales very well Max 64 sockets per thread Max 64 sockets per thread A little complexity overhead A little complexity overhead All socket requests return immediately. All socket requests return immediately. Process with event objects or completion routines. Process with event objects or completion routines. Window NT based O/S only (NT, 2000, xp) Window NT based O/S only (NT, 2000, xp)

I/O Completion Ports Best Scalability Best Scalability One thread per CPU One thread per CPU Unlimited sockets per thread Unlimited sockets per thread Complex setup Complex setup Uses overlapped I/O constructs Uses overlapped I/O constructs CreateIoCompletionPort ( … ) CreateIoCompletionPort ( … ) One completion port per socket is created One completion port per socket is created GetQueuedCompletionStatus (…) GetQueuedCompletionStatus (…) 1 thread per proc handles all status using this method in each thread 1 thread per proc handles all status using this method in each thread