Why Events Are A Bad Idea (for high-concurrency servers)

Slides:



Advertisements
Similar presentations
1 Capriccio: Scalable Threads for Internet Services Matthew Phillips.
Advertisements

Why Events Are A Bad Idea (for high-concurrency servers) By Rob von Behren, Jeremy Condit and Eric Brewer.
Capriccio: Scalable Threads for Internet Services ( by Behren, Condit, Zhou, Necula, Brewer ) Presented by Alex Sherman and Sarita Bafna.
Precept 3 COS 461. Concurrency is Useful Multi Processor/Core Multiple Inputs Don’t wait on slow devices.
CS533 Concepts of Operating Systems Class 6 The Duality of Threads and Events.
Capriccio: Scalable Threads for Internet Services Rob von Behren, Jeremy Condit, Feng Zhou, Geroge Necula and Eric Brewer University of California at Berkeley.
Threads 1 CS502 Spring 2006 Threads CS-502 Spring 2006.
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,
Concurrency, Threads, and Events Robbert van Renesse.
CS Distributed Computing Systems Chin-Chih Chang, An Introduction to Threads.
CS533 Concepts of Operating Systems Class 2 The Duality of Threads and Events.
A. Frank - P. Weisberg Operating Systems Introduction to Tasks/Threads.
Why Events Are A Bad Idea (for high-concurrency servers) Rob von Behren, Jeremy Condit and Eric Brewer Computer Science Division, University of California.
CS 3013 & CS 502 Summer 2006 Threads1 CS-3013 & CS-502 Summer 2006.
Why Threads Are A Bad Idea (for most purposes) John Ousterhout Sun Microsystems Laboratories
1 Threads Chapter 4 Reading: 4.1,4.4, Process Characteristics l Unit of resource ownership - process is allocated: n a virtual address space to.
Why Events Are A Bad Idea (for high-concurrency servers) Rob von Behren, Jeremy Condit and Eric Brewer University of California at Berkeley
Why Events Are A Bad Idea (for high-concurrency servers) Rob von Behren, Jeremy Condit and Eric Brewer Presented by: Hisham Benotman CS533 - Concepts of.
Cooperative Task Management without Manual Stack Management Or, Event-driven Programming is not the Opposite of Thread Programming Atul Adya, John Howell,
Parallel Programming Models Jihad El-Sana These slides are based on the book: Introduction to Parallel Computing, Blaise Barney, Lawrence Livermore National.
Threads, Thread management & Resource Management.
SEDA: An Architecture for Well-Conditioned, Scalable Internet Services Presented by Changdae Kim and Jaeung Han OFFENCE.
Scheduler Activations: Effective Kernel Support for the User- Level Management of Parallelism. Thomas E. Anderson, Brian N. Bershad, Edward D. Lazowska,
Concurrent Programming. Concurrency  Concurrency means for a program to have multiple paths of execution running at (almost) the same time. Examples:
Rapid Development of High Performance Servers Khaled ElMeleegy Alan Cox Willy Zwaenepoel.
Capriccio: Scalable Threads for Internet Services Rob von Behren, Jeremy Condit, Feng Zhou, Geroge Necula and Eric Brewer University of California at Berkeley.
CS333 Intro to Operating Systems Jonathan Walpole.
5204 – Operating Systems Threads vs. Events. 2 CS 5204 – Operating Systems Forms of task management serial preemptivecooperative (yield) (interrupt)
Multithreaded Programing. Outline Overview of threads Threads Multithreaded Models  Many-to-One  One-to-One  Many-to-Many Thread Libraries  Pthread.
M. Accetta, R. Baron, W. Bolosky, D. Golub, R. Rashid, A. Tevanian, and M. Young MACH: A New Kernel Foundation for UNIX Development Presenter: Wei-Lwun.
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).
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.
By: Rob von Behren, Jeremy Condit and Eric Brewer 2003 Presenter: Farnoosh MoshirFatemi Jan
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.
CS533 Concepts of Operating Systems Jonathan Walpole.
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.
Paper Review of Why Events Are A Bad Idea (for high-concurrency servers) Rob von Behren, Jeremy Condit and Eric Brewer By Anandhi Sundaram.
Embedded Real-Time Systems Processing interrupts Lecturer Department University.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Multithreading vs. Event Driven in Code Development of High Performance Servers.
Introduction to threads
Threads & Multithreading
Chapter 4: Threads.
Threads vs. Events SEDA – An Event Model 5204 – Operating Systems.
Processes and Threads Processes and their scheduling
CS399 New Beginnings Jonathan Walpole.
Presenter: Godmar Back
Capriccio – A Thread Model
Chapter 4: Threads.
Threads and Data Sharing
On the Duality of Operating System Structures
Thread Implementation Issues
Fast Communication and User Level Parallelism
Threads Chapter 4.
Multithreaded Programming
Why Threads Are A Bad Idea (for most purposes)
Threads vs. Processes Hank Levy 1.
CS510 Operating System Foundations
Why Events Are a Bad Idea (for high concurrency servers)
CS333 Intro to Operating Systems
Chapter 4: Threads.
Why Threads Are A Bad Idea (for most purposes)
Why Threads Are A Bad Idea (for most purposes)
CS703 – Advanced Operating Systems
SEDA: An Architecture for Well-Conditioned, Scalable Internet Services
CS 5204 Operating Systems Lecture 5
Presentation transcript:

