none
When AsParallel() spawn new multiple thread RRS feed

  • Question

  • dtFilterDataFromAllData.AsEnumerable().AsParallel().Any(w => w.Field<string>("BRTab") == BRTab
    && w.Field<string>("RowNumber") == RowNumber
    && w.Field<string>("StandardDate").Replace("A", "").Replace("E", "") 
    == strPeriod.Replace("A", "").Replace("E", ""))

    dtFilterDataFromAllData is datatable.

    Please see my code where i used AsParallel() but found no as such speed. i am querying datatable which has 10,000 data. so i like to know exactly
    when AsParallel() gives more speed. for how much or how many data AsParallel() spawn new multiple thread ?

    please discuss with my code. thanks
    Friday, March 13, 2020 7:24 AM

Answers

  • Hi Sudip_inn,

    Thank you for posting here.

    Parallelism doesn't necessarily speed things up.

    Whether parallelism can speed up execution depends on the complexity of the task. If linq's functionality is complex, then using parallelism will speed things up, but if linq's functionality is simple, it is not necessarily because the overhead of parallelization will offset most or all of the acceleration.

    But there are no clear boundaries, so we cannot say whether parallelism should be used.

    You can write down both cases and then try with Stopwatch before deciding whether to use parallelism.

    As for the number of parallel threads, Microsoft provides a way to limit the maximum:

    ParallelEnumerable.WithDegreeOfParallelism<TSource>(ParallelQuery<TSource>, Int32) Method

    But there is no mention of when new threads will be added, and I don't know if we can intervene manually.

    If I find relevant information, I will post it here.

    Here are some documents provided by Microsoft about Plinq, you can take a look at them.

    Potential pitfalls with PLINQ

    Introduction to PLINQ

    Understanding Speedup in PLINQ

    How to: Measure PLINQ Query Performance

    Hope this could be helpful.

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Friday, March 13, 2020 9:31 AM
  • In addition, if dtFilterDataFromAllData came from a database, then it's quite likely the bottleneck is not in your code at all.  You have to fetch all of those records from the server.  If it takes 3 seconds to transfer all of your data from the server, then it's going to take 3 seconds, no matter how many threads you use.

    Tim Roberts | Driver MVP Emeritus | Providenza &amp; Boekelheide, Inc.

    • Marked as answer by Sudip_inn Wednesday, March 18, 2020 7:11 PM
    Saturday, March 14, 2020 5:26 AM

All replies

  • Hi Sudip_inn,

    Thank you for posting here.

    Parallelism doesn't necessarily speed things up.

    Whether parallelism can speed up execution depends on the complexity of the task. If linq's functionality is complex, then using parallelism will speed things up, but if linq's functionality is simple, it is not necessarily because the overhead of parallelization will offset most or all of the acceleration.

    But there are no clear boundaries, so we cannot say whether parallelism should be used.

    You can write down both cases and then try with Stopwatch before deciding whether to use parallelism.

    As for the number of parallel threads, Microsoft provides a way to limit the maximum:

    ParallelEnumerable.WithDegreeOfParallelism<TSource>(ParallelQuery<TSource>, Int32) Method

    But there is no mention of when new threads will be added, and I don't know if we can intervene manually.

    If I find relevant information, I will post it here.

    Here are some documents provided by Microsoft about Plinq, you can take a look at them.

    Potential pitfalls with PLINQ

    Introduction to PLINQ

    Understanding Speedup in PLINQ

    How to: Measure PLINQ Query Performance

    Hope this could be helpful.

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Friday, March 13, 2020 9:31 AM
  • In addition, if dtFilterDataFromAllData came from a database, then it's quite likely the bottleneck is not in your code at all.  You have to fetch all of those records from the server.  If it takes 3 seconds to transfer all of your data from the server, then it's going to take 3 seconds, no matter how many threads you use.

    Tim Roberts | Driver MVP Emeritus | Providenza &amp; Boekelheide, Inc.

    • Marked as answer by Sudip_inn Wednesday, March 18, 2020 7:11 PM
    Saturday, March 14, 2020 5:26 AM
  • No dtFilterDataFromAllData datatable has data which is coming from xml file. i saw when there is huge data stored in datatable and when i use AsParallel to query that datatable then i am getting better performance but when there is not much data in dtFilterDataFromAllData datatable then AsParallel does not work for faster search.

    so i like to know for how much data i should use  AsParallel()? i am not getting any clear idea after searching google. if you know then please share some idea. thanks

    Wednesday, March 18, 2020 7:15 PM