While investigating performance issues on our Atlas hosted database, we began to observe a high count of Docs Returned in the Atlas profiler. This high number of returned documents is the result of the changestream getMore
calls of the cursor, and we sometimes see the number of returned documents reaching over 5000 records. We are aware that we are not making that many changes and are wondering what could explain the high number of records being returned. Is this number a cumulative count from the time the cursor was established?
Mongo Changestream getmore profiling
54 views Asked by user1884081 At
1
From the comments:
No, the number in your screenshot is not cumulative.
Your screenshot is from the Atlas profiler. Both the Atlas profiler documentation as well your reference to the screenshot being associated with a
getMore
call point to the fact that we are looking at the results of a single operation.Somewhat relatedly, the
Response Length
field in that screenshot corresponds to thereslen
of the operation. Again this is the amount of data transferred for that single call. There is a hard cap of 16MB of data transmitted per batch, so the size of the documents being returned influence how many will get sent in a single batch.Thanks for the additional context! You are looking at something 'different' here though which is the source of confusion and incorrect conclusion.
In this interface the object being reported against is the cursor itself. A cursor is the object that is created when a query, including a change stream, is executed and will return more than one batch of data.
As you have correctly concluded, the
nDocsReturned
metric in this interface is cumulative for the cursor. The documentation confirms this:Immediately afterwards that page also informs us about
nBatchesReturned
:So each individual
getMore
call will add to these cumulative cursor totals that can be observed incurrentOp
. But the log file and profiler are only going to report the metrics associated with the individualgetMore
executions (that are slow enough to be reported in those places).It sounds like either there are more changes being made than you are expecting or change streams are being (re)opened more often than anticipated (or not using 'resume after' functionality appropriately).