-
Notifications
You must be signed in to change notification settings - Fork 69
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
memberlist: get rid of exclusive mutex on get worker channel method #171
Conversation
Signed-off-by: Miguel Ángel Ortuño <ortuman@gmail.com>
Signed-off-by: Miguel Ángel Ortuño <ortuman@gmail.com>
go func(idx int) { | ||
_ = kv.getKeyWorkerChannel(strconv.Itoa(idx % totalNumberOfKeys)) | ||
wg.Done() | ||
}(i) |
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.
Benchmark should not spawn new goroutine in each iteration.
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 can have constant number of goroutines, each doing N iterations.
Given that memberlist processes incoming messages in single goroutine, I don't think that additional overhead of RW lock is useful here. (Correct benchmark should show RWMutex being slower than classic Mutex [when used from single goroutine]) |
In such a case, and since there's no concurrent access, we could simply do without PS: and no need for benchmark either... the fastest code is the one that does not execute. |
That would be nice :) I'm not 100% sure about that however, I see two paths leading to |
One running in On the other hand, I agree that if most of the time the worker channels map is going to accessed sequentially there's no need for switching to a non-exclusive mutex. 👍 Closing, as this solution does not add real value. |
What this PR does:
This PR adapts memberlist KV to make use of a non-exclusive mutex to protect worker channels access.
Below are the numbers of running the included test benchmark comparing against the new code.
Old version:
New version:
Comparison:
$ benchstat old.txt new.txt name old time/op new time/op delta KV_GetWorkerChannel-1024 363ns ±11% 202ns ±12% -44.30% (p=0.000 n=9+10) name old alloc/op new alloc/op delta KV_GetWorkerChannel-1024 50.5B ±15% 48.0B ± 0% -4.95% (p=0.003 n=10+10) name old allocs/op new allocs/op delta KV_GetWorkerChannel-1024 2.00 ± 0% 2.00 ± 0% ~ (all equal)
Which issue(s) this PR fixes:
Fixes N/A
Checklist
CHANGELOG.md
updated - the order of entries should be[CHANGE]
,[FEATURE]
,[ENHANCEMENT]
,[BUGFIX]