-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
feat(store): Parallel write in the CacheMultiStore
#20817
Changes from 1 commit
99e6319
da99cd8
b8d3211
0e5be9f
7bd8653
d1970ba
bdf02c0
f9baf60
f19c252
a8908fe
f415034
5ac069e
146866b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,9 @@ package cachemulti | |
import ( | ||
"fmt" | ||
"io" | ||
"sync" | ||
|
||
dbm "github.com/cosmos/cosmos-db" | ||
"golang.org/x/sync/errgroup" | ||
|
||
"cosmossdk.io/store/cachekv" | ||
"cosmossdk.io/store/dbadapter" | ||
|
@@ -123,15 +123,22 @@ func (cms Store) GetStoreType() types.StoreType { | |
// Write calls Write on each underlying store. | ||
func (cms Store) Write() { | ||
cms.db.Write() | ||
wg := sync.WaitGroup{} | ||
wg.Add(len(cms.stores)) | ||
eg := new(errgroup.Group) | ||
for _, store := range cms.stores { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should there be a concurrency limit? or is it good enough to delegate this work completely to the go scheduler? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should do some benchmarks with databases and come up with a optimal number of runners There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as we can see in #20817 (comment), from 8 stores, there is not much improvement, let me benchmark with limited number of runners |
||
go func(s types.CacheWrap) { | ||
defer wg.Done() | ||
s := store // https://golang.org/doc/faq#closures_and_goroutines | ||
eg.Go(func() (err error) { | ||
defer func() { | ||
if r := recover(); r != nil { | ||
err = fmt.Errorf("panic in Write: %v", r) | ||
} | ||
}() | ||
s.Write() | ||
}(store) | ||
return nil | ||
}) | ||
} | ||
if err := eg.Wait(); err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if the panic is handled somewhere else in case: this is not deterministic for multiple errors. In the godoc for Wait:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we don't need to care about the multiple errors, the Write is the memory action and it won't affect the finalized state |
||
panic(err) | ||
} | ||
wg.Wait() | ||
} | ||
|
||
// Implements CacheWrapper. | ||
|
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.
Testing against a LSM db would be more illustrative of performance improvements, let's try leveldb and pebbledb?
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 is not for i/o, mostly for tree updates in memory, in WorkingHash liefcycle