Rewrite delta to use only a single goroutine #373
Merged
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.
The current delta implementation uses two goroutines that read from their own channels but update shared maps all the time. Rewriting it to just use a single goroutine make almost no difference in wall clock time (seems to even be a little faster) but removes quite a lot of lock contention so that the total CPU time needed decreases quite a bit.
For the following test, I increased the limit in the benchmark (didn't want to commit this as that test needs about 12GB RAM).
Before
After
Comparison
(Don't give too much on the exact numbers, that was just a single run but it matches my general impression from multiple runs: there's no huge change but it tends to even be slightly faster.)
Also the CPU time (user+sys) went from 87.25s to 69.86s (-20 %), that's the main benefit of this PR.
refs #361 (Making delta single-threaded was originally part of that PR but now got moved here. There's a bit of history/context over there.)