Documentation
¶
Index ¶
Constants ¶
const ( JOB_OBJECT_CPU_RATE_CONTROL_ENABLE = 0x1 // The job's CPU rate is a hard limit. After the job reaches its CPU cycle limit for the current scheduling interval, // no threads associated with the job will run until the next interval. // => See https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-jobobject_cpu_rate_control_information JOB_OBJECT_CPU_RATE_CONTROL_HARD_CAP = 0x4 )
const ( DefaultCgroup = "/blockless" DefaultMountpoint = "/sys/fs/cgroup" DefaultJobObjectName = "blockless" // Default percentage of the CPU allowed. By default we run unlimited. DefaultCPUPercentage = 1.0 )
Variables ¶
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 (*Limits) LimitProcess ¶
LimitProcess will set the resource limits for the process identified by the handle.
func (*Limits) ListProcesses ¶
func (*Limits) Shutdown ¶
Shutdown will shutdown the limiter. All processes currently associated with the limiter will complete their execution as-is, meaning that the limitations will not be removed. "After a process is associated with a job, the association cannot be broken" => See https://learn.microsoft.com/en-us/windows/win32/procthread/job-objects#creating-jobs.
type Option ¶
type Option func(*Config)
Option can be used to set limits.
func WithCPUPercentage ¶
WithCPUPercentage sets the percentage of CPU time allowed.
func WithCgroup ¶
WithCgroup sets the path for the cgroup used for the jobs.
func WithJobObjectName ¶
WithJobObjectName sets the name for the job object to be used for the jobs.
func WithMemoryKB ¶
WithMemoryKB sets the max amount of memory allowed in kilobytes.