Search code examples
.netc#-4.0amazon-ec2plinq

Using .NET ThreadPool on AWS EC2


Does anyone have experience with using default .NET ThreadPool using .NET 4 Parallel or Task framework on Amazon EC2 instances?

The documentation says that .NET will use Environment.ProcessorCount to figure out the optimal thread count. However I'm not sure that EC2 instances will give you the right ProcessorCount as it is measured on compute units and allocation may vary depending on need.

What is the right way to do this? Do you have to work out and set the ParallelOptions.MaxDegreeOfParallelism Property?


Solution

  • EC2 Instances are measured in Compute Units but they also have virtual cores. An X-Large instance for example has 4 Cores @ 2 Compute Units - total 8 Compute Units.

    A full spec is here: http://gevaperry.typepad.com/main/2009/03/figuring-out-the-roi-of-infrastructureasaservice.html

    Given that you're still working with cores, albeit virtual cores. Its probably best to leave .NET to figure out its own Threadpool Size. An EC2 instance is not much different to a dedicated server from the .NET framework's point of view. Some servers have lots of cores and a big threadpool, some have small number of cores and therefore a smaller threadpool. Leave it to .NET to figure it out.