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

34% performance loss switching from Count to CountDocuments

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major - P3
    • Resolution: Unresolved
    • Affects Version/s: 4.4.5, 4.0.25
    • Fix Version/s: Backlog
    • Component/s: None
    • Labels:
      None
    • Operating System:
      ALL
    • Steps To Reproduce:
      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 }}}]))
    • Case:

      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

              Assignee:
              backlog-query-execution Backlog - Query Execution
              Reporter:
              jochem@netwinst.nl Jochem Bonarius
              Participants:
              Votes:
              2 Vote for this issue
              Watchers:
              20 Start watching this issue

                Dates

                Created:
                Updated: