diff --git a/src/m3ninx/index/segment/mem/options.go b/src/m3ninx/index/segment/mem/options.go index b67dad00ce..448230526b 100644 --- a/src/m3ninx/index/segment/mem/options.go +++ b/src/m3ninx/index/segment/mem/options.go @@ -32,6 +32,11 @@ import ( const ( defaultInitialCapacity = 1024 defaultBytesArrayPoolCapacity = 1024 + // This pool is used in a single-threaded manner. + defaultBytesArrayPoolSize = 1 + // 2^24 * 16 bytes (byte slice pointer) * 2 (Golang G.C) ~= + // 0.5 GiB max memory usage. + defaultBytesArrayPoolMaxArrayCapacity = 2 ^ 24 ) // Options is a collection of knobs for an in-memory segment. @@ -78,8 +83,12 @@ type opts struct { // NewOptions returns new options. func NewOptions() Options { arrPool := bytes.NewSliceArrayPool(bytes.SliceArrayPoolOpts{ - Capacity: defaultBytesArrayPoolCapacity, - Options: pool.NewObjectPoolOptions(), + Capacity: defaultBytesArrayPoolCapacity, + MaxCapacity: defaultBytesArrayPoolMaxArrayCapacity, + Options: pool.NewObjectPoolOptions(). + SetSize(defaultBytesArrayPoolSize). + SetRefillLowWatermark(0). + SetRefillHighWatermark(0), }) arrPool.Init() return &opts{