CSE 124: OPTIONS, SIGNALS, TIMEOUTS, AND CONCURRENCY. George Porter Oct 13, 2017

Similar documents
CSE 124 January 27, Winter 2017, UCSD Prof. George Porter

CLIENT-SIDE PROGRAMMING

CSE 124: QUANTIFYING PERFORMANCE AT SCALE AND COURSE REVIEW. George Porter December 6, 2017

Signals, Synchronization. CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han

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

INTRODUCTION TO PROTOCOLS, LAYERING, FRAMING AND PARSING

CSE 124 Discussion Section Sockets Programming 10/10/17

CSE 124: LAMPORT AND VECTOR CLOCKS. George Porter October 30, 2017

Operating System: Chap13 I/O Systems. National Tsing-Hua University 2016, Fall Semester

CSE 124: CONTENT-DISTRIBUTION NETWORKS. George Porter December 4, 2017

Signals. CSC209: Software Tools and Systems Programming. Furkan Alaca & Paul Vrbik

Chapter 4 Multithreaded Programming

Signals. POSIX defines a variety of signal types, each for a particular

Lecture 7: Signals and Events. CSC 469H1F Fall 2006 Angela Demke Brown

THE DATACENTER AS A COMPUTER AND COURSE REVIEW

CSE 124: TIME SYNCHRONIZATION, CRISTIAN S ALGORITHM, BERKELEY ALGORITHM, NTP. George Porter October 27, 2017

ECE 650 Systems Programming & Engineering. Spring 2018

Embedded Systems Programming

CSE 421: Introduction to Operating Systems

CSci 4061 Introduction to Operating Systems. (Advanced Control Signals)

Flash: an efficient and portable web server

Operating Systems 2010/2011

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

CONTENT-DISTRIBUTION NETWORKS

TWO-PHASE COMMIT ATTRIBUTION 5/11/2018. George Porter May 9 and 11, 2018

Integrating Concurrency Control and Energy Management in Device Drivers

Operating Systems (2INC0) 2018/19. Introduction (01) Dr. Tanir Ozcelebi. Courtesy of Prof. Dr. Johan Lukkien. System Architecture and Networking Group

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 18

Integrating Concurrency Control and Energy Management in Device Drivers. Chenyang Lu

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

Unix System Programming - Chapter 8

I/O Design, I/O Subsystem, I/O-Handler Device Driver, Buffering, Disks, RAID January WT 2008/09

Lecture 15: I/O Devices & Drivers

Lecture 4 Threads. (chapter 4)

Signals: Management and Implementation. Sanjiv K. Bhatia Univ. of Missouri St. Louis

Network Programming. Multicast on a LAN 1/4. Sending & Receiving Multicast Messages. Multicasting II. Dr. Thaier Hayajneh

Signals. Joseph Cordina

REPLICATED STATE MACHINES

Network programming(ii) Lenuta Alboaie

CSE 120 Principles of Operating Systems

CSE 124: REPLICATED STATE MACHINES. George Porter November 8 and 10, 2017

Device-Functionality Progression

Chapter 12: I/O Systems. I/O Hardware

Outline. Operating Systems: Devices and I/O p. 1/18

Systems Programming/ C and UNIX

CONCURRENCY CONTROL, TRANSACTIONS, LOCKING, AND RECOVERY

Chapter 8: I/O functions & socket options

Operating Systems 2010/2011

CSE398: Network Systems Design

SMD149 - Operating Systems

CSE410 Operating Systems Spring 2018 Project 1: Introduction to Unix/Linux Signals

CSE 120 Principles of Operating Systems

Software-Defined Networking (Continued)

15: OS Scheduling and Buffering

COS 318: Operating Systems. Message Passing. Vivek Pai Computer Science Department Princeton University

CSE 124: TAIL LATENCY AND PERFORMANCE AT SCALE. George Porter November 27, 2017

TAIL LATENCY AND PERFORMANCE AT SCALE

Chapter 2. OS Overview

Module 12: I/O Systems

Asynchronous Events on Linux

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

