concurrency

package
v1.35.21 Latest Latest
Warning

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

Go to latest
Published: May 21, 2026 License: BSD-3-Clause Imports: 3 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 BudgetFromCtx added in v1.31.8

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

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.

Jump to

Keyboard shortcuts

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