Network Programming TDC 561

Similar documents
I/O Models. Kartik Gopalan

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

CONCURRENCY MODEL. UNIX Programming 2014 Fall by Euiseong Seo

UNIT III - APPLICATION DEVELOPMENT. TCP Echo Server

ISA 563: Fundamentals of Systems Programming

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

Concurrent Server Design Multiple- vs. Single-Thread

CISC2200 Threads Spring 2015

Chapter 8: I/O functions & socket options

CS240: Programming in C

Network Programming TDC 561

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

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

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.

Asynchronous Events on Linux

Network Programming TDC 561

Chapter 4 Multithreaded Programming

CSC209 Review. Yeah! We made it!

CS118 Discussion Week 2. Taqi

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

10. I/O System Library

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

Network programming(ii) Lenuta Alboaie

Operating Systems. VI. Threads. Eurecom. Processes and Threads Multithreading Models

Memory-Mapped Files. generic interface: vaddr mmap(file descriptor,fileoffset,length) munmap(vaddr,length)

Process Description and Control

Threads. What is a thread? Motivation. Single and Multithreaded Processes. Benefits

Processes. CS 416: Operating Systems Design, Spring 2011 Department of Computer Science Rutgers University

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

* What are the different states for a task in an OS?

Redesde Computadores(RCOMP)

PROCESS CONCEPTS. Process Concept Relationship to a Program What is a Process? Process Lifecycle Process Management Inter-Process Communication 2.

CHAPTER 3 - PROCESS CONCEPT

Processes. Processes (cont d)

PROCESS CONTROL BLOCK TWO-STATE MODEL (CONT D)

CONCURRENT PROGRAMMING. Lecture 5

Redes de Computadores (RCOMP)

COMP/ELEC 429/556 Introduction to Computer Networks

33. Event-based Concurrency

More Network Programming

Server algorithms and their design

CSC209H Lecture 10. Dan Zingaro. March 18, 2015

Introduction to Asynchronous Programming Fall 2014

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

The basic server algorithm. Server algorithms and their design. Problems with the simple server? Servers. overview ofaserver

W4118 Operating Systems. Junfeng Yang

A Scalable Event Dispatching Library for Linux Network Servers

Concurrent Servers Dec 2, 2009"

Multithreaded Programming

CSC 539: Operating Systems Structure and Design. Spring 2006

Chapter 3: Processes. Operating System Concepts 9 th Edition

Operating Systems. Review ENCE 360

Operating Systems 2010/2011

CS5460: Operating Systems

Interprocess Communication Mechanisms

shared storage These mechanisms have already been covered. examples: shared virtual memory message based signals

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

Processes and Threads

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

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

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

Processes. Process Scheduling, Process Synchronization, and Deadlock will be discussed further in Chapters 5, 6, and 7, respectively.

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song

Chapter 4: Multithreaded

Chapter 3: Process Concept

Distributed Systems Exam 1 Review. Paul Krzyzanowski. Rutgers University. Fall 2016

Processes and Non-Preemptive Scheduling. Otto J. Anshus

Concurrency. Stefan D. Bruda. Winter 2018

COSC243 Part 2: Operating Systems

Problem Set: Processes

High Performance Computing Course Notes Shared Memory Parallel Programming

CSE 421: Introduction to Operating Systems

Interprocess Communication Mechanisms

Interprocess Communication Mechanisms

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

Concurrent Programming April 21, 2005

Chapter 3: Processes. Operating System Concepts 9 th Edition

OPERATING SYSTEM. Chapter 4: Threads

G Honors Operating Systems

Killing Zombies, Working, Sleeping, and Spawning Children

SMD149 - Operating Systems

Chapter 4: Threads. Chapter 4: Threads

CSE 410: Systems Programming

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

Lecture 4 Threads. (chapter 4)

Processes, Threads, SMP, and Microkernels

System Call. Preview. System Call. System Call. System Call 9/7/2018

Processes. Process Concept

MPAC BENCHMARKING LIBRARY

Overview. POSIX signals. Generation of signals. Handling signals. Some predefined signals. Real-time Systems D0003E 3/3/2009

"#' %#& Lecture 7: Organizing Game Clients and Servers. Socket: Network communication endpoints. IP address: IP-level name of a machine

Threads. studykorner.org

Overview. Administrative. * HW 1 grades. * HW 2 Due. Topics. * 5.1 What is a Signal? * Dealing with Signals - masks, handlers

Background: I/O Concurrency

CS 475. Process = Address space + one thread of control Concurrent program = multiple threads of control

Network Games Part II. Architecture of Network Game

