Parallel Computing Developer Center >
Parallel Computing Forums
>
Parallel Extensions to the .NET Framework
>
Creating many classes instances in parallel
Creating many classes instances in parallel
- Hello,
My scenario is the following :
I have a server app that creates entitty collections and transforms those into DTO (data transport objects - WCF).
List<CustomerDTO> custDto = new List<CustomerDTO>
foreach (CustomerEntity cust in custEntities)
custDto.Add(cust.ToDto());
This consists of only creating an object (DTO) and filling its properties with the entity properties.
Can I expect some performace improvements on a multicore machine by using parallel extension ?
One important thing is that the order should remain the same since it is the result of an ORDER BY.
Thanks
philippe
Answers
- You can use PLINQ to maintain the ordering, e.g.
List<CustomerDto> custDto = custEntities.AsParallel().AsOrdered().Select(cust => cust.ToDto()).ToList();
Without knowing what ToDto does, it's hard to say whether this will scale well or not, but you can certainly try it out and see. Note that if a lot of object allocation is being done, as it appears it may be, you might also try enabling the server GC in the configuration file for your application, e.g.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<runtime>
<gcServer enabled="true"/>
</runtime>
</configuration>- Proposed As Answer byStephen Toub - MSFTMSFT, ModeratorFriday, October 09, 2009 1:12 AM
- Marked As Answer byStephen Toub - MSFTMSFT, ModeratorTuesday, October 13, 2009 7:06 AM
All Replies
- Philippe,At a guess I would say no, but it does depend on1) how complex the projection is2) how many cores you have.Since this a server app Im guessing you will be potentially taking advantage of multiple cores at a more coarse grain level.Bottom line is try it...
Philippe,
At a guess I would say no, but it does depend on1) how complex the projection is2) how many cores you have.Since this a server app Im guessing you will be potentially taking advantage of multiple cores at a more coarse grain level.Bottom line is try it...
Thanks for your answer.
1) it can be complex since dto's contains child tables
2) it's a 8 core server running vmware and each machine of my cluster is only allocated 1 processor.
Is it possible while using multithreading to keep the dto list in the same order as the entity list ?
philippe- You can use PLINQ to maintain the ordering, e.g.
List<CustomerDto> custDto = custEntities.AsParallel().AsOrdered().Select(cust => cust.ToDto()).ToList();
Without knowing what ToDto does, it's hard to say whether this will scale well or not, but you can certainly try it out and see. Note that if a lot of object allocation is being done, as it appears it may be, you might also try enabling the server GC in the configuration file for your application, e.g.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<runtime>
<gcServer enabled="true"/>
</runtime>
</configuration>- Proposed As Answer byStephen Toub - MSFTMSFT, ModeratorFriday, October 09, 2009 1:12 AM
- Marked As Answer byStephen Toub - MSFTMSFT, ModeratorTuesday, October 13, 2009 7:06 AM


