Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vdarulis committed Mar 7, 2021
1 parent 4f30713 commit 19595ff
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 28 deletions.
31 changes: 20 additions & 11 deletions src/cmd/services/m3dbnode/config/pooling.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@

package config

import "fmt"
import (
"fmt"

"github.com/m3db/m3/src/x/pool"
)

// PoolingType is a type of pooling, using runtime or mmap'd bytes pooling.
type PoolingType string
Expand All @@ -39,7 +43,7 @@ const (
)

type poolPolicyDefault struct {
size int
size pool.Size
refillLowWaterMark float64
refillHighWaterMark float64

Expand Down Expand Up @@ -214,55 +218,55 @@ var (
{
Capacity: intPtr(16),
PoolPolicy: PoolPolicy{
Size: intPtr(524288),
Size: poolSizePtr(524288),
RefillLowWaterMark: &defaultRefillLowWaterMark,
RefillHighWaterMark: &defaultRefillHighWaterMark,
},
},
{
Capacity: intPtr(32),
PoolPolicy: PoolPolicy{
Size: intPtr(262144),
Size: poolSizePtr(262144),
RefillLowWaterMark: &defaultRefillLowWaterMark,
RefillHighWaterMark: &defaultRefillHighWaterMark,
},
},
{
Capacity: intPtr(64),
PoolPolicy: PoolPolicy{
Size: intPtr(131072),
Size: poolSizePtr(131072),
RefillLowWaterMark: &defaultRefillLowWaterMark,
RefillHighWaterMark: &defaultRefillHighWaterMark,
},
},
{
Capacity: intPtr(128),
PoolPolicy: PoolPolicy{
Size: intPtr(65536),
Size: poolSizePtr(65536),
RefillLowWaterMark: &defaultRefillLowWaterMark,
RefillHighWaterMark: &defaultRefillHighWaterMark,
},
},
{
Capacity: intPtr(256),
PoolPolicy: PoolPolicy{
Size: intPtr(65536),
Size: poolSizePtr(65536),
RefillLowWaterMark: &defaultRefillLowWaterMark,
RefillHighWaterMark: &defaultRefillHighWaterMark,
},
},
{
Capacity: intPtr(1440),
PoolPolicy: PoolPolicy{
Size: intPtr(16384),
Size: poolSizePtr(16384),
RefillLowWaterMark: &defaultRefillLowWaterMark,
RefillHighWaterMark: &defaultRefillHighWaterMark,
},
},
{
Capacity: intPtr(4096),
PoolPolicy: PoolPolicy{
Size: intPtr(8192),
Size: poolSizePtr(8192),
RefillLowWaterMark: &defaultRefillLowWaterMark,
RefillHighWaterMark: &defaultRefillHighWaterMark,
},
Expand Down Expand Up @@ -486,7 +490,7 @@ func (p *PoolingPolicy) TypeOrDefault() PoolingType {
// PoolPolicy specifies a single pool policy.
type PoolPolicy struct {
// The size of the pool.
Size *int `yaml:"size"`
Size *pool.Size `yaml:"size"`

// The low watermark to start refilling the pool, if zero none.
RefillLowWaterMark *float64 `yaml:"lowWatermark"`
Expand Down Expand Up @@ -525,7 +529,7 @@ func (p *PoolPolicy) initDefaultsAndValidate(poolName string) error {
}

// SizeOrDefault returns the configured size if present, or a default value otherwise.
func (p *PoolPolicy) SizeOrDefault() int {
func (p *PoolPolicy) SizeOrDefault() pool.Size {
return *p.Size
}

Expand Down Expand Up @@ -668,3 +672,8 @@ type WriteBatchPoolPolicy struct {
func intPtr(x int) *int {
return &x
}

func poolSizePtr(x int) *pool.Size {
sz := pool.Size(x)
return &sz
}
14 changes: 10 additions & 4 deletions src/dbnode/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1533,7 +1533,7 @@ func withEncodingAndPoolingOptions(

logger.Info("bytes pool configured",
zap.Int("capacity", bucket.CapacityOrDefault()),
zap.Int("size", bucket.SizeOrDefault()),
zap.Int("size", int(bucket.SizeOrDefault())),
zap.Float64("refillLowWaterMark", bucket.RefillLowWaterMarkOrDefault()),
zap.Float64("refillHighWaterMark", bucket.RefillHighWaterMarkOrDefault()))
}
Expand Down Expand Up @@ -1920,7 +1920,7 @@ func poolOptions(
)

if size > 0 {
opts = opts.SetSize(size)
opts = opts.SetSize(int(size))
if refillLowWaterMark > 0 &&
refillHighWaterMark > 0 &&
refillHighWaterMark > refillLowWaterMark {
Expand All @@ -1929,6 +1929,8 @@ func poolOptions(
SetRefillHighWatermark(refillHighWaterMark)
}
}
opts = opts.SetDynamic(size.IsDynamic())

if scope != nil {
opts = opts.SetInstrumentOptions(opts.InstrumentOptions().
SetMetricsScope(scope))
Expand All @@ -1948,14 +1950,16 @@ func capacityPoolOptions(
)

if size > 0 {
opts = opts.SetSize(size)
opts = opts.SetSize(int(size))
if refillLowWaterMark > 0 &&
refillHighWaterMark > 0 &&
refillHighWaterMark > refillLowWaterMark {
opts = opts.SetRefillLowWatermark(refillLowWaterMark)
opts = opts.SetRefillHighWatermark(refillHighWaterMark)
}
}
opts = opts.SetDynamic(size.IsDynamic())

if scope != nil {
opts = opts.SetInstrumentOptions(opts.InstrumentOptions().
SetMetricsScope(scope))
Expand All @@ -1975,14 +1979,16 @@ func maxCapacityPoolOptions(
)

if size > 0 {
opts = opts.SetSize(size)
opts = opts.SetSize(int(size))
if refillLowWaterMark > 0 &&
refillHighWaterMark > 0 &&
refillHighWaterMark > refillLowWaterMark {
opts = opts.SetRefillLowWatermark(refillLowWaterMark)
opts = opts.SetRefillHighWatermark(refillHighWaterMark)
}
}
opts = opts.SetDynamic(size.IsDynamic())

if scope != nil {
opts = opts.SetInstrumentOptions(opts.InstrumentOptions().
SetMetricsScope(scope))
Expand Down
2 changes: 1 addition & 1 deletion src/msg/protocol/proto/roundtrip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func getBytesPool(bucketSizes int, bucketCaps []int) pool.BytesPool {
buckets := make([]pool.Bucket, len(bucketCaps))
for i, cap := range bucketCaps {
buckets[i] = pool.Bucket{
Count: bucketSizes,
Count: pool.Size(bucketSizes),
Capacity: cap,
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/x/pool/bucketized.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ func (p *bucketizedObjectPool) Init(alloc BucketizedAllocator) {

if size > 0 {
opts = opts.SetSize(int(size))
} else if size == _dynamicPoolSize {
opts.SetDynamic(true)
}
opts = opts.SetDynamic(size.IsDynamic())

iopts := opts.InstrumentOptions()

if iopts.MetricsScope() != nil {
Expand Down
18 changes: 8 additions & 10 deletions src/x/pool/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,15 @@ type ObjectPoolConfiguration struct {
func (c *ObjectPoolConfiguration) NewObjectPoolOptions(
instrumentOpts instrument.Options,
) ObjectPoolOptions {
var (
size = _defaultSize
dynamic bool
)

switch {
case c.Size > 0:
size := _defaultSize
if c.Size > 0 {
size = int(c.Size)
case c.Size == _dynamicPoolSize:
dynamic = true
}

return NewObjectPoolOptions().
SetInstrumentOptions(instrumentOpts).
SetSize(size).
SetDynamic(dynamic).
SetDynamic(c.Size.IsDynamic()).
SetRefillLowWatermark(c.Watermark.RefillLowWatermark).
SetRefillHighWatermark(c.Watermark.RefillHighWatermark)
}
Expand Down Expand Up @@ -138,3 +131,8 @@ func (s *Size) UnmarshalText(b []byte) error {

return nil
}

// IsDynamic returns whether the pool should be fixed size or not.
func (s Size) IsDynamic() bool {
return s == _dynamicPoolSize
}

0 comments on commit 19595ff

Please sign in to comment.