InfoQ

InfoQ

News

My Bookmarks

Login or Register to enable bookmarks for unlimited time.

The content has been bookmarked!

There was an error bookmarking this content! Please retry.

Patterns and Samples for .NET Parallel Extensions

Posted by Jonathan Allen on Apr 21, 2010

Sections
Development,
Architecture & Design
Topics
Performance & Scalability ,
.NET
Tags
Parallel Programming ,
PLINQ ,
Concurrency ,
Coordination Data Structures

Even though Microsoft has been working on .NET’s Parallel Extensions since 2007, there are still many features that they didn’t have time to fully implement for .NET 4.0. Some features were “too application-specific to be included in the core of the Framework” while others simply needed for testing and user feedback. Stephen Toub continues,

Luckily, in the vast majority of these cases, we’ve been able to build this functionality on top of the parallelizatino constructs provided in .NET 4, in some cases simply containing .NET 4 types and methods, and in other cases taking advantage of extensibility points provided in .NET 4 for the explicit purpose of enabling developers to provide their own customized functionality where the Framework leaves off. Over time, we’ve amassed a wealth of code of this ilk, and we’ve chosen to expose most of it through the ParallelExtensionsExtras project available as part of our .NET 4 samples, which can be downloaded at http://code.msdn.microsoft.com/ParExtSamples.

The code samples cover a wide range of functionality. Some of the highlights include:

An IProducerConsumerCollection implementation for the BlockingCollection wrapper. This interface is for thread-safe collections in traditional producer/consumer scenarios. This wasn’t included in .NET 4.0 because the correct semantics for a BlockingCollection version could vary depending on the application’s needs.

For working with COM components that require single-threaded apartments there is the StaTaskScheduler. The base version of the StaTaskScheduler is pretty simple, it simply spins up a predefined number of STA threads and waits for tasks to perform. A suggested variant is to use thread-local storage to instantiate one instance of a COM object for each worker thread.

For those interested in the Reactive Extensions Framework, there is the Task.ToObservable extension method. This allows a subscription to be attached to the result of a Task. If the subscription is dropped before the task is completed, then the task will be cancelled.

A rather complex scenario is the ReductionVariable. This contains a set of values, one per instance per thread, for use in reduction operations. Based on thread-local storage, it requires very little synchronization between worker threads and thus scales up well. Once the reduction operation is complete, the values can be enumerated over to generate the final result.

No comments

Watch Thread Reply

Educational Content

New-age Transactional Systems - Not Your Grandpa's OLTP

John Hugg discusses high volume transaction processing applications with high and low frequency profiles, and how VoltDB can be used for that purpose.

Cool Code

Kevlin Henney examines code samples to see what can be learned from them starting from the premise that one won’t write great code unless he knows how to read it.

Collaboration: At the Extremities of Extreme

Jason Ayers share the observations he made watching a team of developers collaborating in real time on the same code base, pushing XP, pair programming and continuous integration to their extremes.

Yesod Web Framework

Michael Snoyman presents Yesod, a web framework written in Haskell and containing a web server, templating, ORM, libraries (templating, gravatar, etc.).

Transactions without Transactions

Richard Kreuter and Kyle Banker on how to avoid classical RDBMS transactional systems by using compensation mechanisms, transactional messaging or transactional procedures.

Attila Szegedi on JVM and GC Performance Tuning at Twitter

Attila Szegedi talks about performance tuning Java and Scala programs at Twitter: how to approach GC problems, the importance of asynchronous I/O, when to use MySQL/Cassandra/Redis, and much more.

10 tips on how to prevent business value risk

One category of risk that project teams need to ensure they address is business value failure – delivering a product that fails to provide value for the business investor.

Interview: Software Systems Architecture: Working With Stakeholders Using Viewpoints and Perspectives

InfoQ spoke to the authors of Software Systems Architecture on a couple of new topics, the System Context viewpoint and Agile, which have been added to the second edition.