-
Notifications
You must be signed in to change notification settings - Fork 15
REP-6766 Use a batch cursor to parse the change stream #153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
REP-6766 Use a batch cursor to parse the change stream #153
Conversation
This alters document comparison to use a batch cursor instead of the Go driver’s cursor. The advantage here is that, instead of creating giant slices of documents (which are copied from the driver), we’ll read the raw documents directly from the server response buffer. This minimizes GC pressure. Pprof analysis shows that before this change, slices.Clone() allocated more heap than any other functions. With this change, those allocations are gone. PR #153 will make the change stream use the same batch cursor.
tdq45gj
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left two small suggestions. LGTM.
| err = csr.readAndHandleOneChangeEventBatch(ctx, ri, cs, sess) | ||
| err = csr.readAndHandleOneChangeEventBatch(ctx, ri, csCursor) | ||
|
|
||
| if err := csCursor.GetNext(ctx); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer a different variable name for the GetNext error, especially since we haven't finished with the original err.
| SetMaxAwaitTime(maxChangeStreamAwaitTime) | ||
| ) (*cursor.BatchCursor, bson.Timestamp, error) { | ||
|
|
||
| changeStreamStage := bson.D{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could use the BSON builder.
This applies the new batch cursor from PR #148 to the change stream.