Documentation
¶
Overview ¶
*
memlim provides project-global utility functions that hook into golang runtime tools in an attempt to provide memory management features for applications that can quickly consume large amounts of memory if not slowed down. Unfourtunately, golang's reporting on memory state is unreliable. memlim imlements it's own memory usage tracking to provide additional reliability for memory management related decision making. Therefore it is very important that you **Call memlim.LimitMemory(<maxSizeInBytes>) at the very beginning of your program execution** and **Consistently call WaitForFreeMemory with precise estimations and stable LoadSheddingFnc's** in order for memlim to work smoothly. Running benchmarks on your stuff ahead of using memlim is recommended. Overestimating in case of uncertainty is also recommended.
*
Index ¶
- Variables
- func FreedMemHint(freedMemBytes uint64)
- func LimitMemory(maxHeapSize uint64) context.CancelFunc
- func LimitMemoryDynamic() error
- func ReadMemAlloc() uint64
- func SetLogger(logger logr.Logger)
- func WaitForFreeMemory(ctx context.Context, RequestedMem uint64, cancelFnc LoadSheddingFnc)
- type LoadSheddingFnc
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultInterval = 4 * time.Second
View Source
var Interval = DefaultInterval
Functions ¶
func FreedMemHint ¶
func FreedMemHint(freedMemBytes uint64)
func LimitMemory ¶
func LimitMemory(maxHeapSize uint64) context.CancelFunc
LimitMemory attempts to limit memory consumption by enabling WaitForFreeMemory to wait for sufficient available memory and manages recognized overconsumption by executing LoadSheddingFnc's
func LimitMemoryDynamic ¶
func LimitMemoryDynamic() error
func ReadMemAlloc ¶
func ReadMemAlloc() uint64
func WaitForFreeMemory ¶
func WaitForFreeMemory(ctx context.Context, RequestedMem uint64, cancelFnc LoadSheddingFnc)
WaitForFreeMemory suspends the execution of the caller's thread until `RequestedMem` bytes of memory are available or the caller-provided `ctx` is canceled. The cancelFnc is expected to free up approximately RequestdedMem bytes, making the efficiency and stability of memlim highly dependent on precise estimations of how much memory the following operation will require.
Types ¶
type LoadSheddingFnc ¶
type LoadSheddingFnc func()
Click to show internal directories.
Click to hide internal directories.