-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
account.Address: use RWLocker #8774
Conversation
Thanks for the PR but sync.RWMutex is going to give surprising results for
situations unless you have multiple readers and a single producer scenario
plus overwhelming evidence that reads are slower, otherwise one is tacking
on expenses that are unnecessary. Please see
https://gist.github.com/odeke-em/234bc88fbaf9e439b70a618ce6674659#file-aresults-md
I’d just stick to entirely using sync.Mutex unless the mutex is being held
for a long time. In fact there are plans to fix sizes and cost of
sync.RWMutex like
golang/go#37142
…On Wed, Mar 3, 2021 at 11:24 AM Robert Zaremba ***@***.***> wrote:
@robert-zaremba <https://github.com/robert-zaremba> requested your review
on: #8774 <#8774>
account.Address: use RWLocker.
—
You are receiving this because your review was requested.
Reply to this email directly, view it on GitHub
<#8774 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABFL3VYJIA7WRNQO6JNOQ4TTB2EHFANCNFSM4YR2RIQQ>
.
|
Codecov Report
@@ Coverage Diff @@
## master #8774 +/- ##
==========================================
+ Coverage 59.17% 59.34% +0.17%
==========================================
Files 571 563 -8
Lines 31800 31256 -544
==========================================
- Hits 18817 18550 -267
+ Misses 10780 10551 -229
+ Partials 2203 2155 -48
|
Thanks for insights @odeke-em . So on direct benchmark, |
This is why benchmarking code will answer those questions and quell assumptions that might not hold in practice. As I showed in that surprising benchmark, multiple readers and a single writer, yet memory and allocations were still high, an objective measure would be to check for performance before and after having written a carefully close to reality scenario for benchmarking. |
My assumption for a real-world use case, that after the warm up we will have mostly (95+% ?) reads. @marbar3778 , @alessio - what do you think? |
yea agree. Might as well do some quick benchmarks, doesnt hurt |
Merging master in as tests are failing. |
The race detector is failing |
Benchmark finished. See the result: https://github.orijtech.com/benchmark/result?id=af2d7eabe3064b71bc725b7c3049ec5d |
Benchmark beginning. Status page: https://github.orijtech.com/benchmark/status?commit=4cbcc86fa36d99a198421ee08ec87ae6409a9b96 |
@@ -78,11 +78,11 @@ const ( | |||
var ( | |||
// AccAddress.String() is expensive and if unoptimized dominantly showed up in profiles, |
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's unforunate we have to rely on singletons for the cache and mutexes :-/
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.
True. Changing it would involve a big refactoring -> reducing package public functions and making everything managed by objects.
I made a benchmark based on the code Emanuel shared (https://gist.github.com/odeke-em/234bc88fbaf9e439b70a618ce6674659#file-aresults-md). I adjusted it to my CPU (4 cores) and here are the result:
Also, we can expect that there will be way more reads than writes after a warmup. Decreasing writes will only bring more points to the RWMutex in the benchmark. So it make even more sense to use RWMutex. |
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.
utACK.
Thank you for doing the benchmarking. Do you want to add the code to the repo?
@robert-zaremba thanks for letting me know.
The above steps help remove noise, and give a direct comparison and summary. Also the benchmarks I provided were specific for a comparison. Did you adapt to code that uses the cosmos-sdk and this new code in specific usage? |
Here are aggregated stats, with multiple run.
|
merging, the rw mutex is appropriate for this use case. |
Benchmark beginning. Status page: https://github.orijtech.com/benchmark/status?commit=8537baddeb5eace04b5156fe69a130ff22a3cde6 |
Benchmark finished. See the result: https://github.orijtech.com/benchmark/result?id=1aa770d250184d9f890dfd4cc345f6bb |
Description
Use
sync.RWMutex
instead ofsync.Mutex
in account cache as suggested in #8767 (comment)Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.
docs/
) or specification (x/<module>/spec/
)godoc
comments.Unreleased
section inCHANGELOG.md
Files changed
in the Github PR explorerCodecov Report
in the comment section below once CI passes