From b0af3db7b93265079b50bf2b2e4aaa2911743c9a Mon Sep 17 00:00:00 2001 From: yihuang Date: Wed, 15 Nov 2023 15:02:16 +0800 Subject: [PATCH] Problem: memiavl restore not fast enough (backport #1241) (#1245) * Problem: memiavl restore not fast enough Solution: - increase channel buffer size to improve parallisation it reduce restore time by 44% when testing with testnet, thanks @yzang2019 for sharing the finding. * Update CHANGELOG.md * fix unit test --------- Signed-off-by: yihuang --- CHANGELOG.md | 2 ++ memiavl/import.go | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index de12296b03..eb49782014 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- [#1241](https://github.com/crypto-org-chain/cronos/pull/1241) Improve parallelization of memiavl restoration. + ### State Machine Breaking - [cronos#695](https://github.com/crypto-org-chain/cronos/pull/695) Implement ADR-007, generic events format with indexed params. diff --git a/memiavl/import.go b/memiavl/import.go index 8d96f79835..696cd2d4af 100644 --- a/memiavl/import.go +++ b/memiavl/import.go @@ -17,6 +17,8 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) +const NodeChannelBuffer = 2048 + // Import restore memiavl db from state-sync snapshot stream func Import( dir string, height uint64, format uint32, protoReader protoio.Reader, @@ -116,7 +118,7 @@ type TreeImporter struct { } func NewTreeImporter(dir string, version int64) *TreeImporter { - nodesChan := make(chan *iavl.ExportNode) + nodesChan := make(chan *iavl.ExportNode, NodeChannelBuffer) quitChan := make(chan error) go func() { defer close(quitChan)