Cooperative Task Management without Manual Stack Management or, Event-driven Programming is Not the Opposite of Threaded Programming Atul Adya, Jon Howell,

Slides:



Advertisements
Similar presentations
Threads Relation to processes Threads exist as subsets of processes Threads share memory and state information within a process Switching between threads.
Advertisements

CS 443 Advanced OS Fabián E. Bustamante, Spring 2005 Cooperative Task Management without Manual Stack Management or Event-driven programming is not the.
1 SEDA: An Architecture for Well- Conditioned, Scalable Internet Services Matt Welsh, David Culler, and Eric Brewer Computer Science Division University.
1 Capriccio: Scalable Threads for Internet Services Matthew Phillips.
Threads Irfan Khan Myo Thein What Are Threads ? a light, fine, string like length of material made up of two or more fibers or strands of spun cotton,
Fast Servers Robert Grimm New York University Or: Religious Wars, part I, Events vs. Threads.
Threads Section 2.2. Introduction to threads A thread (of execution) is a light-weight process –Threads reside within processes. –They share one address.
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.
Fast Servers Robert Grimm New York University Or: Religious Wars, part I, Events vs. Threads.
UCoM Software Architecture Universal Communicator Research UCoM Programming Model The Problem  Multi-threaded code is difficult to write.
Threads 1 CS502 Spring 2006 Threads CS-502 Spring 2006.
Threads CSCI 444/544 Operating Systems Fall 2008.
“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,
Concurrency, Threads, and Events Robbert van Renesse.
A. Frank - P. Weisberg Operating Systems Introduction to Tasks/Threads.
Mehmet Can Vuran, Instructor University of Nebraska-Lincoln Acknowledgement: Overheads adapted from those provided by the authors of the textbook.
SEDA: An Architecture for Well-Conditioned, Scalable Internet Services
Cooperative Task Management without Manual Stack Management Or, Event-driven Programming is not the Opposite of Thread Programming Atul Adya, John Howell,
hardware and operating systems basics.
1 Lecture 4: Threads Operating System Fall Contents Overview: Processes & Threads Benefits of Threads Thread State and Operations User Thread.
Parallel Programming Models Jihad El-Sana These slides are based on the book: Introduction to Parallel Computing, Blaise Barney, Lawrence Livermore National.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Thread Scheduling.
Cooperative Task Management without Manual Stack Management or, Event-driven programming is Not the Opposite of Threaded Programming Atul Adya, Jon Howell,
Review The Joys and Pains of Threads and Multithreading –what is a thread –threads vs. processes –opportunities and risks.
© 2004, D. J. Foreman 1 Implementing Processes and Threads.
Java Thread and Memory Model
Concurrency & Context Switching Process Control Block What's in it and why? How is it used? Who sees it? 5 State Process Model State Labels. Causes of.
Cooperative Task Management without Manual Stack Management OR Presented by Tina Swenson CS533 - February 12, 2007 Event-driven Programming is Not the.
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.
CSE 60641: Operating Systems Next topic: CPU (Process/threads/scheduling, synchronization and deadlocks) –Why threads are a bad idea (for most purposes).
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Processes and Threads.
1 Cooperative Task Management without Manual Stack Management or Event-driven Programming is not the Opposite of Threaded Programming Atul Adya, Jon Howell,
SEDA: An Architecture for Well-Conditioned, Scalable Internet Services Matt Welsh, David Culler, and Eric Brewer Computer Science Division University of.
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.
Atul Adya, Jon Howell, Marvin Theimer, William J. Bolosky, John R. Douceur Microsoft Research Presented by Poonam Singh CS 533 – Winter 2010.
OSes: 2. Structs 1 Operating Systems v Objective –to give a (selective) overview of computer system architectures Certificate Program in Software Development.
1 Why Threads are a Bad Idea (for most purposes) based on a presentation by John Ousterhout Sun Microsystems Laboratories Threads!
Cooperative Task Management without Manual Stack management Hanyun Tao EECS 582 – W161.
1 Critical Section Problem CIS 450 Winter 2003 Professor Jinhua Guo.
Operating System Concepts
Multithreading vs. Event Driven in Code Development of High Performance Servers.
2.2 Threads  Process: address space + code execution  There is no law that states that a process cannot have more than one “line” of execution.  Threads:
CSCI/CMPE 4334 Operating Systems Review: Exam 1 1.
CSCE451/851 Introduction to Operating Systems
WORKING OF SCHEDULER IN OS
Introduction to Operating Systems Concepts
Chapter 4 – Thread Concepts
Introduction to threads
Threads & Multithreading
Chapter 4: Threads.
Why Events Are A Bad Idea (for high-concurrency servers)
Chapter 4 Threads.
Operating System Concepts
Chapter 4: Threads.
Cooperative Task Management without Manual Stack Management or, Event-driven Programming is Not the Opposite of Threaded Programming Atul Adya, Jon Howell,
On the Duality of Operating System Structures
CSE 451: Operating Systems Spring 2012 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Threads Chapter 5 2/17/2019 B.Ramamurthy.
Threads Chapter 5 2/23/2019 B.Ramamurthy.
Why Threads Are A Bad Idea (for most purposes)
CS510 Operating System Foundations
Why Events Are a Bad Idea (for high concurrency servers)
Foundations and Definitions
Why Threads Are A Bad Idea (for most purposes)
Why Threads Are A Bad Idea (for most purposes)
CS703 – Advanced Operating Systems
CS 5204 Operating Systems Lecture 5
Threads CSE 2431: Introduction to Operating Systems
Presentation transcript:

