Skip to content

Set GOMAXPROCS quota aware in Linux containers #9357

@bt90

Description

@bt90

We currently set GOMAXPROCS to the available number of CPU cores if nothing is explicitly configured by the user:

if os.Getenv("GOMAXPROCS") == "" {
runtime.GOMAXPROCS(runtime.NumCPU())
}

This doesn't play very nice with CPU quotas. See golang/go#33803

A possible solution might be https://github.com/uber-go/automaxprocs

 if os.Getenv("GOMAXPROCS") == "" { 
 	maxprocs.Set(maxprocs.Logger(log.Printf))
 } 

We can even get away with a simple import, because automaxprocs honors GOMAXPROCS by default:

import _ "go.uber.org/automaxprocs"

A blog post which covers this topic: https://www.riverphillips.dev/blog/go-cfs/

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew features or improvements of some kind, as opposed to a problem (bug)frozen-due-to-ageIssues closed and untouched for a long time, together with being locked for discussionneeds-triageNew issues needed to be validated

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions