resources

package
v0.0.0-...-8acab51 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package resources provides resource limit management for the application.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetRlimits

func GetRlimits() (map[string]Rlimit, error)

GetRlimits returns current rlimit values.

Types

type Config

type Config struct {
	// MaxMemoryMB is the maximum memory in megabytes (0 = no limit).
	MaxMemoryMB int64 `yaml:"max_memory_mb" yaml:"max_memory_mb"`

	// MaxCPUPercent is the maximum CPU percentage (0 = no limit).
	MaxCPUPercent int `yaml:"max_cpu_percent" yaml:"max_cpu_percent"`

	// MaxOpenFiles is the maximum number of open files.
	MaxOpenFiles uint64 `yaml:"max_open_files" yaml:"max_open_files"`

	// MaxGoroutines is the maximum number of goroutines (0 = no limit).
	MaxGoroutines int `yaml:"max_goroutines" yaml:"max_goroutines"`

	// GCPercent is the garbage collection target percentage.
	GCPercent int `yaml:"gc_percent" yaml:"gc_percent"`
}

Config holds resource limit configuration.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default resource configuration.

type Limiter

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

Limiter manages resource limits for the application.

func NewLimiter

func NewLimiter(config Config) *Limiter

NewLimiter creates a new resource limiter.

func (*Limiter) Apply

func (l *Limiter) Apply() error

Apply applies the resource limits.

func (*Limiter) CheckGoroutineLimit

func (l *Limiter) CheckGoroutineLimit() error

CheckGoroutineLimit checks if the goroutine limit has been exceeded.

func (*Limiter) Config

func (l *Limiter) Config() Config

Config returns the current configuration.

func (*Limiter) Stats

func (l *Limiter) Stats() ResourceStats

Stats returns current resource usage statistics.

type ResourceStats

type ResourceStats struct {
	AllocMB       int64  `json:"alloc_mb"`
	TotalAllocMB  int64  `json:"total_alloc_mb"`
	SysMB         int64  `json:"sys_mb"`
	NumGoroutines int    `json:"num_goroutines"`
	NumCPU        int    `json:"num_cpu"`
	GOMAXPROCS    int    `json:"gomaxprocs"`
	NumGC         uint32 `json:"num_gc"`
	GCPauseNs     uint64 `json:"gc_pause_ns"`
}

ResourceStats holds current resource usage statistics.

type Rlimit

type Rlimit struct {
	Cur uint64 `json:"cur"`
	Max uint64 `json:"max"`
}

Rlimit represents a resource limit.

Jump to

Keyboard shortcuts

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