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
CS 443 Advanced OS Fabián E. Bustamante, Spring 2005 Cooperative Task Management without Manual Stack Management or Event-driven programming is not the.
Advertisements

Chapter 5 Processes and Threads Copyright © 2008.
Threads Section 2.2. Introduction to threads A thread (of execution) is a light-weight process –Threads reside within processes. –They share one address.
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.
Cooperative Task Management without Manual Stack Management or, Event-driven Programming is Not the Opposite of Threaded Programming Atul Adya, Jon Howell,
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.
CS533 Concepts of Operating Systems Class 7 Integrated Task and Stack Management.
1 Chapter 4 Threads Threads: Resource ownership and execution.
Mehmet Can Vuran, Instructor University of Nebraska-Lincoln Acknowledgement: Overheads adapted from those provided by the authors of the textbook.
Threads CS 416: Operating Systems Design, Spring 2001 Department of Computer Science Rutgers University
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.
Advanced Operating Systems CIS 720 Lecture 1. Instructor Dr. Gurdip Singh – 234 Nichols Hall –
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Threads and Processes.
Operating Systems Lecture 2 Processes and Threads Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing Liu School of.
Cooperative Task Management without Manual Stack Management or, Event-driven programming is Not the Opposite of Threaded Programming Atul Adya, Jon Howell,
CS333 Intro to Operating Systems Jonathan Walpole.
Multithreading in Java Sameer Singh Chauhan Lecturer, I. T. Dept., SVIT, Vasad.
Cooperative Task Management without Manual Stack Management OR Presented by Tina Swenson CS533 - February 12, 2007 Event-driven Programming is Not the.
Department of Computer Science and Software Engineering
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,
Thread basics. A computer process Every time a program is executed a process is created It is managed via a data structure that keeps all things memory.
Threads versus Events CSE451 Andrew Whitaker. This Class Threads vs. events is an ongoing debate  So, neat-and-tidy answers aren’t necessarily available.
Atul Adya, Jon Howell, Marvin Theimer, William J. Bolosky, John R. Douceur Microsoft Research Presented by Poonam Singh CS 533 – Winter 2010.
CS533 Concepts of Operating Systems Jonathan Walpole.
Processes and Threads MICROSOFT.  Process  Process Model  Process Creation  Process Termination  Process States  Implementation of Processes  Thread.
Embedded Computer - Definition When a microcomputer is part of a larger product, it is said to be an embedded computer. The embedded computer retrieves.
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.
Assembly Language Co-Routines
Multithreading vs. Event Driven in Code Development of High Performance Servers.
Threads prepared and instructed by Shmuel Wimer Eng. Faculty, Bar-Ilan University 1July 2016Processes.
Multiprogramming. Readings r Chapter 2.1 of the textbook.
Introduction to Operating Systems Concepts
Chapter 4 – Thread Concepts
Process concept.
Advanced Operating Systems CIS 720
Why Events Are A Bad Idea (for high-concurrency servers)
Process Management Process Concept Why only the global variables?
CS 6560: Operating Systems Design
Operating Systems (CS 340 D)
Chapter 4 – Thread Concepts
CS399 New Beginnings Jonathan Walpole.
CS533 Concepts of Operating Systems
Chapter 4 Threads.
Intro to Processes CSSE 332 Operating Systems
Operating Systems (CS 340 D)
Thread Implementation Issues
Lecture Topics: 11/1 General Operating System Concepts Processes
Threads and Concurrency
Threads Chapter 4.
Multithreaded Programming
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
Chapter 6: Synchronization Tools
The SMART Way to Migrate Replicated Stateful Services
CSE 153 Design of Operating Systems Winter 2019
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
CS533 Concepts of Operating Systems Class 4
CS 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 Poonam Singh CS 533 – Winter 2010

Outline Task Management Serial, Cooperative, Preemptive Stack Management Manual, Automatic Importance of Sweet point Cooperative threading Importance of adapters in switching from manual to automatic stack management vice-versa.

Goal of Paper Event-Driven Programming is not the opposite of Threaded Programming. Cooperative Threading = Cooperative task management + automatic stack management. Focuses on conflation of event-driven programming with multithreaded and shows how one can get the best of both worlds. Importance of adapters in switching between manual stack management to automatic stack management and vice-versa.

Paper Organisation First half of the paper talks about “How one can get the best of both world”. There arises the concept of “Conflation” which called as Sweet Spot. Second half of the paper talks about how we find the glue between Manual Stack Management and Automatic Stack Management. The Solution is Adapters!!!

