automaxprocs — screenshot of github.com

automaxprocs

I use automaxprocs to automatically configure GOMAXPROCS, ensuring my Go applications running in Linux containers respect CPU quotas for optimal performance and to avoid throttling.

Visit github.com →

Questions & Answers

What is automaxprocs?
automaxprocs is a Go library that automatically adjusts the GOMAXPROCS environment variable to match the Linux container CPU quota. This helps Go applications utilize CPU resources efficiently within containerized environments.
Who should use automaxprocs?
Developers deploying Go applications in containerized environments like Docker or Kubernetes should use automaxprocs. It is particularly beneficial for services that might experience performance degradation or throttling due to incorrect GOMAXPROCS settings.
How does automaxprocs improve Go application performance in containers?
By dynamically setting GOMAXPROCS to the container's CPU quota, automaxprocs prevents the Go runtime from over-scheduling goroutines beyond available CPU capacity. This significantly reduces CPU throttling and improves request per second (RPS) and latency metrics, especially P99 latencies, compared to default or manually misconfigured GOMAXPROCS values.
When should I integrate automaxprocs into my Go application?
Integrate automaxprocs when deploying Go services into environments where CPU resources are managed by Linux container quotas. It's especially important for applications with high concurrency or strict latency requirements to ensure efficient resource utilization and stable performance.
How is automaxprocs installed and enabled in a Go application?
automaxprocs can be installed using go get -u go.uber.org/automaxprocs. To enable it, simply import _ "go.uber.org/automaxprocs" in your main package. The library initializes itself automatically, adjusting GOMAXPROCS at startup.