Skip to content

Commit

Permalink
export: reduce node buffer to 32
Browse files Browse the repository at this point in the history
To avoid races with IAVL pruning, the SDK must begin exports of all IAVL stores at the same time. Lowering the IAVL export buffer reduces the memory overhead of doing this, while still keeping it large enough to mitigate context switching penalties.
  • Loading branch information
erikgrinaker authored Apr 21, 2020
1 parent fc28dd2 commit dd2636c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion export.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import (
"github.com/pkg/errors"
)

// exportBufferSize is the number of nodes to buffer in the exporter. It improves throughput by
// processing multiple nodes per context switch, but take care to avoid excessive memory usage,
// especially since callers may export several IAVL stores in parallel (e.g. the Cosmos SDK).
const exportBufferSize = 32

// ExportDone is returned by Exporter.Next() when all items have been exported.
var ExportDone = errors.New("export is complete") // nolint:golint

Expand Down Expand Up @@ -33,7 +38,7 @@ func newExporter(tree *ImmutableTree) *Exporter {
ctx, cancel := context.WithCancel(context.Background())
exporter := &Exporter{
tree: tree,
ch: make(chan *ExportNode, 64),
ch: make(chan *ExportNode, exportBufferSize),
cancel: cancel,
}

Expand Down

0 comments on commit dd2636c

Please sign in to comment.