Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-57518

34% performance loss switching from Count to CountDocuments

    XMLWordPrintable

Details

    • Bug
    • Status: Open
    • Major - P3
    • Resolution: Unresolved
    • 4.4.5, 4.0.25
    • None
    • None
    • ALL
    • Hide

      Run in shell (Robo 3T 1.2.1 doesnt know countDocuments, so we wrote it out fully)

      function stopwatch(func) {
          var iters = 10;
          var start = new Date();
          for(var i=0; i<iters; i++) {
              func();
          }
          var end = new Date();
          print((end-start)/iters + " ms");
      }
      stopwatch(() => db.largeCollection.count({Om:0}));
      stopwatch(() => db.largeCollection.aggregate([{$match: {Om:0}}, {$group: {_id: null, count: {$sum:1}}}]))
      

      Show
      Run in shell (Robo 3T 1.2.1 doesnt know countDocuments, so we wrote it out fully) function stopwatch(func) { var iters = 10 ; var start = new Date(); for (var i= 0 ; i<iters; i++) { func(); } var end = new Date(); print((end-start)/iters + " ms" ); } stopwatch(() => db.largeCollection.count({Om: 0 })); stopwatch(() => db.largeCollection.aggregate([{$match: {Om: 0 }}, {$group: {_id: null , count: {$sum: 1 }}}]))
    • QO 2022-04-04, QO 2022-04-18, QO 2022-05-02, QO 2022-05-16, QO 2022-05-30, QO 2022-06-13

    Description

      Dear Server team,

      I'm a C# dev on a team using MongoDb and I have the task to clean up the compile warnings. One warning was "Count is obsolete. Use CountDocuments instead"

      But at every occurrence in the code,  at all the lines have the comment "Don't use CountDocuments, it is slower", referencing Jira NODE-1638.

      I did my own tests and indeed found CountDocuments to be about 34% slower then Count (~150 ms longer). That is quite significant and thus a problem for us, as we are already having performance issues.

      First thinking this was a C# driver issue, I opened a ticket CSHARP-3680 and had some interaction there. However, we found out that the issue already occurs on the server, thus should get a new SERVER ticket.

      Please read CSHARP-3680 for all the details and let me know what more information you need.

      Thank you.

      Attachments

        Issue Links

          Activity

            People

              james.wahlin@mongodb.com James Wahlin
              jochem@netwinst.nl Jochem Bonarius
              Votes:
              3 Vote for this issue
              Watchers:
              25 Start watching this issue

              Dates

                Created:
                Updated: