Poser une questionPoser une question
 

TraitéePLINQ vs LINQ

  • mardi 21 avril 2009 03:25Han Cheng Médailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     
    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()?

Réponses

  • mardi 21 avril 2009 04:46Reed Copsey, Jr. Médailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     Traitée
    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.

  • mardi 21 avril 2009 21:49Stephen Toub - MSFTMSFT, ModérateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     Traitée
    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.

Toutes les réponses

  • mardi 21 avril 2009 04:46Reed Copsey, Jr. Médailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     Traitée
    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.

  • mardi 21 avril 2009 21:49Stephen Toub - MSFTMSFT, ModérateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     Traitée
    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.
  • mardi 21 avril 2009 23:28Reed Copsey, Jr. Médailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     
    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. ;)  )
  • mercredi 1 juillet 2009 10:07Konstantin Bykov Médailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     A du code
    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 :)
  • mercredi 1 juillet 2009 22:29Ed Essey - MSFTMSFT, PropriétaireMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     Réponse proposée

    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.

  • vendredi 3 juillet 2009 03:27Konstantin Bykov Médailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     A du code
    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?