Why Events Are A Bad Idea (for high-concurrency servers) Paper: Rob von Behren, Jeremy Condit and Eric Brewer Presentation: David Baldwin

Overview Brief Recap: Threads vs. Events Review relevant details from prior classes Limitations and Criticisms of Threads Possible Ways to Improve Limitations Evaluation of Improvements Via simple web server implementation Discussion

Threads Useful tool for concurrency Allow the programmer to straightforwardly (?!) adapt serial program Provides primitives for shared memory access Can greatly improve performance when used correctly But... Deadlock and race conditions Tricky to get right in complex cases More on this later....

Threads vs. Events Events are advantageous for high concurrency (Ousterhout) No context switching between blocking calls No overhead from locking Deadlock easily avoidable Though circular events might create the same effect More memory efficient

Threads vs. Events Events are advantageous for high concurrency (Ousterhout) Fine tuning of scheduling based on the application Ease of debugging, subjective ease of programming vs. threads

Threads vs. Events A bit of a false dichotomy Duality of threads and events (Aday et. al., 2002; Lauer et al, 1978) Threads and events have the same 'blocking graph' Events are programmatically more explict about state, blocking calls and scheduling Thread libraries handle this for the programmer

Threads vs. Events Threads evolved from processes Obvious benefits: shared memory, comparably lightweight, etc. Original intent likely not thread-per-request web servers! The big questions of this paper: Is the thread abstraction intrinsically flawed? Can theoretical duality hold up in practice? What accounts for the differences between thread and event performance and consequences?

More Critiques of Threads 1. Threads have restricted control flow Unnatural for fan-in/out and pub/sub patterns 2. Synchronization is heavyweight Events get 'free' locking

More Critiques of Threads 3. Stack management Events unwind stacks upon completion 4. Scheduling Events can be explicit, threads are generic and libraries don't usually provide facilities to alter scheduling Events can exploit things like code locality by batch processing events 5. Events minimize live state Obvious memory advantages

More Critiques of Threads 6. Many thread based implementation of concurrent programs have not yielded large performance gains Context switching can be O(n) w.r.t. number of threads High cost of context switch Save registers Kernel crossings

Solutions and Responses 1. Threads have restricted control flow Most programs follow patterns that are more natural in threaded code Pipelines, call/return, parallel calls Most high concurrency applications use these

Threads vs. Events Events introduce their own complexity Stack ripping run(){ foo = readData(); bar = callWebService(foo); writeData(bar); } vs. readDataEvent(){ readDataAsync(callWebServiceEvent); } callWebServiceEvent(foo){ callWebServiceAsync(foo,writeDataEvent); writeDataEvent(bar){ writeDataAsync(bar) /* … and glue code (queue, etc); need continuations for local state*/

Solutions and Responses 2. Synchronization is heavyweight To some extent this is because events don't preempt each other Possibly true of any system Cooperative multithreading introduces some control over context switching

Solutions and Responses 3. Stack management Dynamic stack growth – upper bound space per function call Live state management – analyze which variables can be discarded from the stack 4. Scheduling Cooperatively scheduled threads can use same techniques as events Underlying libraries might be able to exploit same tricks as event systems

Solutions and Responses 5. Events minimize live state This can be a disadvantage! Threads naturally handle exceptions and other control flow issues Heap allocated events have trouble here Garbage collection difficult Case: Inktomi Traffic Server – an event based system with memory leaks

Solutions and Responses 6. Many thread based implementation of concurrent programs with threads have not yielded large performance gains Context switching can be O(n) w.r.t. number of threads This is an implementation issue that can be optimized away 10^5 threads possible on SEDA benchmark Using user threads instead of kernel

Performance Analysis Authors developed cooperative threading based web server - Knot Optimized context switching Blocking I/O translated to asynchronous Threading library and server ~6000 lines Compared to SEDA based web server (Haboob)

Performance Analysis Haboob and Knot-A accept new connections Haboob crashes at ~16000: out at memory

Conclusion Back to the big question: Is the thread abstraction intrinsically flawed? No, we can achieve similar performance What accounts for prior differences? Library implementation Program implementation Hardware But to show this, the authors make threads look more like events

And the winner is... Code complexity cuts both ways Events require stack ripping, explicit wiring between events; more up front coding work Both patterns can introduce subtle bugs Paper complementary to existing research Title a bit misleading “Why Threads and Events are Possibly Applicable (depending on your situation)” doesn't have the same ring to it....

And the winner is... No magic bullets for concurrency Threads and events are tools and abstractions that can be used and abused Performance is going to be based largely on your implementation (and your library) Large scale systems are likely to be some hybrid Efficient concurrent systems can be hard to program regardless of the paradigm The sad corollary: We still have to think when writing code

Additional Thoughts Concurrent and distributed systems A concurrent event code can be adapted to a distributed system more easily than a threaded one