From 1f973b7eb653e0df459fd046f365d75357d77941 Mon Sep 17 00:00:00 2001 From: Thomas Way Date: Mon, 26 Feb 2024 00:44:31 +0000 Subject: [PATCH] chore: use Linux container CPU quota Go is not cgroup aware and by default will set GOMAXPROCS to the number of available threads, regardless of whether it is within the allocated quota. This behaviour causes high amount of CPU throttling and degraded application performance. Fixes: #3735 Signed-off-by: Thomas Way --- cmd/alertmanager/main.go | 1 + cmd/amtool/main.go | 5 ++++- go.mod | 1 + go.sum | 4 ++++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/cmd/alertmanager/main.go b/cmd/alertmanager/main.go index b2938189d5..da9e185899 100644 --- a/cmd/alertmanager/main.go +++ b/cmd/alertmanager/main.go @@ -41,6 +41,7 @@ import ( "github.com/prometheus/common/version" "github.com/prometheus/exporter-toolkit/web" webflag "github.com/prometheus/exporter-toolkit/web/kingpinflag" + _ "go.uber.org/automaxprocs" "github.com/prometheus/alertmanager/api" "github.com/prometheus/alertmanager/cluster" diff --git a/cmd/amtool/main.go b/cmd/amtool/main.go index 9e36fb9d39..3f15478288 100644 --- a/cmd/amtool/main.go +++ b/cmd/amtool/main.go @@ -13,7 +13,10 @@ package main -import "github.com/prometheus/alertmanager/cli" +import ( + "github.com/prometheus/alertmanager/cli" + _ "go.uber.org/automaxprocs" +) func main() { cli.Execute() diff --git a/go.mod b/go.mod index 76aa4a2f4b..d218450752 100644 --- a/go.mod +++ b/go.mod @@ -39,6 +39,7 @@ require ( github.com/stretchr/testify v1.8.4 github.com/xlab/treeprint v1.2.0 go.uber.org/atomic v1.11.0 + go.uber.org/automaxprocs v1.5.3 golang.org/x/mod v0.14.0 golang.org/x/net v0.20.0 golang.org/x/text v0.14.0 diff --git a/go.sum b/go.sum index 60f1a0a695..b779aeb9e7 100644 --- a/go.sum +++ b/go.sum @@ -413,6 +413,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s= +github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g= +github.com/prashantv/gostub v1.1.0/go.mod h1:A5zLQHz7ieHGG7is6LLXLz7I8+3LZzsrV0P1IAHhP5U= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= github.com/prometheus/client_golang v1.4.0/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU= @@ -526,6 +528,8 @@ go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqe go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE= go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= +go.uber.org/automaxprocs v1.5.3 h1:kWazyxZUrS3Gs4qUpbwo5kEIMGe/DAvi5Z4tl2NW4j8= +go.uber.org/automaxprocs v1.5.3/go.mod h1:eRbA25aqJrxAbsLO0xy5jVwPt7FQnRgjW+efnwa1WM0= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=