Cooperative Task Management without Manual Stack Management or, Event-driven Programming is Not the Opposite of Threaded Programming Atul Adya, Jon Howell, Marvin Theimer, William J. Bolosky, John R. Douceur Microsoft Research Presented by Jonathan Beare CS 533 – Winter 2009

References “An Introduction to Programming with Threads” Andrew D Birrell “On the Duality of Operating System Structures” H. C. Lauer and R. M. Needham “ Why threads are a bad idea (for most purposes)” John Ousterhout “SEDA: An architecture for well-conditioned, scalable internet services” Matt Welsh, David Culler, and Eric Brewer

Introduction  Events vs. Threads Argument  Stack Management Manual, Automatic  Task Management Serial, Cooperative, Preemptive  We need a Compromise! Cooperative Threading

Goals for Cooperative Threading  Benefits of both Event-driven (Manual Stack)  Ease of reasoning about concurrency Thread-driven (Automatic Stack)  Ease of readability and maintainability

Conflation, Conflation, Conflation  Task Management  Stack Management  I/O Response Management  Conflict Management  Data Partitioning

Cooperative Threading  Automatic Stack Management  Cooperative Task Management Atomic Blocks Yielding

Cooperative Threading  Advantages Readability Few concurrency issues Efficiency  Disadvantages Explicit yielding

Manual, Automatic Interoperation  Hybrid Approach  Usage of Wrappers  Disparate Programmers  Conflicting Codebases  Generally not a preferred method

