Concurrent programming from thread pool to parallel extensions
Download
1 / 30

Concurrent Programming: From Thread Pool to Parallel Extensions - PowerPoint PPT Presentation


  • 68 Views
  • Uploaded on

Concurrent Programming: From Thread Pool to Parallel Extensions. Sasha Goldshtein Senior Consultant, Sela Group http://blogs.microsoft.co.il/blogs/sasha. The Reason We’re Here. I spare you: “The free lunch is over” “Moore’s law has changed”

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Concurrent Programming: From Thread Pool to Parallel Extensions' - palmer


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Concurrent programming from thread pool to parallel extensions

Concurrent Programming: From Thread Pool to Parallel Extensions

Sasha Goldshtein

Senior Consultant, Sela Group

http://blogs.microsoft.co.il/blogs/sasha


The reason we re here
The Reason We’re Here Extensions

  • 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


There is no silver bullet
There Is No Silver Bullet Extensions

  • Code, rinse, repeat

  • Patterns are emerging

  • Frameworks are emerging


So what s in this session
So What’s In This Session? Extensions

  • What kind of work likes parallelism?

  • Threads and thread pool

  • APM

  • Synchronization (is hard)

  • Concurrency architecture and patterns

  • Upcoming frameworks


The faces of parallelism
The Faces Of Parallelism Extensions

  • 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


System threading 101
System.Threading 101 Extensions

  • Create a thread (System.Thread) for each user request

  • Why is this BAD?


Demo Extensions

Thread per request


Threads bad tasks good 102
Threads Bad; Tasks Good (102) Extensions

  • Task: An independent unit of work

  • Thinking in tasks decouples us from threads

  • Scheduling is done by a resource manager

  • Revised server: ThreadPool.QueueUWI()


Demo Extensions

Fire-and-forget using System.ThreadPool


What if the thread pool explodes
What If The Thread Pool Explodes? Extensions

  • 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


DEMO Extensions

Bounded thread pool


System threading 103

We depend on tasks! Extensions

System.Threading 103

  • User clicks a button

  • Synchronous operation = UI not responsive

  • Fix: Execute the request asynchronously and (somehow) get the response later


Demo Extensions

The ubiquitous APM


Synchronization intermezzo
Synchronization Intermezzo Extensions

  • Shared writeable data will become corrupt unless protected

  • Design aspects: Lock high / lock low

  • Don’t lock on the first line of Main() 


Synchronization problems
Synchronization Problems Extensions

  • 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


Demo Extensions

Lock leveling


Advanced synchronization problems
Advanced Synchronization Problems Extensions

  • Reentrancy

  • Lock convoys

  • N readers, one writer


Architecting concurrency
Architecting Concurrency Extensions

  • Partition

  • Pipeline

  • Pipeline X Partition = Grid


Announcing
Announcing Extensions

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


Partitioning patterns
Partitioning Patterns Extensions

  • Data-Driven Parallelism

    • CountdownEvent

    • PLINQ / Parallel.For


Pipeline patterns
Pipeline Patterns Extensions

  • N-1 producers, N-1 consumers

    • BoundedQueue

    • BlockingQueue

    • Condition variable (Wait/Pulse)

    • Cyclic buffer


DEMO Extensions

Concurrency patterns in action


Advanced patterns
Advanced Patterns Extensions

  • Read/write cache

  • Init-once


Tooling support
Tooling Support Extensions

  • Multi-threaded profilers

  • Multi-threaded debuggers

  • Runtime “bug trappers”

  • Visual Studio 2010

    • Grab the CTP now



Visual studio 2010 parallel stacks
Visual Studio 2010 Parallel Stacks Extensions

  • With an abundance of tasks, call stack view is not enough!


Summary
Summary Extensions

  • 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


Related sessions
Related Sessions Extensions

ARC301: "Velocity": Distributed Cache …

Yair Shibak

16:00 – 17:10 Tavor Hall



© Extensions2008 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.


ad