Skip to content

Set GOMAXPROCS quota aware in Linux containers #9357

Closed

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/

Activity

  1. added
    enhancement
    needs-triage
    on Jan 19, 2024
  2. calmh commented on Jan 19, 2024

    @calmh
    Member

    What we do is a no-op since many years since the default is to use all CPU cores. It should just be removed since it does nothing.

    I honestly don't think we should be doing anything clever here. If the (obviously quite knowledgeable) user is deploying containers with CPU limits rust can also set GOMAXPROCS...

  3. bt90 commented on Jan 19, 2024

    @bt90
    ContributorAuthor

    If the (obviously quite knowledgeable) user is deploying containers with CPU limits rust can also set GOMAXPROCS...

    Adding --cpus="2" isn't rocket science. And even a knowledgeable user might overlook that golang isn't cgroup aware. Case in point: I did

    (even Java is cgroup aware, wtf Google?)

  4. calmh commented on Jan 19, 2024

    @calmh
    Member

    Is the damage we're trying to avoid a few milliseconds pause in GC? If so, I think it's a non-issue for Syncthing specifically. A web service responding to API requests for interactive user things is something else entirely, of course.

  5. reopened this on Feb 26, 2024
  6. added a commit that references this issue on Feb 26, 2024
    aa559bf
  7. added this to the v1.27.4 milestone on Feb 27, 2024
  8. added 2 commits that reference this issue on Jul 7, 2024
    685d17e
    199e176
  9. added
    frozen-due-to-age
    on Apr 9, 2025
  10. locked and limited conversation to collaborators on Apr 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementfrozen-due-to-ageneeds-triage

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions