budget

package
v0.5.0 Latest Latest
Warning

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

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

Documentation

Overview

Package budget decides whether another stack fits into the memory the machine has for siding. Everything here is a pure function; the numbers come from Docker and the compose config.

Index

Constants

View Source
const (
	// ServiceDefault is the estimate of a service without a memory limit. It is a guess, until
	// siding learns real peaks (v0.3).
	ServiceDefault int64 = 256 << 20
	// DefaultShare is the part of Docker's memory that is the budget when none is set.
	DefaultShare = 0.75
)
View Source
const PeakMargin = 1.25

PeakMargin is added to a learned peak: one-shot stats see the use now, not the maximum.

Variables

This section is empty.

Functions

func Default

func Default(dockerMemory int64) int64

Default is the budget without a label: 75 % of the memory the Docker daemon reports.

func Estimate

func Estimate(p *compose.Project) int64

Estimate is the memory a project will need without learned peaks: per service and replica its memory limit, or ServiceDefault without one.

func EstimateLearned

func EstimateLearned(p *compose.Project, repo string, peaks Peaks) int64

EstimateLearned is the memory a project of repo will need: per service and replica its learned peak plus PeakMargin, capped at its memory limit; else the limit; else ServiceDefault.

func Learn

func Learn(home string, samples Peaks) error

Learn records samples, keeping the highest value per key, and writes the cache atomically. A sample another siding process wrote meanwhile may be lost; it is a cache.

func ParseSize

func ParseSize(s string) (int64, error)

ParseSize reads a size as bytes or with the binary suffix k, m or g: 512m, 12g, 1073741824.

func PeakKey

func PeakKey(repo, service string) string

PeakKey is the key of a service of a repository.

Types

type Check

type Check struct {
	Budget   int64
	Used     int64 // memory of every other stack
	Estimate int64 // of this stack
}

Check is the outcome of fitting a stack into the budget.

func (Check) Fits

func (c Check) Fits() bool

Fits reports whether the stack fits.

type Peaks

type Peaks map[string]int64

Peaks is the highest memory use siding has seen per "<repository>/<service>". It is kept in ~/.siding/peaks.json, a losable cache.

func LoadPeaks

func LoadPeaks(home string) Peaks

LoadPeaks reads the cache; a missing or broken file is an empty cache.

Jump to

Keyboard shortcuts

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