Documentation
¶
Index ¶
- Variables
- func BudgetFromCtx(ctx context.Context, fallback int) int
- func ContextWithFractionalBudget(ctx context.Context, factor, fallback int) context.Context
- func CtxWithBudget(ctx context.Context, budget int) context.Context
- func FractionOf(original, factor int) int
- func NoMoreThanGOMAXPROCS(conc int) int
- func TimesFloatGOMAXPROCS(factor float64) int
- func TimesGOMAXPROCS(factor int) int
Constants ¶
This section is empty.
Variables ¶
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 ContextWithFractionalBudget ¶ added in v1.31.8
func CtxWithBudget ¶ added in v1.31.8
func FractionOf ¶ added in v1.31.8
func NoMoreThanGOMAXPROCS ¶ added in v1.35.0
func TimesFloatGOMAXPROCS ¶ added in v1.35.0
TimesFloatGOMAXPROCS calculate number of gorutines based on GOMAXPROCS and given factor greater or equal to 0.
func TimesGOMAXPROCS ¶ added in v1.35.0
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.