From cdfe6a2cee5ae7daa3810febec2063a473ba7427 Mon Sep 17 00:00:00 2001 From: Richard Artoul Date: Tue, 18 Dec 2018 17:55:54 -0800 Subject: [PATCH] Change pooling options for index array pool to prevent (almost) unbounded growth over time (#1254) --- src/m3ninx/index/segment/mem/options.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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{