in pkg/client/client_v2.go [622:651]
func (c *clientV2) syncComponent(expected *proto.CheckinExpected) {
c.componentMu.Lock()
defer c.componentMu.Unlock()
// applying the component limits
var (
prevGoMaxProcs int
newGoMaxProcs int
)
if c.componentConfig != nil && c.componentConfig.Limits != nil {
prevGoMaxProcs = int(c.componentConfig.Limits.GoMaxProcs)
}
if expected.Component != nil && expected.Component.Limits != nil {
newGoMaxProcs = int(expected.Component.Limits.GoMaxProcs)
}
// calling `runtime.GOMAXPROCS` is expensive, so we call it only when the value really changed
if newGoMaxProcs != prevGoMaxProcs {
if newGoMaxProcs == 0 {
_ = runtime.GOMAXPROCS(runtime.NumCPU())
} else {
_ = runtime.GOMAXPROCS(newGoMaxProcs)
}
}
// Technically we should wait until the APM config is also applied, but the syncUnits is called after this and
// we have a single index for the whole component
c.componentConfig = expected.Component
c.componentIdx = expected.ComponentIdx
}