Skip to content

Commit ff00e08

Browse files
authored
Allow to configure min/max bucket size for the store-gateway chunks pool (#4119)
* Allow to configure min/max bucket size for the store-gateway chunks pool Signed-off-by: Marco Pracucci <marco@pracucci.com> * Fixed unit test Signed-off-by: Marco Pracucci <marco@pracucci.com>
1 parent 7f0c4ab commit ff00e08

File tree

8 files changed

+36
-21
lines changed

8 files changed

+36
-21
lines changed

docs/blocks-storage/querier.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -435,11 +435,6 @@ blocks_storage:
435435
# CLI flag: -blocks-storage.bucket-store.sync-interval
436436
[sync_interval: <duration> | default = 15m]
437437
438-
# Max size - in bytes - of a chunks pool, used to reduce memory allocations.
439-
# The pool is shared across all tenants. 0 to disable the limit.
440-
# CLI flag: -blocks-storage.bucket-store.max-chunk-pool-bytes
441-
[max_chunk_pool_bytes: <int> | default = 2147483648]
442-
443438
# Max number of concurrent queries to execute against the long-term storage.
444439
# The limit is shared across all tenants.
445440
# CLI flag: -blocks-storage.bucket-store.max-concurrent
@@ -717,6 +712,11 @@ blocks_storage:
717712
# CLI flag: -blocks-storage.bucket-store.bucket-index.max-stale-period
718713
[max_stale_period: <duration> | default = 1h]
719714
715+
# Max size - in bytes - of a chunks pool, used to reduce memory allocations.
716+
# The pool is shared across all tenants. 0 to disable the limit.
717+
# CLI flag: -blocks-storage.bucket-store.max-chunk-pool-bytes
718+
[max_chunk_pool_bytes: <int> | default = 2147483648]
719+
720720
# If enabled, store-gateway will lazy load an index-header only once
721721
# required by a query.
722722
# CLI flag: -blocks-storage.bucket-store.index-header-lazy-loading-enabled

docs/blocks-storage/store-gateway.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -481,11 +481,6 @@ blocks_storage:
481481
# CLI flag: -blocks-storage.bucket-store.sync-interval
482482
[sync_interval: <duration> | default = 15m]
483483
484-
# Max size - in bytes - of a chunks pool, used to reduce memory allocations.
485-
# The pool is shared across all tenants. 0 to disable the limit.
486-
# CLI flag: -blocks-storage.bucket-store.max-chunk-pool-bytes
487-
[max_chunk_pool_bytes: <int> | default = 2147483648]
488-
489484
# Max number of concurrent queries to execute against the long-term storage.
490485
# The limit is shared across all tenants.
491486
# CLI flag: -blocks-storage.bucket-store.max-concurrent
@@ -763,6 +758,11 @@ blocks_storage:
763758
# CLI flag: -blocks-storage.bucket-store.bucket-index.max-stale-period
764759
[max_stale_period: <duration> | default = 1h]
765760
761+
# Max size - in bytes - of a chunks pool, used to reduce memory allocations.
762+
# The pool is shared across all tenants. 0 to disable the limit.
763+
# CLI flag: -blocks-storage.bucket-store.max-chunk-pool-bytes
764+
[max_chunk_pool_bytes: <int> | default = 2147483648]
765+
766766
# If enabled, store-gateway will lazy load an index-header only once
767767
# required by a query.
768768
# CLI flag: -blocks-storage.bucket-store.index-header-lazy-loading-enabled

docs/configuration/config-file-reference.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4565,11 +4565,6 @@ bucket_store:
45654565
# CLI flag: -blocks-storage.bucket-store.sync-interval
45664566
[sync_interval: <duration> | default = 15m]
45674567
4568-
# Max size - in bytes - of a chunks pool, used to reduce memory allocations.
4569-
# The pool is shared across all tenants. 0 to disable the limit.
4570-
# CLI flag: -blocks-storage.bucket-store.max-chunk-pool-bytes
4571-
[max_chunk_pool_bytes: <int> | default = 2147483648]
4572-
45734568
# Max number of concurrent queries to execute against the long-term storage.
45744569
# The limit is shared across all tenants.
45754570
# CLI flag: -blocks-storage.bucket-store.max-concurrent
@@ -4846,6 +4841,11 @@ bucket_store:
48464841
# CLI flag: -blocks-storage.bucket-store.bucket-index.max-stale-period
48474842
[max_stale_period: <duration> | default = 1h]
48484843
4844+
# Max size - in bytes - of a chunks pool, used to reduce memory allocations.
4845+
# The pool is shared across all tenants. 0 to disable the limit.
4846+
# CLI flag: -blocks-storage.bucket-store.max-chunk-pool-bytes
4847+
[max_chunk_pool_bytes: <int> | default = 2147483648]
4848+
48494849
# If enabled, store-gateway will lazy load an index-header only once required
48504850
# by a query.
48514851
# CLI flag: -blocks-storage.bucket-store.index-header-lazy-loading-enabled

pkg/cortex/cortex_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ func TestCortex(t *testing.T) {
6363
},
6464
},
6565
BucketStore: tsdb.BucketStoreConfig{
66+
ChunkPoolMinBucketSizeBytes: tsdb.ChunkPoolDefaultMinBucketSize,
67+
ChunkPoolMaxBucketSizeBytes: tsdb.ChunkPoolDefaultMaxBucketSize,
6668
IndexCache: tsdb.IndexCacheConfig{
6769
Backend: tsdb.IndexCacheBackendInMemory,
6870
},

pkg/storage/tsdb/config.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ const (
3333

3434
// How often to check for tenant deletion mark.
3535
DeletionMarkCheckInterval = 1 * time.Hour
36+
37+
// Default minimum bucket size (bytes) of the chunk pool.
38+
ChunkPoolDefaultMinBucketSize = store.EstimatedMaxChunkSize
39+
40+
// Default maximum bucket size (bytes) of the chunk pool.
41+
ChunkPoolDefaultMaxBucketSize = 50e6
3642
)
3743

3844
// Validation errors
@@ -215,7 +221,6 @@ func (cfg *TSDBConfig) IsBlocksShippingEnabled() bool {
215221
type BucketStoreConfig struct {
216222
SyncDir string `yaml:"sync_dir"`
217223
SyncInterval time.Duration `yaml:"sync_interval"`
218-
MaxChunkPoolBytes uint64 `yaml:"max_chunk_pool_bytes"`
219224
MaxConcurrent int `yaml:"max_concurrent"`
220225
TenantSyncConcurrency int `yaml:"tenant_sync_concurrency"`
221226
BlockSyncConcurrency int `yaml:"block_sync_concurrency"`
@@ -227,6 +232,11 @@ type BucketStoreConfig struct {
227232
IgnoreDeletionMarksDelay time.Duration `yaml:"ignore_deletion_mark_delay"`
228233
BucketIndex BucketIndexConfig `yaml:"bucket_index"`
229234

235+
// Chunk pool.
236+
MaxChunkPoolBytes uint64 `yaml:"max_chunk_pool_bytes"`
237+
ChunkPoolMinBucketSizeBytes int `yaml:"chunk_pool_min_bucket_size_bytes" doc:"hidden"`
238+
ChunkPoolMaxBucketSizeBytes int `yaml:"chunk_pool_max_bucket_size_bytes" doc:"hidden"`
239+
230240
// Controls whether index-header lazy loading is enabled.
231241
IndexHeaderLazyLoadingEnabled bool `yaml:"index_header_lazy_loading_enabled"`
232242
IndexHeaderLazyLoadingIdleTimeout time.Duration `yaml:"index_header_lazy_loading_idle_timeout"`
@@ -253,6 +263,8 @@ func (cfg *BucketStoreConfig) RegisterFlags(f *flag.FlagSet) {
253263
f.StringVar(&cfg.SyncDir, "blocks-storage.bucket-store.sync-dir", "tsdb-sync", "Directory to store synchronized TSDB index headers.")
254264
f.DurationVar(&cfg.SyncInterval, "blocks-storage.bucket-store.sync-interval", 15*time.Minute, "How frequently to scan the bucket, or to refresh the bucket index (if enabled), in order to look for changes (new blocks shipped by ingesters and blocks deleted by retention or compaction).")
255265
f.Uint64Var(&cfg.MaxChunkPoolBytes, "blocks-storage.bucket-store.max-chunk-pool-bytes", uint64(2*units.Gibibyte), "Max size - in bytes - of a chunks pool, used to reduce memory allocations. The pool is shared across all tenants. 0 to disable the limit.")
266+
f.IntVar(&cfg.ChunkPoolMinBucketSizeBytes, "blocks-storage.bucket-store.chunk-pool-min-bucket-size-bytes", ChunkPoolDefaultMinBucketSize, "Size - in bytes - of the smallest chunks pool bucket.")
267+
f.IntVar(&cfg.ChunkPoolMaxBucketSizeBytes, "blocks-storage.bucket-store.chunk-pool-max-bucket-size-bytes", ChunkPoolDefaultMaxBucketSize, "Size - in bytes - of the largest chunks pool bucket.")
256268
f.IntVar(&cfg.MaxConcurrent, "blocks-storage.bucket-store.max-concurrent", 100, "Max number of concurrent queries to execute against the long-term storage. The limit is shared across all tenants.")
257269
f.IntVar(&cfg.TenantSyncConcurrency, "blocks-storage.bucket-store.tenant-sync-concurrency", 10, "Maximum number of concurrent tenants synching blocks.")
258270
f.IntVar(&cfg.BlockSyncConcurrency, "blocks-storage.bucket-store.block-sync-concurrency", 20, "Maximum number of concurrent blocks synching per tenant.")

pkg/storegateway/bucket_stores.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func NewBucketStores(cfg tsdb.BlocksStorageConfig, shardingStrategy ShardingStra
126126
}
127127

128128
// Init the chunks bytes pool.
129-
if u.chunksPool, err = newChunkBytesPool(cfg.BucketStore.MaxChunkPoolBytes, reg); err != nil {
129+
if u.chunksPool, err = newChunkBytesPool(cfg.BucketStore.ChunkPoolMinBucketSizeBytes, cfg.BucketStore.ChunkPoolMaxBucketSizeBytes, cfg.BucketStore.MaxChunkPoolBytes, reg); err != nil {
130130
return nil, errors.Wrap(err, "create chunks bytes pool")
131131
}
132132

pkg/storegateway/chunk_bytes_pool.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"github.com/prometheus/client_golang/prometheus"
55
"github.com/prometheus/client_golang/prometheus/promauto"
66
"github.com/thanos-io/thanos/pkg/pool"
7-
"github.com/thanos-io/thanos/pkg/store"
87
)
98

109
type chunkBytesPool struct {
@@ -15,8 +14,8 @@ type chunkBytesPool struct {
1514
returnedBytes prometheus.Counter
1615
}
1716

18-
func newChunkBytesPool(maxChunkPoolBytes uint64, reg prometheus.Registerer) (*chunkBytesPool, error) {
19-
upstream, err := pool.NewBucketedBytes(store.EstimatedMaxChunkSize, 50e6, 2, maxChunkPoolBytes)
17+
func newChunkBytesPool(minBucketSize, maxBucketSize int, maxChunkPoolBytes uint64, reg prometheus.Registerer) (*chunkBytesPool, error) {
18+
upstream, err := pool.NewBucketedBytes(minBucketSize, maxBucketSize, 2, maxChunkPoolBytes)
2019
if err != nil {
2120
return nil, err
2221
}

pkg/storegateway/chunk_bytes_pool_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ import (
1010
"github.com/stretchr/testify/assert"
1111
"github.com/stretchr/testify/require"
1212
"github.com/thanos-io/thanos/pkg/store"
13+
14+
cortex_tsdb "github.com/cortexproject/cortex/pkg/storage/tsdb"
1315
)
1416

1517
func TestChunkBytesPool_Get(t *testing.T) {
1618
reg := prometheus.NewPedanticRegistry()
17-
p, err := newChunkBytesPool(0, reg)
19+
p, err := newChunkBytesPool(cortex_tsdb.ChunkPoolDefaultMinBucketSize, cortex_tsdb.ChunkPoolDefaultMaxBucketSize, 0, reg)
1820
require.NoError(t, err)
1921

2022
_, err = p.Get(store.EstimatedMaxChunkSize - 1)

0 commit comments

Comments
 (0)