PEER-TO-PEER NETWORKS, DHTS, AND CHORD

Signals and Session Management. Signals. Mechanism to notify processes of system events

Network Management & Monitoring Network Delay

ECS 150 Operating Systems

CSE 410: Systems Programming

Shell Execution of Programs. Process Groups, Session and Signals 1

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

Standards / Extensions C or C++ Dependencies POSIX.1 XPG4 XPG4.2 Single UNIX Specification, Version 3

Start of Lecture on January 20, Chapter 3: Processes

CSE 153 Design of Operating Systems Fall 18

11/13/2018 CACHING, CONTENT-DISTRIBUTION NETWORKS, AND OVERLAY NETWORKS ATTRIBUTION

What is an Operating System? A Whirlwind Tour of Operating Systems. How did OS evolve? How did OS evolve?

Input/Output Systems

CSE 333 Lecture server sockets

Operating Systems. Review ENCE 360

Exceptions and Processes

Exam Solutions EDA040 Concurrent and Real-Time Programming

Operating Systems. Threads and Signals. Amir Ghavam Winter Winter Amir Ghavam

Implementing Lightweight Threads

System Architecture Directions for Networked Sensors[1]

Assignment 1: tcpbridge

Hardware OS & OS- Application interface

CSCI 4061: Signals and Signal Handlers

SWITCHING, FORWARDING, AND ROUTING

Overview. Thread Packages. Threads The Thread Model (1) The Thread Model (2) The Thread Model (3) Thread Usage (1)

Chapter 2 Computer-System Structure

Course Syllabus. Operating Systems, Spring 2016, Meni Adler, Danny Hendler & Amnon Meisels

I/O Systems. Amir H. Payberah. Amirkabir University of Technology (Tehran Polytechnic)

Outline. Introduction. Survey of Device Driver Management in Real-Time Operating Systems

Dr. Rafiq Zakaria Campus. Maulana Azad College of Arts, Science & Commerce, Aurangabad. Department of Computer Science. Academic Year

NetCheck: Network Diagnoses from Blackbox Traces

CSCE Operating Systems Interrupts, Exceptions, and Signals. Qiang Zeng, Ph.D. Fall 2018

I/O Systems. 04/16/2007 CSCI 315 Operating Systems Design 1

6.033 Computer System Engineering

SOCKET. Valerio Di Valerio

ECE 598 Advanced Operating Systems Lecture 23

A set of processes distributed over a network that communicate via messages. Processes communicate via services offered by the operating system

PRIMARY-BACKUP REPLICATION

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

Transcription:

CSE 124: OPTIONS, SIGNALS, TIMEOUTS, AND CONCURRENCY George Porter Oct 13, 2017

ATTRIBUTION These slides are released under an Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0) Creative Commons license

ANNOUNCEMENTS HW 2 out Project 1 deadline will be pushed back a bit (TBD) But do start on it!

Outline 1. Socket internals 2. Socket options 3. Signals and timeouts 4. Concurrency

DIGGING INTO SEND() A BIT MORE

AFTER 3 SEND() CALLS

AFTER FIRST RECV()

AFTER ANOTHER RECV()

WHEN DOES BLOCKING OCCUR? SendQ size: SQS RecvQ size: RQS send(s, buffer, n, 0); n>sqs: blocks until (n SQS) bytes xfered to RecvQ If n>(sqs+rqs), blocks until receiver calls recv() enough to read in n-(sqs+rqs) bytes How does this lead to deadlock? Trivial cause: both sides call recv() w/o sending data

MORE SUBTLE REASON FOR DEADLOCK SendQ size = 500; RecvQ size = 500

Outline 1. Socket internals 2. Socket options 3. Signals and timeouts 4. Concurrency

SOCKET OPTIONS: MOTIVATION Basic out of the box socket functionality fine for most purposes But what if you need to tweak the behavior? Can set/get options on sockets These options apply to different layers of the network stack: IP TCP Socket

