Ask a questionAsk a question
 

AnswerCreating many classes instances in parallel

  • Tuesday, October 06, 2009 7:21 AMphilippe lombaers Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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

  • Friday, October 09, 2009 1:12 AMStephen Toub - MSFTMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    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>

All Replies

  • Wednesday, October 07, 2009 12:10 PMAndy Clymer Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Philippe,

    At a guess I would say no, but it does depend on

    1) how complex the projection is
    2) 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...


  • Wednesday, October 07, 2009 7:44 PMphilippe lombaers Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Philippe,

    At a guess I would say no, but it does depend on

    1) how complex the projection is
    2) 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
  • Friday, October 09, 2009 1:12 AMStephen Toub - MSFTMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    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>