-
Notifications
You must be signed in to change notification settings - Fork 344
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
chore(pkg/database): use atomic for waitingCount in instrumentedRWMutex #1917
base: master
Are you sure you want to change the base?
chore(pkg/database): use atomic for waitingCount in instrumentedRWMutex #1917
Conversation
18f3d47
to
98de1f1
Compare
pkg/database/instrumented_rwmutex.go
Outdated
imux.waitingCount++ | ||
imux.trwmutex.Unlock() | ||
atomic.AddInt64(&imux.waitingCount, 1) | ||
defer atomic.AddInt64(&imux.waitingCount, -1) |
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 do not think that it makes sense to use defer here, just call after rlock.
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.
fixed
@arturmelanchyk , please sign commits with GPG |
Signed-off-by: Artur Melanchyk <[email protected]>
Signed-off-by: Artur Melanchyk <[email protected]>
2d77b7b
to
56010cc
Compare
Just a kind reminder @tomekkolo @SimoneLazzaris , branch has been rebased onto latest master and all commits signed with GPG |
Looked at it once more, why using 64 bit ? If you follow the path where it is used (DatabaseHealth), it is anyway cut to 32bits at the end. And generally, no need for such big counter here. Also not sure about real gain, this endpoint is not called so much. |
see list of methods that use it: as a result, even tiny improvement in this type will lead to noticeable speed boost
|
This change minimizes lock contention when working with
instrumentedRWMutex
According to the attached benchmark
Lock
\Unlock
operations as well asRLock
\RUnlock
gain ~50% performance boost whileState
's performance remains on the same level