Skip to content

Commit 04cc770

Browse files
authored
Adding a jitter on the head compaction and changing the max head comp… (#5919)
* Adding a jitter on the head compaction and changing the max head compaction interval to 30 min Signed-off-by: alanprot <[email protected]> * Doc Signed-off-by: alanprot <[email protected]> * changelog Signed-off-by: alanprot <[email protected]> * fix test Signed-off-by: alanprot <[email protected]> * whitenoise Signed-off-by: alanprot <[email protected]> --------- Signed-off-by: alanprot <[email protected]>
1 parent 7ff681a commit 04cc770

File tree

7 files changed

+22
-10
lines changed

7 files changed

+22
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## master / unreleased
44
* [ENHANCEMENT] Query Frontend/Querier: Added store gateway postings touched count and touched size in Querier stats and log in Query Frontend. #5892
55
* [ENHANCEMENT] Query Frontend/Querier: Returns `warnings` on prometheus query responses. #5916
6+
* [ENHANCEMENT] Ingester: Allowing to configure `-blocks-storage.tsdb.head-compaction-interval` flag up to 30 min and add a jitter on the first head compaction. #5919
67
* [CHANGE] Upgrade Dockerfile Node version from 14x to 18x. #5906
78

89
## 1.17.0 2024-04-30

docs/blocks-storage/querier.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,8 +1372,9 @@ blocks_storage:
13721372
[ship_concurrency: <int> | default = 10]
13731373

13741374
# How frequently does Cortex try to compact TSDB head. Block is only created
1375-
# if data covers smallest block range. Must be greater than 0 and max 5
1376-
# minutes.
1375+
# if data covers smallest block range. Must be greater than 0 and max 30
1376+
# minutes. Note that up to 50% jitter is added to the value for the first
1377+
# compaction to avoid ingesters compacting concurrently.
13771378
# CLI flag: -blocks-storage.tsdb.head-compaction-interval
13781379
[head_compaction_interval: <duration> | default = 1m]
13791380

docs/blocks-storage/store-gateway.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,8 +1491,9 @@ blocks_storage:
14911491
[ship_concurrency: <int> | default = 10]
14921492

14931493
# How frequently does Cortex try to compact TSDB head. Block is only created
1494-
# if data covers smallest block range. Must be greater than 0 and max 5
1495-
# minutes.
1494+
# if data covers smallest block range. Must be greater than 0 and max 30
1495+
# minutes. Note that up to 50% jitter is added to the value for the first
1496+
# compaction to avoid ingesters compacting concurrently.
14961497
# CLI flag: -blocks-storage.tsdb.head-compaction-interval
14971498
[head_compaction_interval: <duration> | default = 1m]
14981499

docs/configuration/config-file-reference.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,8 +1924,9 @@ tsdb:
19241924
[ship_concurrency: <int> | default = 10]
19251925

19261926
# How frequently does Cortex try to compact TSDB head. Block is only created
1927-
# if data covers smallest block range. Must be greater than 0 and max 5
1928-
# minutes.
1927+
# if data covers smallest block range. Must be greater than 0 and max 30
1928+
# minutes. Note that up to 50% jitter is added to the value for the first
1929+
# compaction to avoid ingesters compacting concurrently.
19291930
# CLI flag: -blocks-storage.tsdb.head-compaction-interval
19301931
[head_compaction_interval: <duration> | default = 1m]
19311932

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 for the first compaction 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

pkg/storage/tsdb/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func TestConfig_Validate(t *testing.T) {
6363
},
6464
"should fail on too high compaction interval": {
6565
setup: func(cfg *BlocksStorageConfig) {
66-
cfg.TSDB.HeadCompactionInterval = 10 * time.Minute
66+
cfg.TSDB.HeadCompactionInterval = 40 * time.Minute
6767
},
6868
expectedErr: errInvalidCompactionInterval,
6969
},

0 commit comments

Comments
 (0)