Documentation ¶
Overview ¶
memguardian is a package that provides a simple RAM memory control mechanism once activated it sets an internal atomic boolean when the RAM usage exceed in absolute terms the warning ratio, for passive indirect check or invoke an optional callback for reactive backpressure
Index ¶
Constants ¶
const ( MemGuardianEnabled = "MEMGUARDIAN" MemGuardianMaxUsedRamRatioENV = "MEMGUARDIAN_MAX_RAM_RATIO" MemGuardianMaxUsedMemoryENV = "MEMGUARDIAN_MAX_RAM" MemGuardianIntervalENV = "MEMGUARDIAN_INTERVAL" )
Variables ¶
var ( DefaultInterval time.Duration DefaultMaxUsedRamRatio float64 DefaultMemGuardian *MemGuardian )
Functions ¶
Types ¶
type MemGuardian ¶
func New ¶
func New(options ...MemGuardianOption) (*MemGuardian, error)
New mem guadian instance with user defined options
type MemGuardianOption ¶
type MemGuardianOption func(*MemGuardian) error
func WitInterval ¶
func WitInterval(d time.Duration) MemGuardianOption
WithInterval defines the ticker interval of the memory monitor
func WithCallback ¶
func WithCallback(f func()) MemGuardianOption
WithCallback defines an optional callback if the warning ration is exceeded
func WithMaxRamAmountWarning ¶
func WithMaxRamAmountWarning(maxRam string) MemGuardianOption
WithMaxRamAmountWarning defines the max amount of used RAM in bytes threshold of the warning state (and optional callback invocation)
func WithMaxRamRatioWarning ¶
func WithMaxRamRatioWarning(ratio float64) MemGuardianOption
WithMaxRamRatioWarning defines the ratio (1-100) threshold of the warning state (and optional callback invocation)