질문하기질문하기
 

답변됨PLINQ vs LINQ

  • 2009년 4월 21일 화요일 오전 3:25Han Cheng 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    I am trying to compare the benefits of PLINQ vs LINQ but it seems that the time taken to retrieve data in PLINQ is the same as LINQ.

    Does anyone has same code to compare PLINQ vs LINQ using AsParallel()?

답변

  • 2009년 4월 21일 화요일 오전 4:46Reed Copsey, Jr. 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨
    Check out this article describing the benefits: http://www.scip.be/index.php?Page=ArticlesNET08&Lang=EN

    Just realize that you need to make sure the objects you are querying, and the query itself, are able to take advantage of parallelism.  Also, if you only have a single core/processor, plinq will likely be slower, due to the extra overhead of initialization.

  • 2009년 4월 21일 화요일 오후 9:49Stephen Toub - MSFTMSFT, 중재자사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨
    Thanks, Reed.  Also please keep in mind that a lot of the performance work on Parallel Extensions was not available in the June 2008 CTP, which influences any kind of performance analysis.  The performance in many areas will be significantly better in the future, as a lot of work has happened there and will continue to moving forward.

모든 응답

  • 2009년 4월 21일 화요일 오전 4:46Reed Copsey, Jr. 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨
    Check out this article describing the benefits: http://www.scip.be/index.php?Page=ArticlesNET08&Lang=EN

    Just realize that you need to make sure the objects you are querying, and the query itself, are able to take advantage of parallelism.  Also, if you only have a single core/processor, plinq will likely be slower, due to the extra overhead of initialization.

  • 2009년 4월 21일 화요일 오후 9:49Stephen Toub - MSFTMSFT, 중재자사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨
    Thanks, Reed.  Also please keep in mind that a lot of the performance work on Parallel Extensions was not available in the June 2008 CTP, which influences any kind of performance analysis.  The performance in many areas will be significantly better in the future, as a lot of work has happened there and will continue to moving forward.
  • 2009년 4월 21일 화요일 오후 11:28Reed Copsey, Jr. 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    Glad to hear the performance is getting better on this.

    The June CTP was still impressive in many cases - I still wish that it would be redistributable for .net 3.5...   (but I'll wait 'till 4.0 since I need to. ;)  )
  • 2009년 7월 1일 수요일 오전 10:07Konstantin Bykov 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     코드 있음
    Oh, yes. Today I had compare speed queries in LINQ and PLINQ. In PLINQ queries perform little slower then in LINQ.
    I have two core processor, two List<> objects with 292831 and 1694019 records and LINQ query like this:

    var pereza =
    from a in Lresult43
    join b in Lresult44 on a.family + a.name + a.father + a.vozrast.ToString() equals b.family + b.name + b.father + b.vozrast.ToString()
    select new
    {
    family = a.family,
    name = a.name,
    father = a.father,
    vozrast = a.vozrast,
    family2 = b.family,
    name2 = b.name,
    father2 = b.father,
    vozrast2 = b.vozrast,
    key = a.family + a.name + a.father + a.vozrast.ToString()
    };


    P.s.: Sorry for my bad english :)
  • 2009년 7월 1일 수요일 오후 10:29Ed Essey - MSFTMSFT, 소유자사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     제안된 답변

    Konstantin Bykov,
    Thank you for sharing your query and experience.  There are some cases where even with a lot of records, you still may not see speedups in PLINQ.  Operators such as Join, which your query uses, and GroupBy require implementations with a lot of data contention.  These use our hash partitioning algorithm, as described in the blog post at http://blogs.msdn.com/pfxteam/archive/2009/05/28/9648672.aspx.

    Some performance improvements have been made on Join since Beta1; so you may already begin to see gains there.  It's hard for me to speculate on the performance without understanding more factors of your data, such as how many matches will occur in your joins.  However, what I can tell you is the chaining the joins with other operators and larger delegates are likely to show you overall performance gains on your queries.  Your select statement performs very little work, so the overhead of partitioning isn't really recovered by the small amount of work done in the select body.

    For cases like this, looking at both LINQ-to-objects and PLINQ performance is recommended.

  • 2009년 7월 3일 금요일 오전 3:27Konstantin Bykov 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     코드 있음
    Thanks for your attention!
    I had modificy my code for reduse "Your select statement performs very little work". And my test on LINQ-to-object. I understand it from begin. It's my code:

            private void CreateDatasetInMemory()
            {
                try
                {
                    Console.WriteLine("Copyng two reestrs to the memory.");
                    DateTime startOp = DateTime.Now;
                    DataContext db = new DataContext(TaskTests.Properties.Settings.Default.polisesConnectionString);
                    IEnumerable<resultQ> result44 = db.ExecuteQuery<resultQ>(@"some query");
                    IEnumerable<resultQ> result43 = db.ExecuteQuery<resultQ>(@"some query");
                    List<resultQ> Lresult44 = new List<resultQ>(result44);//coping data to the memory
                    List<resultQ> Lresult43 = new List<resultQ>(result43);//coping data to the memory
                    Console.WriteLine(
                        "44 count: " + Lresult44.Count.ToString() +
                        "\n43 count: " + Lresult43.Count.ToString());
                    DateTime stopOp = DateTime.Now;
                    TimeSpan span = stopOp - startOp;
                    Console.WriteLine("Spended time for this: " + span.ToString());
                    Console.WriteLine("Test begin.");
                    startOp = DateTime.Now;
                    IEnumerable<Pereza> pereza =
                        from a in Lresult43.AsParallel()
                        join b in Lresult44.AsParallel() on a.family + a.name + a.father + a.vozrast.ToString() equals b.family + b.name + b.father + b.vozrast.ToString()
                        select new Pereza(
                            a.family,
                            a.name,
                            a.father,
                            a.vozrast,
                            b.family,
                            b.name,
                            b.father,
                            b.vozrast,
                            a.family + a.name + a.father + a.vozrast.ToString());
                    List<Pereza> pp = new List<Pereza>(pereza);//reduse "Your select statement performs very little work"
                    Console.WriteLine("Q: How many matches will occur in your joins?\nA: " + pp.Count());
                    stopOp = DateTime.Now;
                    span = stopOp - startOp;
                    Console.WriteLine("Spended time for join: " + span.ToString());
                }
                catch (Exception er)
                {
                    Console.WriteLine(er.Message);
                    Console.WriteLine(er.StackTrace);
                    //throw;
                }
            }
    
            public class resultQ
            {
                public string family;
                public string name;
                public string father;
                public string pol;
                public DateTime vozrast;
                public DateTime vidacha;
                public DateTime sdacha;
            }
    
            public class Pereza
            {
                public string family;
                public string name;
                public string father;
                public DateTime vozrast;
                public string family2;
                public string name2;
                public string father2;
                public DateTime vozrast2;
                public string key;
    
                public Pereza(string family,
                     string name,
                     string father,
                     DateTime vozrast,
                     string family2,
                     string name2,
                     string father2,
                     DateTime vozrast2,
                     string key)
                {
                    this.family=family;
                    this.name=name;
                    this.father=father;
                    this.vozrast=vozrast;
                    this.family2=family2;
                    this.name2=name2;
                    this.father2=father2;
                    this.vozrast2=vozrast2;
                    this.key = key;
                }
            }
    
    




    Result W/O parallelism:
    Copyng two reestrs to the memory.
    44 count: 292831
    43 count: 1694019
    Spended time for this: 00:00:30.4565040
    Test begin.
    Q: How many matches will occur in your joins?
    A: 55193
    Spended time for join: 00:00:05.7619060

    Result W/parallelism ( Lresult43.AsParallel() and Lresult44.AsParallel() ) :
    Copyng two reestrs to the memory.
    44 count: 292831
    43 count: 1694019
    Spended time for this: 00:00:30.3212376
    Test begin.
    Q: How many matches will occur in your joins?
    A: 55193
    Spended time for join: 00:00:06.3570816


    Any comment?