limits

package
v0.4.7 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultCgroup        = "/blockless"
	DefaultMountpoint    = "/sys/fs/cgroup"
	DefaultJobObjectName = "blockless"

	// Default percentage of the CPU allowed. By default we run unlimited.
	DefaultCPUPercentage = 1.0
)

Variables

View Source
var DefaultConfig = Config{
	Cgroup:        DefaultCgroup,
	JobName:       DefaultJobObjectName,
	MemoryKB:      -1,
	CPUPercentage: DefaultCPUPercentage,
}

DefaultConfig describes the default process resource limits.

Functions

This section is empty.

Types

type Config

type Config struct {
	Cgroup  string // On Linux, Cgroup to use for limits.
	JobName string // On Windows, job object name to use for limits.

	MemoryKB      int64   // Maximum amount of memory allowed in kilobytes.
	CPUPercentage float64 // Percentage of the CPU time allowed.
}

Config represents the resource limits to set.

type Limits

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

func New

func New(opts ...Option) (*Limits, error)

New creates a new process resource limit with the given configuration.

func (*Limits) LimitProcess

func (l *Limits) LimitProcess(proc execute.ProcessID) error

LimitProcess will set the resource limits for the process with the given PID.

func (*Limits) ListProcesses

func (l *Limits) ListProcesses() ([]int, error)

ListProcesses will return the pids of the processes that were added to the resource limit group.

func (*Limits) Shutdown

func (l *Limits) Shutdown() error

Shutdown will remove any set resource limits.

type Option

type Option func(*Config)

Option can be used to set limits.

func WithCPUPercentage

func WithCPUPercentage(p float64) Option

WithCPUPercentage sets the percentage of CPU time allowed.

func WithCgroup

func WithCgroup(path string) Option

WithCgroup sets the path for the cgroup used for the jobs.

func WithJobObjectName

func WithJobObjectName(name string) Option

WithJobObjectName sets the name for the job object to be used for the jobs.

func WithMemoryKB

func WithMemoryKB(limit int64) Option

WithMemoryKB sets the max amount of memory allowed in kilobytes.

Jump to

Keyboard shortcuts

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