Skip to content

Commit

Permalink
Change pooling options for index array pool to prevent (almost) unbou…
Browse files Browse the repository at this point in the history
…nded growth over time (#1254)
  • Loading branch information
richardartoul authored Dec 19, 2018
1 parent a948b5a commit cdfe6a2
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/m3ninx/index/segment/mem/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit cdfe6a2

Please sign in to comment.