Help us shape the future of Go! Take the 2026 Go Developer Survey

memtune

package
v0.0.160 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package memtune applies Go runtime memory settings from a file that the host can rewrite while the process runs, so a container's GC soft limit can follow the host's memory budget without a restart.

The file is JSON:

{"memory_limit_bytes": 4294967296, "gc_percent": 50}

memory_limit_bytes is passed to debug.SetMemoryLimit as is (unlike sing-box's experimental.debug.memory_limit, which is divided by 1.5). Either field may be omitted to leave that setting at its baseline: the running config's experimental.debug value, else the process's startup value. The baseline is restored when the file is removed or a field is dropped.

Index

Constants

View Source
const (
	// MinMemoryLimit rejects budgets too small for a proxy to run under; a
	// limit below the live heap makes the GC run continuously.
	MinMemoryLimit = 64 << 20

	DefaultInterval = 10 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Settings

type Settings struct {
	MemoryLimitBytes *int64 `json:"memory_limit_bytes,omitempty"`
	GCPercent        *int   `json:"gc_percent,omitempty"`
}

Settings is the file's schema.

type Tuner

type Tuner struct {
	// contains filtered or unexported fields
}

Tuner polls one settings file and applies it to the Go runtime.

func New

func New(path string, interval time.Duration) *Tuner

New returns a Tuner for path. It records the runtime's current settings as the startup values, so call it before any config is applied. Then call Resync once the service is created, and Run to poll.

func (*Tuner) Resync

func (t *Tuner) Resync(debugOptions *option.DebugOptions)

Resync sets the baseline from the running config's debug options and applies the file on top. Call it whenever anything may have built a box (service creation, and a reload's config check, whether it passed or not), since building a box applies that config's debug options to the runtime.

func (*Tuner) Run

func (t *Tuner) Run(ctx context.Context)

Run polls the file until ctx is done.

Jump to

Keyboard shortcuts

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