concurrency

package
v1.37.13 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	GOMAXPROCS   = runtime.GOMAXPROCS(0)
	GOMAXPROCSx2 = GOMAXPROCS * 2
	GOMAXPROCS_2 = max(GOMAXPROCS/2, 1)

	SROAR_MERGE = GOMAXPROCS_2
)

Use runtime.GOMAXPROCS instead of runtime.NumCPU because NumCPU returns the physical CPU cores. However, in a containerization context, that might not be what we want. The physical node could have 128 cores, but we could be cgroup-limited to 2 cores. In that case, we want 2 to be our limit, not 128. It isn't guaranteed that MAXPROCS reflects the cgroup limit, but at least there is a chance that it was set correctly. If not, it defaults to NumCPU anyway, so we're not any worse off.

Functions

func BudgetCapDisabled added in v1.36.22

func BudgetCapDisabled() bool

BudgetCapDisabled reports whether the sroar merge budget kill switch is set.

func BudgetFromCtx added in v1.31.8

func BudgetFromCtx(ctx context.Context, fallback int) int

func BudgetFromCtxCapped added in v1.36.22

func BudgetFromCtxCapped(ctx context.Context, limit int) int

BudgetFromCtxCapped returns ctx's per-query budget clamped to [1, limit]; limit is also the fallback when ctx carries no budget. The floor of 1 is load-bearing: sroar's *Conc ops treat maxConcurrency<=0 as "unlimited".

func ContextWithFractionalBudget added in v1.31.8

func ContextWithFractionalBudget(ctx context.Context, factor, fallback int) context.Context

func CtxWithBudget added in v1.31.8

func CtxWithBudget(ctx context.Context, budget int) context.Context

func FractionOf added in v1.31.8

func FractionOf(original, factor int) int

func NoMoreThanGOMAXPROCS added in v1.35.0

func NoMoreThanGOMAXPROCS(conc int) int

func TimesFloatGOMAXPROCS added in v1.35.0

func TimesFloatGOMAXPROCS(factor float64) int

TimesFloatGOMAXPROCS calculate number of gorutines based on GOMAXPROCS and given factor greater or equal to 0.

func TimesGOMAXPROCS added in v1.35.0

func TimesGOMAXPROCS(factor int) int

TimesGOMAXPROCS calculate number of gorutines based on GOMAXPROCS and given factor. Negative factors are interpreted as fractions. Result is rounded down, min returned result is 1. Examples for factors: * -3: GOMAXPROCS/3 * -2: GOMAXPROCS/2 * -1, 0, 1: GOMAXPROCS * 2: GOMAXPROCS*2 * 3: GOMAXPROCS*3

Types

This section is empty.

Directories

Path Synopsis
Package testinghelpers provides shared assertions for concurrency-budget tests: verifying hot read paths don't fan out more goroutines than budgeted.
Package testinghelpers provides shared assertions for concurrency-budget tests: verifying hot read paths don't fan out more goroutines than budgeted.

Jump to

Keyboard shortcuts

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