Presentation is loading. Please wait.

Presentation is loading. Please wait.

By: Rob von Behren, Jeremy Condit and Eric Brewer 2003 Presenter: Farnoosh MoshirFatemi Jan-25-2012.

Similar presentations


Presentation on theme: "By: Rob von Behren, Jeremy Condit and Eric Brewer 2003 Presenter: Farnoosh MoshirFatemi Jan-25-2012."— Presentation transcript:

1 By: Rob von Behren, Jeremy Condit and Eric Brewer 2003 Presenter: Farnoosh MoshirFatemi Jan-25-2012

2 Contents  Background  Criticisms about threads  Advantages of Threads  Compiler support for threads  Evaluation  Conclusion 2

3 Background-Event based models Small, static number of processes Explicit message system for communication and synchronization A message-oriented system Pre-defined static communication mechanism One execution stream, no CPU concurrency No preemption of event handlers Blocked I/O is complex to handle. Stack ripping 3

4 Background-Thread-based models Large, rapidly changing processes Synchronization mechanism is based on shared data A procedure-oriented system through fork and join System recourses encoded as global data structures and shared through locks Blocked I/O is a blocked thread 4

5 Background-Three Opinions Events are better: There is no stack: managing state has lower overhead Cooperative multitasking: free synchronization (no need to mutexes and handle wait queues) Application level information: better scheduling, perform optimizations, and locality More flexible control flow 5

6 Background-Three Opinions Events and threads are equal Based on Lauer & Needham study Message-oriented and procedure-oriented systems are duals The choice should be made based on the nature of the machine architecture upon which the system is going to be built  What they missed: Most modern event systems use cooperative scheduling Most event systems use shared memory and global data structure, which are assumed atypical in their study SEDA is an exception 6

7 Background-Three Opinions Threads are better: Threads can have the same properties as events Threads can have some advantages over events for high concurrent systems Compiler improvements can eliminate historical drawbacks with threads 7

8 Contents  Background  Criticisms about threads  Advantages of Threads  Compiler support for threads  Evaluation  Conclusion 8

9 Criticisms about threads 1- Performance: have not performed well for high concurrency Respond: Poor thread implementations (thread packages were designed for both high concurrency and blocking operations) Operations with O(n) in the number of threads The context switch overhead and kernel crossing Have modified the GNU Pth user-level threading package Remove O(n) operations from the scheduler Repeated the SEDA threaded server benchmark Performance matches the event-based server 9

10 Criticisms about threads cont’d 2- Control Flow: restrictive control flow. - Encourage the programmer to think too linearly Respond: Complex patterns are not used (difficult and error prone) Threads express common patterns more naturally: - call/return - parallel calls - pipelines 10

11 Criticism about threads cont’d 3- Synchronization: heavyweight synchronization -Events have “free” synchronization Respond: Adya et al show that this advantage is due to cooperative multitasking, not events themselves It is “free” only with uniprocessor High-concurrency servers have multi processors 11

12 Criticisms about threads cont’d 4- State Management: Thread are not effective in managing live state A tradeoff between risking stack overflow and wasting address space on large stacks Event systems unwind the thread stack after each event handler Respond: Have proposed a mechanism which allow stack to grow dynamically. (later) 12

13 Criticisms about threads cont’d 5- Scheduling: can’t optimize scheduling decisions Runtime system is too generic in thread-based Event systems can schedule at application level (better scheduling, and code locality) Respond: Lauer and Needham indicate that the cooperatively scheduled threads can have the same scheduling tricks Threads and events are equivalent in power 13

14 Contents  Background  Criticisms about threads  Advantages of Threads  Compiler support for threads  Evaluation  Conclusion 14

15 Advantages of Threads Observations about modern servers : 1- The concurrency is because of the largely independent concurrent requests 2- The code that handles each code is usually sequential  Threads provide a better programming abstraction for servers. 15

16 Advantages of Threads cont’d Control Flow: Event-based systems: tend to obfuscate the control flow 1- Programmer has to manually match the call/return pairs 2-Manually save and restore live state. “Stack Ripping” Thread-based systems: express control flow in a more natural manner 1- Group calls with returns. Ensuring a one-to-one relationship. 2- live state encapsulate at stack. Much easier debugging 16

17 Advantages of Threads cont’d Exception Handling and state Lifetime -The thread stack tracks the live state. cleaning up task state is simple. -In event systems, task state is typically heap allocated. (difficult to freeing it on time) -Garbage collection is inappropriate for high performance systems. 17

18 Advantages of Threads cont’d Existing Systems: - The event-based systems, using thread in the complex parts of the code: Ninja system - Applications without a high concurrency also using threads for simplicity: FTP server in Harvest uses threads Just Fix Events: - Fixing the problems with events is equal to switching to threads Threads have advantages over events 18

19 Contents  Background  Criticisms about threads  Advantages of Threads  Compiler support for threads  Evaluation  Conclusion 19

20 Compiler support for threads Minor modification can improve safety and performance of the threaded systems 1-Dynamic Stack Growth: Analyze upper bound on the stack size when calling a function Determine which call sites may require stack growth 20

21 Compiler support for threads cont’d 2- Live State Management: Remove unnecessary state from the stack -temporary variables before calling subroutines -popped entire frame in tail call. 3- Synchronization With compiler analysis can: - Warn the programmer about data races (reduce the occurrence of bugs) - Determine which atomic sections are safe to run concurrently. 21

22 Contents  Background  Criticisms about threads  Advantages of Threads  Compiler support for threads  Evaluation  Conclusion 22

23 Evaluation Designed and implemented a simple user-level cooperative threading package for Linux (5000 line) used the package to write a test web server, Knot. (700 line) Compared the performance of Knot with Haboob (SEDA’s event-driven web server) Two different scheduling policies for Knot: 1-favors processing of current connections 2-favors processing of accepting connections 23

24 Web server bandwidth versus the number f simultaneous clients. 24

25 Contents  Background  Criticisms about threads  Advantages of Threads  Compiler support for threads  Evaluation  Conclusion 25

26 Conclusion Threads have the similar or better performance than events in high concurrency systems Improvement to compiler can eliminate threads’ problems 26

27


Download ppt "By: Rob von Behren, Jeremy Condit and Eric Brewer 2003 Presenter: Farnoosh MoshirFatemi Jan-25-2012."

Similar presentations


Ads by Google