Task Management Serial, Preemptive and co-operative Divide the work, where each task encapsulates a control flow. All tasks access some common shared area. Task finishes and then yields control. Advantage: No conflict access to shared area. Preemptive : (Multithreaded) Opposite of serial. High performance program. Execution of tasks can interleave on uniprocessor or overlap on multiprocessor. Control can be preempted from a particular task. Cooperative : (event-driven) A compromise of serial and preemptive. A task yields control at well defined points during execution, usually when task must wait for long running I/O.

Stack Management Automatic and Manual Manual Stack Management (event-driven) Automatic Stack Management (Multithreaded ) Multithreaded Event-driven Automatic Stack management Manual Stack management Preemptive Task Management Cooperative Task Management ( non preemptive)

Importance of sweet point Sweet Point = Cooperative task management preserving automatic stack management Makes programming language structured. Conflated Point

Reason why Task Management. and Stack Management concept Reason why Task Management and Stack Management concept discussed in this paper ?????

Reason why Task Management and Stack Management concept discussed in this paper ????? Because Multithreaded programming and Event- driven programming styles conflates at these two concept. Author is finding the space that combines the advantage of both programming style (Sweet Spot).

Stack Management Automatic - Uses program stack provided by the procedural Language Code only with the compute only function CAInfo GetCAInfo(CAID caId) { CAInfo caInfo = LookupHashTable(caId); return caInfo; } Automatic with I/O’s 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);

Event Handler/ Scheduler Function in Manual Stack Management E1 . initiate I/O register a Continuation stores a bundle state (data, E2) Terminate E2 Code after I/O completion

Stack Management Manual Programming language procedures ripped into different Event Handlers. Example: 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); voidGetCAInfoHandler2(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); }

Drawback of Manual Stack Management Task Specific states are broken. Control flow for a single conceptual task is also broken. Magnifies the problem of stack ripping: A call that did not yield yesterday may be changed tomorrow to yield for I/O, its signature changes to reflect the new structure. More problems with I/O in functions having loops. If there are more I/O calls there are even more rips in the code. Difficult to debug( Stack Unrecoverable). The programmer deconstructs the language stack, reconstructs it on the heap. Program Becomes less readable. Cumbersome code restructuring.

What people at Microsoft Think? • Two groups of developers – One supporting Manual Stack Management – The other strongly advocating the Automatic Stack Management • Pieces of Code exist written using both the styles of Stack Management • Need to find a glue!!

Solution Hybrid Approach: - Enables both styles (automatic and manual) to coexist in the same code base using Adaptors to connect between them. - Cooperative Tasks management can be achieved by scheduling multiple fibers on a single thread; at any given time, only one fiber is active. - Scheduler runs on a special fiber called MainFiber in both approaches. - Code with automatic stack management, that expects to block for I/O, always runs on a fiber other than MainFiber, when it blocks, it always yields control back to MainFiber, where scheduler selects the next task to schedule. - Compute only function, may run on any fiber. - Both types of stack management code are scheduled by the same scheduler(switching ).

Manual Calling Automatic and Automatic Calling Manual By Use of Adaptors Manual Automatic Manual Automatic

Working in both style using Adapters In hybrid task of CFA (Continuation- to-Fiber adaptor) , task has been blocked for the I/O initiated by the code with automatic stack management while ensuring that event handler FetchCert2 does not block. Later once I/O completes verifyFiber is resumed & then control return back to FiberStart. In hybrid task of FCA (Fiber-to-Continuation adaptor), automatic stack management needs to block for I/O, but manual simply schedules the I/O and returns. To reconcile, FCA used, that calls the manual code with a special continuation and relinquishes control to the MainFiber causing the adapter’s caller to remain blocked.

Implementation Of Cooperative Task Management Farsite - Uses Windows fibers, Cooperative threading - A distributed, secure, serverless file system - Run over desktops. UCoM - Uses automatic stack management (exclusively). - A wireless phone application - Designed for Windows CE OS(client application that runs with UI and audio support)

Conclusions Ongoing debate about “event-driven” vs “threaded” programming models got solved. With adapters in place, each style of code is unaware of the other. Choice of task management strategy(Cooperative task management) is fundamental but choice of stack management can be left to individual taste by using adapters. Fiber execution looks like a continuation to the event-driven code, and the continuation scheduler like any other fiber to the procedure-oriented code.

References John Ousterhout “Thanks to Jonathan Beare and   Amit Bhat for providing me nice graphics ” “Thread-based vs event-based implementation of a group communication service” S. Mishra and R. Yang.Thread-based “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