pace

package
v0.8.0-alpha Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package pace fits the server to the machine it runs on, so a small one (a Raspberry Pi 3, an old Celeron mini PC) stays responsive. It does three things:

  • says how small the machine is (Machine), from its processors and memory;
  • tells Go's memory manager how much the machine can spare (Tune), so the server's own memory stays well inside it;
  • holds background work back while someone is watching (Yield), and says how much of it may run at once (Slots).

Work that nobody is waiting for marks its context with Background. Everything else is left alone: a person pressing play never waits here.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Background

func Background(ctx context.Context) context.Context

Background marks a context as work nobody is waiting for: a scan, a refresh, a tidy-up. Such work yields to people (Yield) and may be started at a lower priority.

func Busy

func Busy() bool

Busy says whether the machine is serving someone work that background jobs should give way to.

func Force

func Force(c Class) (restore func())

Force sets the class, for tests, and returns what puts it back.

func IsBackground

func IsBackground(ctx context.Context) bool

IsBackground says whether a context was marked with Background.

func SetBusy

func SetBusy(f func() bool)

SetBusy gives the question Yield asks. The server sets it once at start.

func Slots

func Slots(k Kind) int

Slots is how many of a kind may run at once on this machine. Each is a process of its own, with tens of megabytes of memory and a processor to itself for as long as it runs.

func Stats

func Stats() (times int64, waited time.Duration)

Stats is how often background work has been held back since the server started, and for how long in all.

func Yield

func Yield(ctx context.Context) error

Yield is called by background work before each piece of it: a file to probe, a picture to fetch. On a small machine it waits while someone's stream is being converted, so the scan doesn't take the processor a film needs. It never waits for ever: after a while one piece goes through, so a scan started during a long film still finishes, slowly. Foreground work and roomy machines return at once. The only error is the context's own.

Types

type Class

type Class int

Class is how much machine there is.

const (
	// Tiny: a Raspberry Pi 3 or the like. Up to 1.5 GB of memory, or one or two processors
	// with up to 2 GB.
	Tiny Class = iota
	// Small: an old Celeron or Atom mini PC, a Pi 4 with 2 or 4 GB. Up to four processors
	// or up to 4 GB.
	Small
	// Roomy: anything larger. Nothing is held back.
	Roomy
)

func Classify

func Classify(cores int, memoryMB int64) Class

Classify says what class a machine with these processors and this much memory is. Memory of 0 is "not known", and then the processors alone decide.

func Machine

func Machine() Class

Machine is this machine's class, worked out once. WMS_MACHINE=tiny, small or roomy overrides it, for a machine this reads wrongly and for trying the small settings on a large one.

func (Class) String

func (c Class) String() string

type Kind

type Kind int

Kind is a sort of work that is limited to so many at once.

const (
	// Probes: ffprobe reading a file's details.
	Probes Kind = iota
	// Thumbs: FFmpeg making a small picture.
	Thumbs
)

type Tuning

type Tuning struct {
	Class       Class
	Cores       int
	MemoryMB    int64
	MemoryLimit int64 // bytes given to Go as its soft limit, 0 when left alone
	GCPercent   int   // 0 when left alone
}

Tuning is what Tune did, for the log.

func Tune

func Tune() Tuning

Tune tells Go's memory manager how much this machine can spare. Without it Go lets the heap double before collecting, whatever the machine holds: on 1 GB, beside FFmpeg, that is what gets a server killed for memory. With a soft limit it collects harder as it nears the limit instead. Whoever set GOMEMLIMIT or GOGC themselves keeps what they set.

Jump to

Keyboard shortcuts

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