Skip to content
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

recsplit: reduce ram pressure #9218

Merged
merged 5 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion erigon-lib/recsplit/recsplit.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,11 @@ func NewRecSplit(args RecSplitArgs, logger log.Logger) (*RecSplit, error) {
rs.baseDataID = args.BaseDataID
rs.etlBufLimit = args.EtlBufLimit
if rs.etlBufLimit == 0 {
rs.etlBufLimit = etl.BufferOptimalSize
// reduce ram pressure, because:
// - indexing done in background or in many workers (building many indices in-parallel)
// - `recsplit` has 2 etl collectors
// - `rescplit` building is cpu-intencive and bottleneck is not in etl loading
rs.etlBufLimit = etl.BufferOptimalSize / 8
}
rs.bucketCollector = etl.NewCollector(RecSplitLogPrefix+" "+fname, rs.tmpDir, etl.NewSortableBuffer(rs.etlBufLimit), logger)
rs.bucketCollector.LogLvl(log.LvlDebug)
Expand Down
13 changes: 6 additions & 7 deletions erigon-lib/state/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,13 +406,12 @@ func iterateForVi(historyItem, iiItem *filesItem, p *background.Progress, compre

func buildVi(ctx context.Context, historyItem, iiItem *filesItem, historyIdxPath, tmpdir string, count int, p *background.Progress, compressVals bool, logger log.Logger) error {
rs, err := recsplit.NewRecSplit(recsplit.RecSplitArgs{
KeyCount: count,
Enums: false,
BucketSize: 2000,
LeafSize: 8,
TmpDir: tmpdir,
IndexFile: historyIdxPath,
EtlBufLimit: etl.BufferOptimalSize / 2,
KeyCount: count,
Enums: false,
BucketSize: 2000,
LeafSize: 8,
TmpDir: tmpdir,
IndexFile: historyIdxPath,
}, logger)
if err != nil {
return fmt.Errorf("create recsplit: %w", err)
Expand Down
46 changes: 21 additions & 25 deletions turbo/snapshotsync/freezeblocks/block_snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
"github.com/ledgerwatch/erigon-lib/compress"
"github.com/ledgerwatch/erigon-lib/diagnostics"
"github.com/ledgerwatch/erigon-lib/downloader/snaptype"
"github.com/ledgerwatch/erigon-lib/etl"
"github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/erigon-lib/recsplit"
types2 "github.com/ledgerwatch/erigon-lib/types"
Expand Down Expand Up @@ -2173,28 +2172,26 @@ func TransactionsIdx(ctx context.Context, chainConfig *chain.Config, version uin
}

txnHashIdx, err := recsplit.NewRecSplit(recsplit.RecSplitArgs{
KeyCount: d.Count(),
Enums: true,
BucketSize: 2000,
LeafSize: 8,
TmpDir: tmpDir,
IndexFile: filepath.Join(snapDir, snaptype.IdxFileName(version, blockFrom, blockTo, snaptype.Transactions.String())),
BaseDataID: firstTxID,
EtlBufLimit: etl.BufferOptimalSize / 2,
KeyCount: d.Count(),
Enums: true,
BucketSize: 2000,
LeafSize: 8,
TmpDir: tmpDir,
IndexFile: filepath.Join(snapDir, snaptype.IdxFileName(version, blockFrom, blockTo, snaptype.Transactions.String())),
BaseDataID: firstTxID,
}, logger)
if err != nil {
return err
}

txnHash2BlockNumIdx, err := recsplit.NewRecSplit(recsplit.RecSplitArgs{
KeyCount: d.Count(),
Enums: false,
BucketSize: 2000,
LeafSize: 8,
TmpDir: tmpDir,
IndexFile: filepath.Join(snapDir, snaptype.IdxFileName(version, blockFrom, blockTo, snaptype.Transactions2Block.String())),
BaseDataID: firstBlockNum,
EtlBufLimit: etl.BufferOptimalSize / 2,
KeyCount: d.Count(),
Enums: false,
BucketSize: 2000,
LeafSize: 8,
TmpDir: tmpDir,
IndexFile: filepath.Join(snapDir, snaptype.IdxFileName(version, blockFrom, blockTo, snaptype.Transactions2Block.String())),
BaseDataID: firstBlockNum,
}, logger)
if err != nil {
return err
Expand Down Expand Up @@ -2382,14 +2379,13 @@ func Idx(ctx context.Context, d *compress.Decompressor, firstDataID uint64, tmpD
var idxFilePath = segmentFileName[0:len(segmentFileName)-len(extension)] + ".idx"

rs, err := recsplit.NewRecSplit(recsplit.RecSplitArgs{
KeyCount: d.Count(),
Enums: true,
BucketSize: 2000,
LeafSize: 8,
TmpDir: tmpDir,
IndexFile: idxFilePath,
BaseDataID: firstDataID,
EtlBufLimit: etl.BufferOptimalSize / 2,
KeyCount: d.Count(),
Enums: true,
BucketSize: 2000,
LeafSize: 8,
TmpDir: tmpDir,
IndexFile: idxFilePath,
BaseDataID: firstDataID,
}, logger)
if err != nil {
return err
Expand Down
Loading