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

store-gateway: introduce more postings strategies #5047

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
21 changes: 21 additions & 0 deletions cmd/mimir/config-descriptor.json
Original file line number Diff line number Diff line change
Expand Up @@ -7211,6 +7211,27 @@
"fieldFlag": "blocks-storage.bucket-store.series-selection-strategy",
"fieldType": "string",
"fieldCategory": "experimental"
},
{
"kind": "block",
"name": "series_selection_strategies",
"required": false,
"desc": "",
"blockEntries": [
{
"kind": "field",
"name": "worst_case_series_preference",
"required": false,
"desc": "This option is only used when blocks-storage.bucket-store.series-selection-strategy=worst-case. Increasing the series preference results in fetching more series than postings. Must be a positive floating point number.",
"fieldValue": null,
"fieldDefaultValue": 1,
"fieldFlag": "blocks-storage.bucket-store.series-selection-strategies.worst-case-series-preference",
"fieldType": "float",
"fieldCategory": "experimental"
}
],
"fieldValue": null,
"fieldDefaultValue": null
}
],
"fieldValue": null,
Expand Down
2 changes: 2 additions & 0 deletions cmd/mimir/help-all.txt.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,8 @@ Usage of ./cmd/mimir/mimir:
Controls what is the ratio of postings offsets that the store will hold in memory. (default 32)
-blocks-storage.bucket-store.series-hash-cache-max-size-bytes uint
Max size - in bytes - of the in-memory series hash cache. The cache is shared across all tenants and it's used only when query sharding is enabled. (default 1073741824)
-blocks-storage.bucket-store.series-selection-strategies.worst-case-series-preference float
[experimental] This option is only used when blocks-storage.bucket-store.series-selection-strategy=worst-case. Increasing the series preference results in fetching more series than postings. Must be a positive floating point number. (default 1)
-blocks-storage.bucket-store.series-selection-strategy string
[experimental] This option controls the strategy to selection of series and deferring application of matchers. A more aggressive strategy will fetch less posting lists at the cost of more series. This is useful when querying large blocks in which many series share the same label name and value. Supported values (most aggressive to least aggressive): speculative, worst-case, worst-case-small-posting-lists, all. (default "all")
-blocks-storage.bucket-store.sync-dir string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3283,6 +3283,14 @@ bucket_store:
# CLI flag: -blocks-storage.bucket-store.series-selection-strategy
[series_selection_strategy: <string> | default = "all"]

series_selection_strategies:
# (experimental) This option is only used when
# blocks-storage.bucket-store.series-selection-strategy=worst-case.
# Increasing the series preference results in fetching more series than
# postings. Must be a positive floating point number.
# CLI flag: -blocks-storage.bucket-store.series-selection-strategies.worst-case-series-preference
[worst_case_series_preference: <float> | default = 1]

tsdb:
# Directory to store TSDBs (including WAL) in the ingesters. This directory is
# required to be persisted between restarts.
Expand Down
16 changes: 12 additions & 4 deletions pkg/storage/tsdb/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ const (
maxTSDBOpeningConcurrencyOnStartupFlag = "blocks-storage.tsdb.max-tsdb-opening-concurrency-on-startup"
defaultMaxTSDBOpeningConcurrencyOnStartup = 10

maxChunksBytesPoolFlag = "blocks-storage.bucket-store.max-chunk-pool-bytes"
minBucketSizeBytesFlag = "blocks-storage.bucket-store.chunk-pool-min-bucket-size-bytes"
maxBucketSizeBytesFlag = "blocks-storage.bucket-store.chunk-pool-max-bucket-size-bytes"
maxChunksBytesPoolFlag = "blocks-storage.bucket-store.max-chunk-pool-bytes"
minBucketSizeBytesFlag = "blocks-storage.bucket-store.chunk-pool-min-bucket-size-bytes"
maxBucketSizeBytesFlag = "blocks-storage.bucket-store.chunk-pool-max-bucket-size-bytes"
seriesSelectionStrategyFlag = "blocks-storage.bucket-store.series-selection-strategy"
)

// Validation errors
Expand Down Expand Up @@ -376,6 +377,9 @@ type BucketStoreConfig struct {
StreamingBatchSize int `yaml:"streaming_series_batch_size" category:"advanced"`
ChunkRangesPerSeries int `yaml:"fine_grained_chunks_caching_ranges_per_series" category:"experimental"`
SeriesSelectionStrategyName string `yaml:"series_selection_strategy" category:"experimental"`
SelectionStrategies struct {
WorstCaseSeriesPreference float64 `yaml:"worst_case_series_preference" category:"experimental"`
} `yaml:"series_selection_strategies"`
}

