Download
concurrent programming from thread pool to parallel extensions n.
Skip this Video
Loading SlideShow in 5 Seconds..
Concurrent Programming: From Thread Pool to Parallel Extensions PowerPoint Presentation
Download Presentation
Concurrent Programming: From Thread Pool to Parallel Extensions

Concurrent Programming: From Thread Pool to Parallel Extensions

82 Vues Download Presentation
Télécharger la présentation

Concurrent Programming: From Thread Pool to Parallel Extensions

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Concurrent Programming: From Thread Pool to Parallel Extensions Sasha Goldshtein Senior Consultant, Sela Group http://blogs.microsoft.co.il/blogs/sasha

  2. The Reason We’re Here • I spare you: • “The free lunch is over” • “Moore’s law has changed” • “Amdahl’s law demands shift in software concepts” • I give you: Sasha’s Law Only Parallel Applications Will Survive

  3. There Is No Silver Bullet • Code, rinse, repeat • Patterns are emerging • Frameworks are emerging

  4. So What’s In This Session? • What kind of work likes parallelism? • Threads and thread pool • APM • Synchronization (is hard) • Concurrency architecture and patterns • Upcoming frameworks

  5. The Faces Of Parallelism • Embarrassingly parallel applications: • Calculating prime numbers, predicting weather • (Partially) CPU-bound applications: • Business rule engine, database server • I/O-bound applications: • Web server, file server, web browser

  6. System.Threading 101 • Create a thread (System.Thread) for each user request • Why is this BAD?

  7. Demo Thread per request

  8. Threads Bad; Tasks Good (102) • Task: An independent unit of work • Thinking in tasks decouples us from threads • Scheduling is done by a resource manager • Revised server: ThreadPool.QueueUWI()

  9. Demo Fire-and-forget using System.ThreadPool

  10. What If The Thread Pool Explodes? • There is no throttling: • Arrival rate: 1,000/second • Execution rate: 10/second • What do you think will happen? • We need a bounded thread pool

  11. DEMO Bounded thread pool

  12. We depend on tasks! System.Threading 103 • User clicks a button • Synchronous operation = UI not responsive • Fix: Execute the request asynchronously and (somehow) get the response later

  13. Demo The ubiquitous APM

  14. Synchronization Intermezzo • Shared writeable data will become corrupt unless protected • Design aspects: Lock high / lock low • Don’t lock on the first line of Main() 

  15. Synchronization Problems • Resources are now protected • Performance is not: Contention • Execution flow is not: • Wait chain: T1 -> M1 -> T2 -> M2 -> T1 • Forward progress: • Timeouts (cf. DB transactions) • Lock leveling

  16. Demo Lock leveling

  17. Advanced Synchronization Problems • Reentrancy • Lock convoys • N readers, one writer

  18. Architecting Concurrency • Partition • Pipeline • Pipeline X Partition = Grid

  19. Announcing Parallel Extensions for .NET 4.0 (Parallel LINQ, Coordination Data Structures, Task Parallel Library)

  20. Partitioning Patterns • Data-Driven Parallelism • CountdownEvent • PLINQ / Parallel.For

  21. Pipeline Patterns • N-1 producers, N-1 consumers • BoundedQueue • BlockingQueue • Condition variable (Wait/Pulse) • Cyclic buffer

  22. DEMO Concurrency patterns in action

  23. Advanced Patterns • Read/write cache • Init-once

  24. Tooling Support • Multi-threaded profilers • Multi-threaded debuggers • Runtime “bug trappers” • Visual Studio 2010 • Grab the CTP now

  25. Visual Studio 2010 Tasks Window

  26. Visual Studio 2010 Parallel Stacks • With an abundance of tasks, call stack view is not enough!

  27. Summary • Exit threads; enter tasks • Only parallel applications will survive • CPU-bound: TPL, PLINQ, thread pool • I/O-bound: APM • Shared state is a key problem • Patterns and frameworks are emerging • Tooling support

  28. Related Sessions ARC301: "Velocity": Distributed Cache … Yair Shibak 16:00 – 17:10 Tavor Hall

  29. Please Fill your Evaluation!

  30. © 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.