Stack Management Automatic CAInfo GetCAInfoBlocking(CAID caId) { CAInfo caInfo = LookupHashTable(caId); if (caInfo != NULL) { // Found node in the hash table return caInfo; } caInfo = new CAInfo(); // DiskRead blocks waiting for // the disk I/O to complete. DiskRead(caId, caInfo); InsertHashTable(caId, CaInfo); return caInfo; }

Stack Management Manual void GetCAInfoHandler1(CAID caId, Continuation ∗ callerCont) { // Return the result immediately if in cache CAInfo ∗ caInfo = LookupHashTable(caId); if (caInfo != NULL) { // Call caller’s continuation with result ( ∗ callerCont−>function)(caInfo); return; } // Make buffer space for disk read caInfo = new CAInfo(); // Save return address & live variables Continuation ∗ cont = new Continuation(&GetCAInfoHandler2, caId, caInfo, callerCont); // Send request EventHandle eh = InitAsyncDiskRead(caId, caInfo); // Schedule event handler to run on reply // by registering continuation RegisterContinuation(eh, cont); } void GetCAInfoHandler2(Continuation ∗ cont) { // Recover live variables CAID caId = (CAID) cont−>arg1; CAInfo ∗ caInfo = (CAInfo ∗ ) cont−>arg2; Continuation ∗ callerCont = (Continuation ∗ ) cont−>arg3; // Stash CAInfo object in hash InsertHashTable(caId, caInfo); // Now “return” results to original caller ( ∗ callerCont−>function)(callerCont); }

Stack Management Hybrid Example function FetchCertificate GetCertificateData if VerifyCertificate is false return false function GetCertificateData if Certificate is InMemory return Certificate else GetCertificateFromDisk return Certificate function VerifyCertificate GetCertificateInfo if CertificateInfo is NULL return false else return CheckCertificate // Implemented as Manual // May retrieve immediately // Must wait for disk // Implemented as Automatic // Implemented as Manual, wait for disk // May retrieve immediately

Hybrid Management Example Overview Manual Automatic

Hybrid Management Cross-calling bool FetchCert(User user, Certificate ∗ cert) { // Get the certificate data from a // function that might do I/O certificate = GetCertData(user); if (!VerifyCert(user, cert)) { return false; } Certificate ∗ GetCertData(User user) { // Look up certificate in the memory // cache and return the answer. // Else fetch from disk/network if (Lookup(user, cert)) return certificate; certificate = DoIOAndGetCert(); return certificate; } bool VerifyCert(User user, Certificate ∗ cert) { // Get the Certificate Authority (CA) // information and then verify cert ca = GetCAInfo(cert); if (ca == NULL) return false; return CACheckCert(ca, user, cert); }

Hybrid Management Continuation-to-Fiber adaptor void VerifyCertCFA(CertData certData, Continuation ∗ callerCont) { // Executed on MainFiber Continuation ∗ vcaCont = new Continuation(VerifyCertCFA2, callerCont); Fiber ∗ verifyFiber = new VerifyCertFiber(certData, vcaCont); // On fiber verifyFiber, start executing // VerifyCertFiber::FiberStart SwitchToFiber(verifyFiber); // Control returns here when // verifyFiber blocks on I/O } VerifyCertFiber::FiberStart() { // Executed on a fiber other than MainFiber // The following call could block on I/O. // Do the actual verification. this−>vcaCont−>returnValue = VerifyCert(this−>certData); // The verification is complete. // Schedule VerifyCertCFA2 scheduler−>schedule(this−>vcaCont); SwitchTo(MainFiber); }

Hybrid Management Fiber-to-Continuation adaptor void FiberContinue(Continuation ∗ cont) { if (!Fiber::OnMainFiber()) { // Manual stack mgmt code did not perform // I/O: just mark it as short-circuited FiberContinuation ∗ fcont = (FiberContinuation) ∗ cont; fcont−>shortCircuit = true; } else { // Resumed after I/O: simply switch // control to the original fiber Fiber ∗ f = (Fiber ∗ ) cont−>arg1; f−>Resume(); } Boolean GetCAInfoFCA(CAID caid) { // Executed on verifyFiber // Get a continuation that switches control // to this fiber when called on MainFiber FiberContinuation ∗ cont = new FiberContinuation(FiberContinue, this); GetCAInfo(caid, cont); if (!cont−>shortCircuit) { // GetCAInfo did block. SwitchTo(MainFiber); } return cont−>returnValue; }

Hybrid Management Wrapping up void VerifyCertCFA2(Continuation ∗ vcaCont) { // Executed on MainFiber. // Scheduled after verifyFiber is done Continuation ∗ callerCont = (Continuation ∗ ) vcaCont−>arg1; callerCont−>returnValue = vcaCont−>returnValue; // “return” to original caller (FetchCert) ( ∗ callerCont−>function)(callerCont); }

Implementation  Farsite – File System Windows NT Originally event-driven  UCoM – Mobile Phone Application Windows CE Automatic stack management

Implementation Cont…  Positive experience  Preempt subtle concurrency problems  Function wrapping is tedious  Possible to automate the wrapping

Conclusions  Events vs. Treads debate clarified  Cooperative Threading Automatic Stack Cooperative Task  Hybrid adaptor may be used to interoperate between Manual and Automatic Stack Cooperation between disparate programmers Software evolution of conflicting code bases