TCP BUFFER SIZE OPTIONS Send and receive buffer sizes What is the default? [gmporter@seed-f60-100 ~]$ cat /proc/sys/net/ipv4/tcp_rmem 4096 87380 6291456 [gmporter@seed-f60-100 ~]$ cat /proc/sys/net/ipv4/tcp_wmem 4096 16384 4194304 Minimum Default Maximum Can we change that value? Yes!

SETTING/GETTING SOCKET OPTIONS Level Option Description SOL_SOCKET SO_SNDBUF SO_REUSEADDR SO_RCVTIMEO SO_SNDTIMEO Send buffer size Allow TCP port to be reused immediately Set a recv() timeout Set a send() timeout

REUSING SOCKETS int optval = 1; /* enable sockets to be immediately reused */ if (setsockopt(serv_sock, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval))!= 0) { die_system("setsockopt() failed"); }

SENDFILE()

Outline 1. Socket internals 2. Socket options 3. Signals and timeouts 4. Concurrency

OS SIGNALS OS mechanism to asynchronously interrupt a program Why is this useful? Kill a runaway/hung process Notify program that there is activity on the keyboard Disk read operation has completed The dreaded SIGSEGV

SIGNALS AND NETWORKING Signals can be used to implement timeouts Examples: Close connection after 3 minutes of inactivity HTTP server: is the client going to send another request? Set timeout for e.g., 5 seconds Useful any time you need to stop blocking recv() send()

SIGNALS: ALARMS SIGALRM Issued after a set period of time goes by Like an alarm clock for your program Others in D&C Chapter 6.2

SETTING UP EVENT HANDLERS Function to handle event Rest of fields can be set to NULL/0 How to handle other events during the handling of this event

HOW TO USE SIGNALS Define the event handling function void myfun(int signal); Associate that function with the signal you want to handle sigaction() call

WHAT DOES MASK MEAN? Signals arrive unpredictably and asynchronously Get a SIGINT or SIGTERM for example What happens if, if your handler for SIGINT, another SIGINT comes? Can simplify our handler by masking signals during our event handler Helper functions provided (e.g., sigfillset( ))

SIGNALS AND SOCKETS APIS What happens to a blocking call when an event comes in? Control transferred to event handler When control returned, the blocking stops, and an error code is returned Recv() Might return fewer bytes than requested, or EINTR return code if no bytes received Send() Might send fewer bytes than requested or EINTR if no bytes sent

Outline 1. Socket internals 2. Socket options 3. Signals and timeouts 4. Concurrency

Outline 1. Socket internals 2. Socket options 3. Signals and timeouts 4. Concurrency

CONCURRENCY VS PARALLELISM Both deal with doing a lot at once, but aren t the same thing Given set of tasks {T 1,T 2,,T n } Concurrency: Progress of multiple elements of the set overlap in time Parallelism: Progress on elements of the set occur at the same time

CONCURRENCY Might be parallel, might not be parallel A single thread of execution can time slice a set of tasks to make partial progress over time Time 0: Work on first 25% of Task 0 Time 1: Work on first 25% of Task 1 Time 2: Work on first 25% of Task 2 Time 3: Work on first 25% of Task 3 Time 4: Work on second 25% of Task 0 Time 5: Work on second 25% of Task 1

PARALLELISM Multiple execution units enable progress to be made simultaneously Processor 1 Processor 2 Time 0: 1 st 25% of Task1 Time 1: 2 nd 25% of Task1 Time 2: 3 rd 25% of Task1 Time 3: 4 th 25% of Task1 Time 4: 1 st 25% of Task3 Time 0: 1 st 25% of Task2 Time 1: 2 nd 25% of Task2 Time 2: 3 rd 25% of Task2 Time 3: 4 th 25% of Task2 Time 4: 1 st 25% of Task4

FLASH TRAFFIC USGS Pasadena, CA office Earthquake site Oct 16, 1999 earthquake

THREADING AND PERFORMANCE Too much parallelism causes thrashing, excessive switching, lower performance

HANDS-ON EXAMPLE Follow along at: https://github.com/gmporter/cse124-lec-concurrency