make emergency trimming optional, disabled by default
This commit is contained in:
parent
1a3d6a6850
commit
ee3785b5c0
|
@ -129,8 +129,12 @@ func NewConnManager(low, hi int, opts ...Option) (*BasicConnMgr, error) {
|
|||
}
|
||||
cm.ctx, cm.cancel = context.WithCancel(context.Background())
|
||||
|
||||
// When we're running low on memory, immediately trigger a trim.
|
||||
cm.unregisterWatchdog = watchdog.RegisterPostGCNotifee(cm.memoryEmergency)
|
||||
if cfg.emergencyTrim {
|
||||
// When we're running low on memory, immediately trigger a trim.
|
||||
cm.unregisterWatchdog = watchdog.RegisterPostGCNotifee(cm.memoryEmergency)
|
||||
} else {
|
||||
cm.unregisterWatchdog = func() {}
|
||||
}
|
||||
|
||||
decay, _ := NewDecayer(cfg.decayer, cm)
|
||||
cm.decayer = decay
|
||||
|
|
|
@ -12,6 +12,7 @@ type config struct {
|
|||
gracePeriod time.Duration
|
||||
silencePeriod time.Duration
|
||||
decayer *DecayerCfg
|
||||
emergencyTrim bool
|
||||
}
|
||||
|
||||
// Option represents an option for the basic connection manager.
|
||||
|
@ -50,3 +51,11 @@ func WithSilencePeriod(p time.Duration) Option {
|
|||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// WithEmergencyTrim is an option to enable trimming connections on memory emergency.
|
||||
func WithEmergencyTrim(enable bool) Option {
|
||||
return func(cfg *config) error {
|
||||
cfg.emergencyTrim = enable
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue