Impications of setting MaxDegreeOfParallelism for TPL Actions to an odd number? RRS feed

  • Question

  • User1000638852 posted

    I am tuning max threads with the TPL statement because my tasks include sql calls so that I do overwhelm the database:

         Parallel.Invoke(new ParallelOptions { MaxDegreeOfParallelism = intWebConfigThreadSetting }, listActions.ToArray());

    The box this code will be run on has a dual core. As such, is there any advantage or disadvantage to having an odd number as the MaxDegreeOfParallelism setting?

    What are the considerations?

    Monday, February 23, 2015 10:17 AM


  • User1644755831 posted

    Hi jjmonty,

    By default, For and ForEach will utilize however many threads the underlying scheduler provides, so changing MaxDegreeOfParallelism from the default only limits how many concurrent tasks will be used.

    Generally, you do not need to modify this setting. However, you may choose to set it explicitly.

    1. When you know that a particular algorithm you're using won't scale beyond a certain number of cores. You can set the property to avoid wasting cycles on additional cores.

    2.When you're running multiple algorithms concurrently and want to manually define how much of the system each algorithm can utilize. You can set a MaxDegreeOfParallelism value for each.

    3.When the thread pool's heuristics is unable to determine the right number of threads to use and could end up injecting too many threads.

    With Regards,

    Krunal Parekh

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 23, 2015 10:19 PM