memlim

package
v0.0.0-...-2ae20b0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

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

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 SetLogger

func SetLogger(logger logr.Logger)

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()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL