Skip to content

Commit

Permalink
Problem: memiavl restore not fast enough (#1241)
Browse files Browse the repository at this point in the history
* 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

Signed-off-by: yihuang <huang@crypto.com>

* fix unit test

---------

Signed-off-by: yihuang <huang@crypto.com>
  • Loading branch information
yihuang authored Nov 15, 2023
1 parent 953c0b4 commit cdfb5de
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
### Improvements

- [#1239](https://github.com/crypto-org-chain/cronos/pull/1239) Refactor websocket/subscription system to improve performance and stability.
- [#1241](https://github.com/crypto-org-chain/cronos/pull/1241) Improve parallelization of memiavl restoration.


*October 17, 2023*
Expand Down
4 changes: 3 additions & 1 deletion memiavl/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"path/filepath"
)

const NodeChannelBuffer = 2048

type MultiTreeImporter struct {
dir string
snapshotDir string
Expand Down Expand Up @@ -100,7 +102,7 @@ type TreeImporter struct {
}

func NewTreeImporter(dir string, version int64) *TreeImporter {
nodesChan := make(chan *ExportNode)
nodesChan := make(chan *ExportNode, NodeChannelBuffer)
quitChan := make(chan error)
go func() {
defer close(quitChan)
Expand Down
2 changes: 1 addition & 1 deletion memiavl/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ func testSnapshotRoundTrip(t *testing.T, db *DB) {
require.NoError(t, importer.Add(item))
}

require.NoError(t, exporter.Close())
require.NoError(t, importer.Finalize())
require.NoError(t, importer.Close())
require.NoError(t, exporter.Close())

db2, err := Load(restoreDir, Options{})
require.NoError(t, err)
Expand Down

0 comments on commit cdfb5de

Please sign in to comment.