Skip to content

Commit

Permalink
Merge pull request #11269 from filecoin-project/throttle-splitstore-p…
Browse files Browse the repository at this point in the history
…urging

fix: Add time slicing to splitstore purging to reduce lock congestion
  • Loading branch information
fridrik01 authored Sep 18, 2023
2 parents 35ceb02 + 2d7a9b0 commit 8aaa8de
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
## New features
- feat: Added new tracing API (**HIGHLY EXPERIMENTAL**) supporting two RPC methods: `trace_block` and `trace_replayBlockTransactions` ([filecoin-project/lotus#11100](https://github.com/filecoin-project/lotus/pull/11100))

## Improvements
- fix: Add time slicing to splitstore purging step during compaction to reduce lock congestion [filecoin-project/lotus#11269](https://github.com/filecoin-project/lotus/pull/11269)

# v1.23.3 / 2023-08-01

This feature release of Lotus includes numerous improvements and enhancements for node operators, ETH RPC-providers and storage providers.
Expand Down
17 changes: 15 additions & 2 deletions blockstore/splitstore/splitstore_compact.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ var (
)

const (
batchSize = 16384
cidKeySize = 128
batchSize = 16384
cidKeySize = 128
purgeWorkSliceDuration = time.Second
)

func (s *SplitStore) HeadChange(_, apply []*types.TipSet) error {
Expand Down Expand Up @@ -1372,9 +1373,21 @@ func (s *SplitStore) purge(coldr *ColdSetReader, checkpoint *Checkpoint, markSet
return err
}

now := time.Now()

err := coldr.ForEach(func(c cid.Cid) error {
batch = append(batch, c)
if len(batch) == batchSize {
// add some time slicing to the purge as this a very disk I/O heavy operation that
// requires write access to txnLk that may starve other operations that require
// access to the blockstore.
elapsed := time.Since(now)
if elapsed > purgeWorkSliceDuration {
// work 1 slice, sleep 4 slices, or 20% utilization
time.Sleep(4 * elapsed)
now = time.Now()
}

return deleteBatch()
}

Expand Down

0 comments on commit 8aaa8de

Please sign in to comment.