procload

package
v1.135.1 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package procload reports how much of the memory and CPU this process may use it is using now, as a percentage of what the container allows it.

It exists for the managed-script run worker, which admits a new run only while the replica has headroom (#1843). It knows nothing about scripts: it reads the process's own counters and the limits the container set, and says when it cannot know one, so its caller never refuses work on a number it made up.

Memory is the Go runtime's mapped memory less what it has returned to the operating system (runtime/metrics), against the smallest of the cgroup's memory limit and GOMEMLIMIT. CPU is the process's user and system time over a short window (getrusage), against the cgroup's CPU quota or, without one, GOMAXPROCS. The runtime's own /cpu/classes metrics are not used: they are only brought up to date at garbage collection, so between collections they describe a load that has already changed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MemoryLimit added in v1.135.1

func MemoryLimit() int64

MemoryLimit is the smallest memory limit in force on this process: the container's cgroup limit or GOMEMLIMIT, in bytes. Zero means none is set. It is what a limit stated as a share of the container's memory is a share of (#1861).

Types

type Sample

type Sample struct {
	MemoryPercent float64
	MemoryKnown   bool
	CPUPercent    float64
	CPUKnown      bool
}

Sample is one reading. A percentage whose Known flag is false could not be measured on this platform or under this configuration, and is zero.

type Sampler

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

Sampler reads the process's load. Safe for concurrent use.

func New

func New() *Sampler

New resolves the limits once and returns a sampler over them. The limits are the container's and do not change under a running process; GOMEMLIMIT can, and a change to it takes effect for a sampler built afterwards.

func (*Sampler) Sample

func (s *Sampler) Sample() Sample

Sample reads the current load.

Jump to

Keyboard shortcuts

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