Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(controller): respect group quotas for number of operating system threads allocated to goroutines #915

Merged
merged 1 commit into from
Nov 30, 2023

Conversation

oliverbaehler
Copy link
Collaborator

If the GOMAXPROCS environment variable is not explicitly set when starting the Go process, it defaults to the output of the runtime.NumCPU() function, which represents the number of available CPU cores (i.e., the value of P).

Verify

To verify if that's true, i added the following to main.go:

func MaxParallelism() int {
	maxProcs := goRuntime.GOMAXPROCS(0)
	numCPU := goRuntime.NumCPU()
	if maxProcs < numCPU {
		return maxProcs
	}
	return numCPU
}

//nolint:maintidx
func main() {
	fmt.Println("MaxParallelism: ", MaxParallelism())

This print out how many cores will be allocated.

  1. Deployed with the main build
kubectl logs -f capsule-controller-manager-8c89798fc-hv5gp -n capsule-system
MaxParallelism:  4
...
  1. Deployed with the go.uber.org/automaxprocs import:
2023/11/30 09:52:53 maxprocs: Updating GOMAXPROCS=1: using minimum allowed GOMAXPROCS
MaxParallelism:  1

In both cases the controller had the following resources allocated:

manager:
  resources:
    limits:
      cpu: 500m
      memory: 512Mi
    requests:
      cpu: 200m
      memory: 128Mi

This only takes affect, if resources.limits.cpu are set. If no resources are set, the amount of host CPU cores are used:

2023/11/30 09:50:05 maxprocs: Leaving GOMAXPROCS=4: CPU quota undefined
MaxParallelism:  4

@oliverbaehler oliverbaehler added this to the v0.5.0 milestone Nov 30, 2023
Copy link

netlify bot commented Nov 30, 2023

Deploy Preview for capsule-documentation canceled.

Name Link
🔨 Latest commit 5b31101
🔍 Latest deploy log https://app.netlify.com/sites/capsule-documentation/deploys/65685f57ccfd250008b62a21

…threads allocated to goroutines

Signed-off-by: Oliver Bähler <[email protected]>
@oliverbaehler oliverbaehler changed the title fix(controller): respect group quotas for number of operating system threads allocated to goroutines fix(controller): respect group quotas for number of operating system threads allocated to goroutines Nov 30, 2023
Copy link
Member

@prometherion prometherion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering how we couldn't implement this, you the best, Oliver! 🎩

@prometherion prometherion merged commit 21c0d04 into projectcapsule:main Nov 30, 2023
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants