Skip to content

Commit 21e82fc

Browse files
committed
Adding a jitter on the head compaction and changing the max head compaction interval to 30 min
Signed-off-by: alanprot <[email protected]>
1 parent 7ff681a commit 21e82fc

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

pkg/ingester/ingester.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ const (
7070

7171
// Jitter applied to the idle timeout to prevent compaction in all ingesters concurrently.
7272
compactionIdleTimeoutJitter = 0.25
73+
initialHeadCompactionJitter = 0.5
7374

7475
instanceIngestionRateTickInterval = time.Second
7576

@@ -2404,13 +2405,20 @@ func (i *Ingester) shipBlocks(ctx context.Context, allowed *util.AllowedTenants)
24042405
}
24052406

24062407
func (i *Ingester) compactionLoop(ctx context.Context) error {
2407-
ticker := time.NewTicker(i.cfg.BlocksStorageConfig.TSDB.HeadCompactionInterval)
2408+
// Apply a jitter on the first head compaction
2409+
firstHeadCompaction := true
2410+
ticker := time.NewTicker(util.DurationWithPositiveJitter(i.cfg.BlocksStorageConfig.TSDB.HeadCompactionInterval, initialHeadCompactionJitter))
24082411
defer ticker.Stop()
24092412

24102413
for ctx.Err() == nil {
24112414
select {
24122415
case <-ticker.C:
24132416
i.compactBlocks(ctx, false, nil)
2417+
// Reset the ticker to run the configured interval on the first head compaction
2418+
if firstHeadCompaction {
2419+
ticker.Reset(i.cfg.BlocksStorageConfig.TSDB.HeadCompactionInterval)
2420+
firstHeadCompaction = false
2421+
}
24142422

24152423
case req := <-i.TSDBState.forceCompactTrigger:
24162424
i.compactBlocks(ctx, true, req.users)

pkg/storage/tsdb/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func (cfg *TSDBConfig) RegisterFlags(f *flag.FlagSet) {
173173
f.DurationVar(&cfg.ShipInterval, "blocks-storage.tsdb.ship-interval", 1*time.Minute, "How frequently the TSDB blocks are scanned and new ones are shipped to the storage. 0 means shipping is disabled.")
174174
f.IntVar(&cfg.ShipConcurrency, "blocks-storage.tsdb.ship-concurrency", 10, "Maximum number of tenants concurrently shipping blocks to the storage.")
175175
f.IntVar(&cfg.MaxTSDBOpeningConcurrencyOnStartup, "blocks-storage.tsdb.max-tsdb-opening-concurrency-on-startup", 10, "limit the number of concurrently opening TSDB's on startup")
176-
f.DurationVar(&cfg.HeadCompactionInterval, "blocks-storage.tsdb.head-compaction-interval", 1*time.Minute, "How frequently does Cortex try to compact TSDB head. Block is only created if data covers smallest block range. Must be greater than 0 and max 5 minutes.")
176+
f.DurationVar(&cfg.HeadCompactionInterval, "blocks-storage.tsdb.head-compaction-interval", 1*time.Minute, "How frequently does Cortex try to compact TSDB head. Block is only created if data covers smallest block range. Must be greater than 0 and max 30 minutes. Note that up to 50% jitter is added to the value to avoid ingesters compacting concurrently.")
177177
f.IntVar(&cfg.HeadCompactionConcurrency, "blocks-storage.tsdb.head-compaction-concurrency", 5, "Maximum number of tenants concurrently compacting TSDB head into a new block")
178178
f.DurationVar(&cfg.HeadCompactionIdleTimeout, "blocks-storage.tsdb.head-compaction-idle-timeout", 1*time.Hour, "If TSDB head is idle for this duration, it is compacted. Note that up to 25% jitter is added to the value to avoid ingesters compacting concurrently. 0 means disabled.")
179179
f.IntVar(&cfg.HeadChunksWriteBufferSize, "blocks-storage.tsdb.head-chunks-write-buffer-size-bytes", chunks.DefaultWriteBufferSize, "The write buffer size used by the head chunks mapper. Lower values reduce memory utilisation on clusters with a large number of tenants at the cost of increased disk I/O operations.")
@@ -198,7 +198,7 @@ func (cfg *TSDBConfig) Validate() error {
198198
return errInvalidOpeningConcurrency
199199
}
200200

201-
if cfg.HeadCompactionInterval <= 0 || cfg.HeadCompactionInterval > 5*time.Minute {
201+
if cfg.HeadCompactionInterval <= 0 || cfg.HeadCompactionInterval > 30*time.Minute {
202202
return errInvalidCompactionInterval
203203
}
204204

0 commit comments

Comments
 (0)