-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Memberlist: Optimise receive path by not cloning current ring state. #76
Conversation
The memberlist is used as the backing store for the ring, processing updates can be costly if the ring state is very large. This is partly due to the ring state being cloned upon the arrival of every message. It is believed that this can be avoided. Additionally, the reduced memory allocations will reduce the amount of work required by the GC. The included benchmark shows a good improvement: Command: ``` dskit/bench$ go test -v -bench BenchmarkMemberlistReceiveWithRingDesc -benchmem -cpu 6 ``` ``` BenchmarkMemberlistReceiveWithRingDesc-6 1138 975938 ns/op 551572 B/op 1264 allocs/op ``` ``` BenchmarkMemberlistReceiveWithRingDesc-6 3580 319163 ns/op 239799 B/op 37 allocs/op ```
I'm getting race conditions when running memberlist tests with |
Me too, looking into it. |
This is necessary because the Mergeable implementors are allowed to reference the source state in the returned changes. For example, in `ring.Desc`, the `Tokens` slice can be shared and is not deep copied. For safety, we can just clone the whole thing, given the changes are typically small. ``` BenchmarkMemberlistReceiveWithRingDesc-6 3229 324260 ns/op 239825 B/op 37 allocs/op ```
I've added a fix to The performance appears to be unchanged. (Edit: Removed outdated benchmark numbers) |
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 have a very limited knowledge of our memberlist implementation, so don't trust my review as much as Peter's one. To my understanding LGTM.
f4c8d07
to
b827143
Compare
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.
Nice find!
LGTM, I just added some suggestions
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.
It still LGTM after your latest changes. However, keep in mind my limited knowledge of our memberlist implementation.
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.
Great job, thanks!
What this PR does:
When memberlist is used as the backing store for the ring, processing updates
can be costly if the ring state is very large. This is partly due to the ring
state being cloned upon the arrival of every message. It is believed that this
can be avoided. Additionally, the reduced memory allocations will reduce the
amount of work required by the GC.
The included benchmark shows a good improvement:
Command:
(Edit: Updated results to take into account adding tokens to benchmark)
Which issue(s) this PR fixes:
Fixes N/A
Checklist
CHANGELOG.md
updated - the order of entries should be[CHANGE]
,[FEATURE]
,[ENHANCEMENT]
,[BUGFIX]