uber-go/automaxprocs

repository·master·Indexed 26 days ago

https://github.com/uber-go/automaxprocs

A Go library that automatically sets GOMAXPROCS to match the Linux container CPU quota. It helps optimize Go runtime performance and prevent CPU throttling in containerized environments by ensuring the runtime is aware of available CPU resources.

Tokens
284
Snippets
2
Records
4
Agent score
39%

What's inside automaxprocs

  1. Overview of automaxprocs

    master
    automaxprocs is a library that automatically sets the GOMAXPROCS environment variable to match the Linux container CPU quota. This helps prevent CPU throttling and improves performance in containerized environments by ensuring the Go runtime is aware of the actual CPU resources available to the container.
  2. Use automaxprocs in your application

    master

    To automatically set GOMAXPROCS to match your Linux container's CPU quota, import the package with a blank identifier (_) in your main package. This triggers the configuration during the application's initialization.

    import _ "go.uber.org/automaxprocs"
    
    func main() {
      // Your application logic here.
    }
  3. Automatically configure GOMAXPROCS via side-effect import

    master
    To automatically set GOMAXPROCS to match the Linux container CPU quota, import the go.uber.org/automaxprocs package with a blank identifier (_). This triggers the init() function which calls maxprocs.Set using the default standard logger (log.Printf).