const (
Expand Down Expand Up @@ -420,7 +424,8 @@ func (cfg *BucketStoreConfig) RegisterFlags(f *flag.FlagSet, logger log.Logger)
f.Uint64Var(&cfg.PartitionerMaxGapBytes, "blocks-storage.bucket-store.partitioner-max-gap-bytes", DefaultPartitionerMaxGapSize, "Max size - in bytes - of a gap for which the partitioner aggregates together two bucket GET object requests.")
f.IntVar(&cfg.StreamingBatchSize, "blocks-storage.bucket-store.batch-series-size", 5000, "This option controls how many series to fetch per batch. The batch size must be greater than 0.")
f.IntVar(&cfg.ChunkRangesPerSeries, "blocks-storage.bucket-store.fine-grained-chunks-caching-ranges-per-series", 1, "This option controls into how many ranges the chunks of each series from each block are split. This value is effectively the number of chunks cache items per series per block when -blocks-storage.bucket-store.chunks-cache.fine-grained-chunks-caching-enabled is enabled.")
f.StringVar(&cfg.SeriesSelectionStrategyName, "blocks-storage.bucket-store.series-selection-strategy", AllPostingsStrategy, "This option controls the strategy to selection of series and deferring application of matchers. A more aggressive strategy will fetch less posting lists at the cost of more series. This is useful when querying large blocks in which many series share the same label name and value. Supported values (most aggressive to least aggressive): "+strings.Join(validSeriesSelectionStrategies, ", ")+".")
f.StringVar(&cfg.SeriesSelectionStrategyName, seriesSelectionStrategyFlag, AllPostingsStrategy, "This option controls the strategy to selection of series and deferring application of matchers. A more aggressive strategy will fetch less posting lists at the cost of more series. This is useful when querying large blocks in which many series share the same label name and value. Supported values (most aggressive to least aggressive): "+strings.Join(validSeriesSelectionStrategies, ", ")+".")
f.Float64Var(&cfg.SelectionStrategies.WorstCaseSeriesPreference, "blocks-storage.bucket-store.series-selection-strategies.worst-case-series-preference", 1.0, "This option is only used when "+seriesSelectionStrategyFlag+"="+WorstCasePostingsStrategy+". Increasing the series preference results in fetching more series than postings. Must be a positive floating point number.")
}

// Validate the config.
Expand Down Expand Up @@ -452,6 +457,9 @@ func (cfg *BucketStoreConfig) Validate(logger log.Logger) error {
if !util.StringsContain(validSeriesSelectionStrategies, cfg.SeriesSelectionStrategyName) {
return errors.New("invalid series-selection-strategy, set one of " + strings.Join(validSeriesSelectionStrategies, ", "))
}
if cfg.SelectionStrategies.WorstCaseSeriesPreference <= 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] I would enforce it only when the strategy is "worst-case".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did it in a924c6d

return errors.New("invalid worst-case series preference; must be positive")
}
return nil
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/storegateway/bucket_stores.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ func (u *BucketStores) getOrCreateStore(userID string) (*BucketStore, error) {
u.syncDirForUser(userID),
u.cfg.BucketStore.StreamingBatchSize,
u.cfg.BucketStore.ChunkRangesPerSeries,
selectPostingsStrategy(u.logger, u.cfg.BucketStore.SeriesSelectionStrategyName),
selectPostingsStrategy(u.logger, u.cfg.BucketStore.SeriesSelectionStrategyName, u.cfg.BucketStore.SelectionStrategies.WorstCaseSeriesPreference),
NewChunksLimiterFactory(func() uint64 {
return uint64(u.limits.MaxChunksPerQuery(userID))
}),
Expand All @@ -496,14 +496,14 @@ func (u *BucketStores) getOrCreateStore(userID string) (*BucketStore, error) {
return bs, nil
}

func selectPostingsStrategy(l log.Logger, name string) postingsSelectionStrategy {
func selectPostingsStrategy(l log.Logger, name string, worstCaseSeriesPreference float64) postingsSelectionStrategy {
switch name {
case tsdb.AllPostingsStrategy:
return selectAllStrategy{}
case tsdb.SpeculativePostingsStrategy:
return speculativeFetchedDataStrategy{}
case tsdb.WorstCasePostingsStrategy:
return worstCaseFetchedDataStrategy{postingListActualSizeFactor: 1.0}
return worstCaseFetchedDataStrategy{postingListActualSizeFactor: worstCaseSeriesPreference}
case tsdb.WorstCaseSmallPostingListsPostingsStrategy:
return worstCaseFetchedDataStrategy{postingListActualSizeFactor: 0.3}
default:
Expand Down