Skip to content

Commit 9eec172

Browse files
committed
pebble: bump the initial buffer pool size for ml compactions and blob readers
We should bump this number to accommodate compactions up to 3 levels and cached blob file readers.
1 parent 8498142 commit 9eec172

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

compaction.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3312,6 +3312,7 @@ func (d *DB) compactAndWrite(
33123312
tableFormat sstable.TableFormat,
33133313
valueSeparation compact.ValueSeparation,
33143314
) (result compact.Result) {
3315+
suggestedCacheReaders := blob.SuggestedCachedReaders(len(c.inputs))
33153316
// Compactions use a pool of buffers to read blocks, avoiding polluting the
33163317
// block cache with blocks that will not be read again. We initialize the
33173318
// buffer pool with a size 12. This initial size does not need to be
@@ -3320,22 +3321,22 @@ func (d *DB) compactAndWrite(
33203321
// choosing a size larger than that working set avoids any additional
33213322
// allocations to grow the size of the pool over the course of iteration.
33223323
//
3323-
// Justification for initial size 12: In a two-level compaction, at any
3324-
// given moment we'll have 2 index blocks in-use and 2 data blocks in-use.
3324+
// Justification for initial size 18: In a compaction with up to 3 levels,
3325+
// at any given moment we'll have 3 index blocks in-use and 3 data blocks in-use.
33253326
// Additionally, when decoding a compressed block, we'll temporarily
33263327
// allocate 1 additional block to hold the compressed buffer. In the worst
3327-
// case that all input sstables have two-level index blocks (+2), value
3328-
// blocks (+2), range deletion blocks (+n) and range key blocks (+n), we'll
3329-
// additionally require 2n+4 blocks where n is the number of input sstables.
3328+
// case that all input sstables have two-level index blocks (+3), value
3329+
// blocks (+3), range deletion blocks (+n) and range key blocks (+n), we'll
3330+
// additionally require 2n+6 blocks where n is the number of input sstables.
33303331
// Range deletion and range key blocks are relatively rare, and the cost of
33313332
// an additional allocation or two over the course of the compaction is
33323333
// considered to be okay. A larger initial size would cause the pool to hold
33333334
// on to more memory, even when it's not in-use because the pool will
33343335
// recycle buffers up to the current capacity of the pool. The memory use of
3335-
// a 12-buffer pool is expected to be within reason, even if all the buffers
3336+
// a 18-buffer pool is expected to be within reason, even if all the buffers
33363337
// grow to the typical size of an index block (256 KiB) which would
3337-
// translate to 3 MiB per compaction.
3338-
c.iterationState.bufferPool.Init(12)
3338+
// translate to 4.5 MiB per compaction.
3339+
c.iterationState.bufferPool.Init(18 + suggestedCacheReaders*2)
33393340
defer c.iterationState.bufferPool.Release()
33403341
blockReadEnv := block.ReadEnv{
33413342
BufferPool: &c.iterationState.bufferPool,
@@ -3346,8 +3347,7 @@ func (d *DB) compactAndWrite(
33463347
),
33473348
}
33483349
if c.version != nil {
3349-
c.iterationState.valueFetcher.Init(&c.version.BlobFiles, d.fileCache, blockReadEnv,
3350-
blob.SuggestedCachedReaders(len(c.inputs)))
3350+
c.iterationState.valueFetcher.Init(&c.version.BlobFiles, d.fileCache, blockReadEnv, suggestedCacheReaders)
33513351
}
33523352
iiopts := internalIterOpts{
33533353
compaction: true,

0 commit comments

Comments
 (0)