| | package model |
| |
|
| | import ( |
| | "time" |
| | ) |
| |
|
| | const ( |
| | DefaultWatchdogInterval = 500 * time.Millisecond |
| | DefaultMemoryReclaimerThreshold = 0.80 |
| | ) |
| |
|
| | |
| | type WatchDogOptions struct { |
| | processManager ProcessManager |
| |
|
| | |
| | busyTimeout time.Duration |
| | idleTimeout time.Duration |
| | watchdogInterval time.Duration |
| |
|
| | |
| | busyCheck bool |
| | idleCheck bool |
| |
|
| | |
| | lruLimit int |
| |
|
| | |
| | memoryReclaimerEnabled bool |
| | memoryReclaimerThreshold float64 |
| |
|
| | |
| | forceEvictionWhenBusy bool |
| | } |
| |
|
| | |
| | type WatchDogOption func(*WatchDogOptions) |
| |
|
| | |
| | func WithProcessManager(pm ProcessManager) WatchDogOption { |
| | return func(o *WatchDogOptions) { |
| | o.processManager = pm |
| | } |
| | } |
| |
|
| | |
| | func WithBusyTimeout(timeout time.Duration) WatchDogOption { |
| | return func(o *WatchDogOptions) { |
| | o.busyTimeout = timeout |
| | } |
| | } |
| |
|
| | |
| | func WithIdleTimeout(timeout time.Duration) WatchDogOption { |
| | return func(o *WatchDogOptions) { |
| | o.idleTimeout = timeout |
| | } |
| | } |
| |
|
| | |
| | func WithWatchdogInterval(interval time.Duration) WatchDogOption { |
| | return func(o *WatchDogOptions) { |
| | o.watchdogInterval = interval |
| | } |
| | } |
| |
|
| | |
| | func WithBusyCheck(enabled bool) WatchDogOption { |
| | return func(o *WatchDogOptions) { |
| | o.busyCheck = enabled |
| | } |
| | } |
| |
|
| | |
| | func WithIdleCheck(enabled bool) WatchDogOption { |
| | return func(o *WatchDogOptions) { |
| | o.idleCheck = enabled |
| | } |
| | } |
| |
|
| | |
| | func WithLRULimit(limit int) WatchDogOption { |
| | return func(o *WatchDogOptions) { |
| | o.lruLimit = limit |
| | } |
| | } |
| |
|
| | |
| | |
| | func WithMemoryReclaimer(enabled bool, threshold float64) WatchDogOption { |
| | return func(o *WatchDogOptions) { |
| | o.memoryReclaimerEnabled = enabled |
| | o.memoryReclaimerThreshold = threshold |
| | } |
| | } |
| |
|
| | |
| | func WithMemoryReclaimerEnabled(enabled bool) WatchDogOption { |
| | return func(o *WatchDogOptions) { |
| | o.memoryReclaimerEnabled = enabled |
| | } |
| | } |
| |
|
| | |
| | func WithMemoryReclaimerThreshold(threshold float64) WatchDogOption { |
| | return func(o *WatchDogOptions) { |
| | o.memoryReclaimerThreshold = threshold |
| | } |
| | } |
| |
|
| | |
| | |
| | func WithForceEvictionWhenBusy(force bool) WatchDogOption { |
| | return func(o *WatchDogOptions) { |
| | o.forceEvictionWhenBusy = force |
| | } |
| | } |
| |
|
| | |
| | func DefaultWatchDogOptions() *WatchDogOptions { |
| | return &WatchDogOptions{ |
| | busyTimeout: 5 * time.Minute, |
| | idleTimeout: 15 * time.Minute, |
| | watchdogInterval: DefaultWatchdogInterval, |
| | busyCheck: false, |
| | idleCheck: false, |
| | lruLimit: 0, |
| | memoryReclaimerEnabled: false, |
| | memoryReclaimerThreshold: DefaultMemoryReclaimerThreshold, |
| | forceEvictionWhenBusy: false, |
| | } |
| | } |
| |
|
| | |
| | func NewWatchDogOptions(opts ...WatchDogOption) *WatchDogOptions { |
| | o := DefaultWatchDogOptions() |
| | for _, opt := range opts { |
| | opt(o) |
| | } |
| | return o |
| | } |
| |
|