Lecture Topics. Announcements. Today: Threads (Stallings, chapter , 4.6) Next: Concurrency (Stallings, chapter , 5.

Topics for this Week

Transcription:

Network Programming TDC 561 Lecture # 4: Server Design (II) - Concurrent Servers Dr. Ehab S. Al-Shaer School of Computer Science & Telecommunication DePaul University Chicago, IL 1 Unix Signals A signal is a notification to a process that an event has occurred. Signals can be sent by one process to another (or to itself) or by the kernel to a process. The signal() system call provides a mechanism for user programs to react to signals by associating a function called a signal handler with a specific signal. 2 signal() system call void (*signal (int sig,void (*func)(int)))(int); Example: signal(sigusr1,myfunc); This would tell the kernel to call the user defined function myfunc() whenever the signal SIGUSR1 is received. There are many differnt signals - each has a name specified in the include file signal.h. 3 1

POSIX Signals SI GABRT SI GALRM SI GFPE SI GHUP SI GI NT SI GKI LL SI GSEGV SI GQUI T SI GUSR1 SI GCHLD SI GCONT SI GSTOP SI GTSTP Abnormal termination Timeout Erroneous arithmetic operation Hangup Interactive attention Termination signal Invalid memory reference Interactive termination (^C) User defined Child process has terminated Continued Stop Interactive Stop (^Z) 4 Sources of Signals The kill() system call allows a process to send a signal to another process. int kill( int pid, int sig ); A signal can be sent via the kill system call only if the effective UID of the sending process is 0 (root) or matches the effective UID of the receiving process. 5 Other sources of signals From shell: e.g. $kill -9 <pid> Certain terminal characters generate signals, for example ^C. Hardware conditions can generate signals (division by zero, memory violation). These signals are passed to the process from the kernel. Some software related conditions can cause the kernel to send a signal (for example the receipt of out-of-band data). 6 2

Concurrent Servers Motivations for Concurrency better response time I/O (and CPU) overlapping multiprocessor systems Nonblocking I/O chew up all processor time (Common) Concurrent Server Architectures Multi-process servers I/O Multiplexing servers Multithreaded servers 7 Multi-process Concurrent Servers Design: Master/slave model Master: always running, manage but does not communicate back Slave: does the actual work (processing + comm) Algorithm for Connection-oriented servers: 1. M: Create a socket & Bind to a port 2. M: Make it passive! (listen) 3. M: Accept connections & create a slave (S) 4. M: Go to 3 5. S: Read, process and reply 6. S: Close and exit 8 Multiprocess Concurrent Servers (cont.) Algorithm for Connectionless servers: 1. M: Create a socket & Bind to a port 2. M: Receive a request & create a slave (S) 3. M: Go to 2 4. S: process and reply 5. S: Close and exit A slave per connection Vs. per request few connectionless concurrent servers exist! Used mainly when slaves are independent (why?) 9 3

I/O Multiplexing Concurrent Servers Design: Singe process (apparent concurrency) select(): the kernel support for asynchronous I/O multiplexing Algorithm for connection-oriented servers: 1. Create a socket (m) & Bind to a port, Add m to socklist, 2. use select(){blocking,unblocking,timeout} 3. Accept connections when m is ready, and add the new socket to socklist 4. Read/write from/to a ready socket 5. Go to 2 10 I/O Multiplexing Concurrent Servers (cont.) Motivations: No fork() overhead connections share same state or coordination client requests are very interleaved (eg. X clients: xclock, xbuf, xterm, xemacs..etc) supporting multi-protocol single server serializability simpler! Issues: programmer must be aware of this concurrency fairness: short requests/service time multiprocessor machine does not help! 11 Select() The select() system call allows us to use blocking I/O on a set of descriptors (file, socket, ). For example, we can ask select to notify us when data is available for reading on either STDIN or a TCP socket. 12 4

Select() int select( int maxfd, fd_set *readset, fd_set *writeset, fd_set *excepset, const struct timeval *timeout); maxfd : highest number assigned to a descriptor. readset: set of descriptors we want to read from. writeset: set of descriptors we want to write to. excepset: set of descriptors to watch for exceptions. timeout: maximum time select should wait 13 struct timeval struct timeval { long tv_sec; /* seconds */ long tv_usec; /* microseconds */ } struct timeval max = {1,0}; 14 fd_set Implementation is not important Operations to use with fd_set: void FD_ZERO( fd_set *fdset); void FD_SET( int fd, fd_set *fdset); void FD_CLR( int fd, fd_set *fdset); int FD_ISSET( int fd, fd_set *fdset); 15 5

Using select() Create fd_set clear the whole thing with FD_ZERO Add each descriptor you want to watch using FD_SET. Call select when select returns, use FD_ISSET to see if I/O is possible on each descriptor. 16 Multithreaded Concurrent Servers Design: (detailed discussion later) Master/slave model with stronger coordination Master: always running, manage but does not communicate back Slave: does the actual work (processing + comm) Algorithm for connection-oriented servers: 1. MT: Create a socket & Bind to a port 2. MT: Make it passive! (listen) 3. MT: Accept & create a thread (ST) 4. MT: Go to 3 5. ST: Read, process, reply and coordinate 6. ST: go to 5 or close and exit-thread 17 Servers Threat Resources consumption rapid connections during 2*MSL too many client crashes Reliability problems Erroneous message requests storm Server deadlock client connects but does not send client send but not receive UDP server sends a request and expects a reply but the request is lost 18 6