make emergency trimming optional, disabled by default

This commit is contained in:
vyzo 2022-01-15 00:15:13 +02:00
parent 1a3d6a6850
commit ee3785b5c0
2 changed files with 15 additions and 2 deletions

View File

@ -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

View File

@ -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
}
}