a library to curb OOMs by running Go GC according to a user-defined policy.
Go to file
Raúl Kripalani 4558d98653 major rewrite of go-watchdog.
This commit introduces a major rewrite of go-watchdog.

* HeapDriven and SystemDriven are now distinct run modes.
* WIP ProcessDriven that uses cgroups.
* Policies are now stateless, pure and greatly simplified.
* Policies now return the next utilization at which GC
  should run. The watchdog enforces that value differently
  depending on the run mode.
* The heap-driven run mode adjusts GOGC dynamically. This
  places the responsibility on the Go runtime to honour the
  trigger point, and results in more robust logic that is not
  vulnerable to very quick bursts within sampling periods.
* The heap-driven run mode is no longer polling (interval-driven).
  Instead, it relies entirely on GC signals.
* The Silence and Emergency features of the watermark policy
  have been removed. If utilization is above the last watermark,
  the policy will request immediate GC.
* Races removed.
2020-12-08 14:19:04 +00:00
LICENSE-APACHE initial commit. 2020-12-02 00:03:20 +00:00
LICENSE-MIT initial commit. 2020-12-02 00:03:20 +00:00
README.md major rewrite of go-watchdog. 2020-12-08 14:19:04 +00:00
adaptive.go major rewrite of go-watchdog. 2020-12-08 14:19:04 +00:00
adaptive_test.go major rewrite of go-watchdog. 2020-12-08 14:19:04 +00:00
go.mod major rewrite of go-watchdog. 2020-12-08 14:19:04 +00:00
go.sum major rewrite of go-watchdog. 2020-12-08 14:19:04 +00:00
log.go major rewrite of go-watchdog. 2020-12-08 14:19:04 +00:00
sys_linux.go major rewrite of go-watchdog. 2020-12-08 14:19:04 +00:00
sys_other.go major rewrite of go-watchdog. 2020-12-08 14:19:04 +00:00
watchdog.go major rewrite of go-watchdog. 2020-12-08 14:19:04 +00:00
watchdog_test.go major rewrite of go-watchdog. 2020-12-08 14:19:04 +00:00
watermarks.go major rewrite of go-watchdog. 2020-12-08 14:19:04 +00:00
watermarks_test.go major rewrite of go-watchdog. 2020-12-08 14:19:04 +00:00

README.md

Go memory watchdog

🐺 A library to curb OOMs by running Go GC according to a user-defined policy.

GoDoc

go-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 are two kinds of watchdog so far:

  • heap-driven: applies a limit to the heap, and obtains current usage through runtime.ReadMemStats().
  • system-driven: applies a limit to the total system memory used, and obtains current usage through elastic/go-sigar.

A third process-driven watchdog that uses cgroups is underway.

This library ships with two policies out of the box:

  • watermarks policy: runs GC at configured watermarks of system or heap memory utilisation.
  • adaptive policy: runs GC when the current usage surpasses a dynamically-set threshold.

You can easily build a custom policy tailored to the allocation patterns of your program.

Why is this even needed?

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:

  1. it is incapable of dealing with bursty/spiky allocations efficiently; depending on the workload, the program may OOM as a consequence of not scheduling GC in a timely manner.
  2. part of the above is due to the fact that go doesn't concern itself with any limits. To date, it is not possible to set a maximum heap size.
  3. its default policy of scheduling GC when the heap doubles, coupled with its ignorance of system or process limits, can easily cause it to OOM.

For more information, check out these GitHub issues:

License

Dual-licensed: MIT, Apache Software License v2, by way of the Permissive License Stack.