Have cursor prefetch the next "getmore" call instead of waiting until the current batch of documents are completely processed.

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Won't Do
    • Priority: Minor - P4
    • None
    • Affects Version/s: 3.0.4
    • Component/s: Core
    • Environment:
      All
    • Not Needed
    • None
    • Not Needed
    • None
    • None
    • None
    • None
    • None
    • None

      Our application consistently needs to stream large datasets to clients. We utilize the "cursor.forEach" function to iterate over each result, do some processing, and ultimately send data to consumers over a web socket.

      In profiling this process it seems that we spend a significant percentage (over 50%) of the time waiting for more documents to process. After walking through the code in mongodb-code/cursor.js, we're seeing the following behavior...

      1. We make the initial connection and get the first batch of documents for the query
      2. Those documents are iterated over and returned to our application (via our provided callback) one-by-one
      3. Only after all the documents in the initial batch have been processed, the next batch of documents for the query are requested. (this happens around line #696 in the code I just pulled from git)
      4. After some time, this next batch is returned and we continue again to step #2

      Because the next batch of documents are not requested until the current batch has been consumed, there are large delays between processing each batch.

      Requested Behavior:
      It would be preferable if this process were more pipelined. In other words, it would be ideal if as soon as the first batch of results was received the next batch would be requested. This would allow application code to consume the first batch in parallel with the next batch being delivered, drastically reducing the amount of time spent idly waiting for more documents.

        1. mongoPrefetch.zip
          755 kB
        2. mongoPrefetch.zip
          19 kB

            Assignee:
            Unassigned
            Reporter:
            Eric Herbrandson
            None
            Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: