[MongoDB] Improve initial replication performance #219
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In some cases, MongoDB initial replication replicated at a rate as low as 150 documents/second, while we're aiming for 5-10k/second. After some investigation, the main bottleneck appears to be reading the documents from the source database, rather than writing to bucket storage.
I can't figure out why, but reading the documents using a MongoDB session appears to be the main culprit. Using the session, it could take as long as 10-20s to read 10k documents in some cases. This is not consistent, which makes it difficult to test. Without the session, that drops down to 0.5-1s for the same 10k documents.
The latter is fairly consistent.This changes the query to not use a session anymore. Initially we used a session for snapshot reads, but that is not required anymore, so there is no good reason to use sessions for this.
The performance both before and after is fairly inconsistent, and I could not find clear patterns. Even with the changes here, replication is slow in some cases. However, the median performance does appear to be better with these changes.
Other smaller changes:
readBufferedDocuments()
to read documents in batches, rather than an async iterator.Flushed 0 + 0 + 0 updates
messages after each actual batch.