OAK-11158 - indexing-job/downloader - Move the conversion of Mongo responses to NodeDocument from the download to the transform threads (WIP) #1753
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.
Currently, the download thread is iterating over the response receive from Mongo by converting the response to NodeDocument instances. This is a fairly expensive operation, that can account for more than 50% of the time of the download threads. While the download thread is processing the answer, it is blocked from requesting more data from Mongo, which is often the bottleneck.
We can instead convert the Mongo documents to a RawBsonDocument, which is just a copy of the binary buffer representing a Mongo document. This is a very fast operation, as it requires only making a copy the binary buffer. We can then pass these RawBsonDocuments to the transform threads, which will then convert them to NodeDocument.
This moves the heavy work of parsing the answer away from the download threads, which should significantly improve the download speed as the download threads will take less time to process each Mongo response and will more quickly send the next request. To deal with the extra load of the transform threads, we can increase their number, which currently is set to 2.