Concurrency, Thread and Event CS6410 Sept 6, 2011 Ji-Yong Shin.

Slides:



Advertisements
Similar presentations
1 SEDA: An Architecture for Well- Conditioned, Scalable Internet Services Matt Welsh, David Culler, and Eric Brewer Computer Science Division University.
Advertisements

CS533 Concepts of Operating Systems Jonathan Walpole.
SEDA: An Architecture for Well- Conditioned, Scalable Internet Services Matt Welsh, David Culler, and Eric Brewer Computer Science Division University.
Concurrency, Threads, and Events Presented by Hakim Weatherspoon.
Hugh Lauer Xerox Corporation Roger Needham Cambridge University Presented by Vidhya Priyadharshnee Palaniswamy Gnanam Spring 2011.
Why Events Are A Bad Idea (for high-concurrency servers) By Rob von Behren, Jeremy Condit and Eric Brewer.
CS533 Concepts of Operating Systems Class 5 Event-Based Systems.
1 On the Duality of Operating System Structures by Hugh C. Lauer, Xerox Corporation and Roger M. Needham, Cambridge University Presented by Scott Fletcher.
SEDA: An Architecture for Well-Conditioned, Scalable Internet Services Matt Welsh, David Culler, and Eric Brewer Computer Science Division University of.
Capriccio: Scalable Threads for Internet Services ( by Behren, Condit, Zhou, Necula, Brewer ) Presented by Alex Sherman and Sarita Bafna.
490dp Synchronous vs. Asynchronous Invocation Robert Grimm.
Processes CSCI 444/544 Operating Systems Fall 2008.
CS533 Concepts of Operating Systems Class 5 Event-Based Systems.
Concurrency CS 510: Programming Languages David Walker.
Why Events Are a Bad Idea (for high-concurrency servers) Author: Rob von Behren, Jeremy Condit and Eric Brewer Presenter: Wenhao Xu Other References: [1]
“Why Events are a Bad Idea (For high-concurrency servers)” Paper by Rob von Behren, Jeremy Condit and Eric Brewer, May 2003 Presentation by Loren Davis,
CS533 Concepts of Operating Systems Class 2 Thread vs Event-Based Programming.
1 On the Duality of Operating System Structures Hugh Lauer, Xerox Roger Needham, Cambridge University Oct 1978, reprinted April 1979 Presented by David.
Concurrency, Threads, and Events Robbert van Renesse.
On the Duality of Operating System Structures Hugh Lauer Xerox Corporation Roger Needham Cambridge University Presented by Yahia Mahmoud.
CS533 Concepts of Operating Systems Class 2 The Duality of Threads and Events.
On the Duality of Operating System Structures Hugh C. Lauer Xerox Corporation Roger M. Needham Cambridge University Presented By: Ashwini Kulkarni.
Concurrency, Threads, and Events Ken Birman (Based on a slide set prepared by Robbert van Renesse)
SEDA: An Architecture for Well-Conditioned, Scalable Internet Services
SEDA – Staged Event-Driven Architecture
SEDA: An Architecture for Well-Conditioned, Scalable Internet Services by, Matt Welsh, David Culler, and Eric Brewer Computer Science Division University.
SEDA: An Architecture for Well-Conditioned, Scalable Internet Services
Advanced Operating Systems CIS 720 Lecture 1. Instructor Dr. Gurdip Singh – 234 Nichols Hall –
Dave Archer - CS533 - Spring On the Duality of Operating System Structures Hugh C. Lauer, Roger M. Needham.
On the Duality of Operating System Structures 1. Hugh C. Lauer Xerox Corporation Palo Alto, Californi a Roger M. Needham Cambridge University Cambridge,
SEDA: An Architecture for Well-Conditioned, Scalable Internet Services Presented by Changdae Kim and Jaeung Han OFFENCE.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
CS533 - Concepts of Operating Systems 1 On The Duality of Operating System Structures Hugh Lauer, Xerox Roger Needham, Cambridge University 1979 Presented.
ON THE DUALITY OF OPERATING SYSTEM STRUCTURES Hugh C. Lauer and Roger M. Needham Presented by: Ali R. Butt (adapted from many slides available online and.
5204 – Operating Systems Threads vs. Events. 2 CS 5204 – Operating Systems Forms of task management serial preemptivecooperative (yield) (interrupt)
CSC Multiprocessor Programming, Spring, 2012 Chapter 11 – Performance and Scalability Dr. Dale E. Parson, week 12.
Presenting: Why Events Are A “Bad” Idea ( for high-concurrency servers) Paper by: Behren, Condit and Brewer, 2003 Presented by: Rania Elnaggar 1/30/2008.
1 Cooperative Task Management without Manual Stack Management or Event-driven Programming is not the Opposite of Threaded Programming Atul Adya, Jon Howell,
13-1 Chapter 13 Concurrency Topics Introduction Introduction to Subprogram-Level Concurrency Semaphores Monitors Message Passing Java Threads C# Threads.
CS533 – Spring Jeanie M. Schwenk Experiences and Processes and Monitors with Mesa What is Mesa? “Mesa is a strongly typed, block structured programming.
SEDA: An Architecture for Well-Conditioned, Scalable Internet Services Matt Welsh, David Culler, and Eric Brewer Computer Science Division University of.
By: Rob von Behren, Jeremy Condit and Eric Brewer 2003 Presenter: Farnoosh MoshirFatemi Jan
SEDA An architecture for Well-Conditioned, scalable Internet Services Matt Welsh, David Culler, and Eric Brewer University of California, Berkeley Symposium.
Threads versus Events CSE451 Andrew Whitaker. This Class Threads vs. events is an ongoing debate  So, neat-and-tidy answers aren’t necessarily available.
1 Why Events Are A Bad Idea (for high-concurrency servers) By Rob von Behren, Jeremy Condit and Eric Brewer (May 2003) CS533 – Spring 2006 – DONG, QIN.
Brian Bershad, Thomas Anderson, Edward Lazowska, and Henry Levy Presented by: Byron Marohn Published: 1991.
1 Why Threads are a Bad Idea (for most purposes) based on a presentation by John Ousterhout Sun Microsystems Laboratories Threads!
REVIEW OF “ON THE DUALITY OF OPERATING SYSTEM STRUCTURES” Paper by Hugh C. Lauer and Roger M. Needham Presentation by Erin Chapman.
Paper Review of Why Events Are A Bad Idea (for high-concurrency servers) Rob von Behren, Jeremy Condit and Eric Brewer By Anandhi Sundaram.
SEDA. How We Got Here On Tuesday we were talking about Multics and Unix. Fast forward years. How has the OS (e.g., Linux) changed? Some of Multics.
Processes and threads.
Advanced Operating Systems CIS 720
SEDA: An Architecture for Scalable, Well-Conditioned Internet Services
Threads vs. Events SEDA – An Event Model 5204 – Operating Systems.
Why Events Are A Bad Idea (for high-concurrency servers)
Chapter 3: Process Concept
On the Duality of Operating System Structures
Concurrency, threads, and events
Processes and Threads Processes and their scheduling
CS533 Concepts of Operating Systems
On the Duality of Operating System Structures
Hugh Lauer Xerox Corporation Roger Needham Cambridge University
CS533 Concepts of Operating Systems Class 7
CS510 Operating System Foundations
On the Duality of Operating System Structures
Why Threads Are A Bad Idea (for most purposes)
Why Threads Are A Bad Idea (for most purposes)
SEDA: An Architecture for Well-Conditioned, Scalable Internet Services
CSC Multiprocessor Programming, Spring, 2011
CS533 Concepts of Operating Systems Class 4
Presentation transcript:

Concurrency, Thread and Event CS6410 Sept 6, 2011 Ji-Yong Shin

What is a Thread? Same as multiple processes sharing an address space. A traditional “process” is an address space and a thread of control. Now add multiple thread of controls –Share address space –Individual program counters and stacks

Uses of Threads To exploit CPU parallelism –Run two CPUs at once in the same program To exploit I/O parallelism –Run I/O while computing, or do multiple I/O –I/O may be “remote procedure call” For program structuring –E.g., timers

Common Problems Priority Inversion –High priority thread waits for low priority thread –Solution: temporarily push priority up (rejected??) Deadlock –X waits for Y, Y waits for X Incorrect Synchronization –Forgetting to release a lock Failed “fork”

What is an Event? An object queued for some module Operations: –create_event_queue(handler)  EQ –enqueue_event(EQ, event-object) Invokes, eventually, handler(event-object) Handler is not allowed to block –Blocking could cause entire system to block –But page faults, garbage collection, …

Synchronization? Handlers cannot block  no synchronization Handlers should not share memory –At least not in parallel All communication through events

Uses of Events CPU parallelism –Different handlers on different CPUs I/O concurrency –Completion of I/O signaled by event –Other activities can happen in parallel Program structuring –Not so great… –But can use multiple programming languages!

Common Problems Priority inversion, deadlock, etc. much the same with threads Stack ripping –No local variables are preserved –Callbacks should explicitly get more and more variables

On the Duality of Operating System Structure Hugh C. Lauer –Adjunct Prof., Worcester Polytechnic Institute –Xerox, Apollo Computer, Mitsubishi Electronic Research Lab, etc. Roger M. Needham –Prof., Cambridge University –Microsoft Research, Cambridge Lab

Message-Oriented System (Event) Small, static # of process Explicit messaging Limited data sharing in memory Identification of address space or context with processes

Message Oriented System Characteristics –Queuing for congested resource –Data structure passed by reference (no concurrent access) –Peripheral devices treated as processes –Priority of process statically determined –No global naming scheme is useful

Message Oriented System Facilities –Message with identifiers: points to larger data –Message channel and ports: Channel: destination of message Port: type specific queue leading to a process Operations –SendMessage –AwaitReply –WaitForMessage –SendReply Process declaration CreateProcess

Message Oriented System Canonical model –begin Do forever WaitForMessages case port port 1: …; port 2: …; SendReply; …; end case end loop end

Procedure-Oriented System (Thread) Large # of small processes Rapidly changing # of processes Communication using direct sharing and interlocking of data Identification of context of execution with function being executed

Procedure Oriented System Characteristics –Synchronization and congestion control associates with waiting for locks –Data is shared directly and lock lasts for short period of time –Control of peripheral devices are in form of manipulating locks –Priority is dynamically determined by the execution context –Global naming and context is important

Procedure Oriented System Facilities –Procedure: implements algorithm and accesses global data –Procedure call facility Synchronous call: regular call Asynchronous call: FORK (creation) and JOIN (syncs termination) –Modules: collection of procedure and data –Monitor: modules with locking facility –NEW and START: instantiate and run modules (monitors) –WAIT condVar and SIGNAL condVar

Procedure Oriented System Canonical model –Monitor -- global data and state info for the process proc1: entry procedure proc2: entry procedure returns begin If resourceExhausted then WAIT; …; RETURN result; …; end proc L: Entry procedure begin …; SIGNAL; … end; endloop; initialize; end

Dual Mapping EventThread Processes: CreateProcessMonitors: NEW/START Message channelExternal procedure id Message portEntry procedure id Send msg (immediate); AwaitReplySimple procedure call Send msg (delayed); AwaitReplyFORK; … JOIN Send replyReturn from procedure Main loop of std resource manager, wait for message stmt, case stmt Monitor lock, ENTRY attribute Arms of case statementENTRY proc declaration Selective waitingCondition vars, WAIT, SIGNAL

Summary One canonical implementation can be switched to the other implementation Performance can be the same as well (?) –But depending on the machine architecture and programming constraints, one model might be preferred over the other

SEDA: An Architecture for Well- Conditioned Scalable Internet Services Matt Welsh –Cornell Alumnus –Google David Culler –Faculty at UC Berkeley Eric Brewer –Faculty at UC Berkeley

Motivation Web services becoming larger –Billions of access per day –Complex services and dynamic contents Traditional concurrency model –Performance does not scale Aim to build well-conditioned service –Graceful degradation as load increases

Thread Easy to program TLB miss, scheduling overhead, lock contention Bounded thread pool leads to unfairness

Event Non-blocking event handling process assumed Scheduling issue for different FSMs Structured event queue: SEDA extends this approach

SEDA Goal –Support massive concurrency –Simplify construction of well conditioned service –Enable introspection by application –Support self-tuning resource management

SEDA Design = Event + Thread (Staged Event Driven Architecture) Stage –Event queue –Event handler –Thread pool –Controller Scheduling Thread pool size –Explicit control boundary

Dynamic Resource Control Thread pool controller –Based on queue length and idle period Queue length ↑ → # Thread ↑ Thread Idle → # Thread ↓ Batching controller –Based on output rate of a stage Output rate ↓ → Batching factor ↑

Evaluation: Throughput & Fairness Haboob: SEDA based Apache: Thread based (max 150 threads) Flash: Event based (max 500 connections)

Evaluation: Distribution of Response Time Haboob: SEDA based Apache: thread based (max 150 threads) Flash: Event based (max 500 connections)

Evaluation: Adaptive Load Shedding Dynamic page request: IO intensive load Flash: CGI bug (?) Haboob: Customized controller improves fairness

Summary Staged event driven architecture –Merits of thread and event –Easy to program and debug Modularity Sequential stages –Controller dynamically handles heavy loads Global arbitration of controllers (?) –Detecting load –Handling load

Discussion Thread vs Event? Are they the same? –Why threads are a bad idea [Ousterhout, 1996] –Why events are a bad idea, [Von Behren, 2003] –Events can make sense, [Krohn, 2007] –… Compromise solution?

Reference /2010fa/lectures/03-concurrency.pptx