
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
🐺 A library to curb OOMs by running Go GC according to a user-defined policy.
Package watchdog runs a singleton memory watchdog in the process, which watches memory utilization and forces Go GC in accordance with a user-defined policy.
There three kinds of watchdogs:
watchdog.HeapDriven()): applies a heap limit, adjusting GOGC
dynamically in accordance with the policy.watchdog.SystemDriven()): applies a limit to the total
system memory used, obtaining the current usage through elastic/go-sigar.watchdog.CgroupDriven()): discovers the memory limit from
the cgroup of the process (derived from /proc/self/cgroup), or from the
root cgroup path if the PID == 1 (which indicates that the process is
running in a container). It uses the cgroup stats to obtain the
current usage.The watchdog's behaviour is controlled by the policy, a pluggable function that determines when to trigger GC based on the current utilization. This library ships with two policies:
watchdog.NewWatermarkPolicy()): runs GC at configured
watermarks of memory utilisation.watchdog.NewAdaptivePolicy()): runs GC when the current
usage surpasses a dynamically-set threshold.You can easily write a custom policy tailored to the allocation patterns of your program.
The recommended way to set up the watchdog is as follows, in descending order of precedence. This logic assumes that the library supports setting a heap limit through an environment variable (e.g. MYAPP_HEAP_MAX) or config key.
Given the low-level nature of this component, some tests need to run in isolation, so that they don't carry over Go runtime metrics. For completeness, this module uses a Docker image for testing, so we can simulate cgroup memory limits.
The test execution and docker builds have been conveniently packaged in a Makefile. Run with:
$ make
The garbage collector that ships with the go runtime is pretty good in some regards (low-latency, negligible no stop-the-world), but it's insatisfactory in a number of situations that yield ill-fated outcomes:
For more information, check out these GitHub issues:
Dual-licensed: MIT, Apache Software License v2, by way of the Permissive License Stack.
FAQs
Unknown package
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.