From cc5b4144298fc0479fded0ea713ac387f35a91fe Mon Sep 17 00:00:00 2001 From: Thomas Way Date: Mon, 26 Feb 2024 01:11:49 +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: #584 --- collector/cmd/collector-metrics/collector-metrics.go | 5 +++-- collector/cmd/collector-selftest/collector-selftest.go | 1 + go.mod | 1 + go.sum | 3 +++ webapp/backend/cmd/scrutiny/scrutiny.go | 5 +++-- webapp/backend/pkg/models/testdata/helper.go | 1 + 6 files changed, 12 insertions(+), 4 deletions(-) diff --git a/collector/cmd/collector-metrics/collector-metrics.go b/collector/cmd/collector-metrics/collector-metrics.go index 2c9f7090..49f18df2 100644 --- a/collector/cmd/collector-metrics/collector-metrics.go +++ b/collector/cmd/collector-metrics/collector-metrics.go @@ -17,6 +17,7 @@ import ( utils "github.com/analogj/go-util/utils" "github.com/fatih/color" "github.com/urfave/cli/v2" + _ "go.uber.org/automaxprocs" ) var goos string @@ -37,8 +38,8 @@ func main() { } //we're going to load the config file manually, since we need to validate it. - err = config.ReadConfig(configFilePath) // Find and read the config file - if _, ok := err.(errors.ConfigFileMissingError); ok { // Handle errors reading the config file + err = config.ReadConfig(configFilePath) // Find and read the config file + if _, ok := err.(errors.ConfigFileMissingError); ok { // Handle errors reading the config file //ignore "could not find config file" } else if err != nil { os.Exit(1) diff --git a/collector/cmd/collector-selftest/collector-selftest.go b/collector/cmd/collector-selftest/collector-selftest.go index ac2e2fab..d25e6be1 100644 --- a/collector/cmd/collector-selftest/collector-selftest.go +++ b/collector/cmd/collector-selftest/collector-selftest.go @@ -13,6 +13,7 @@ import ( utils "github.com/analogj/go-util/utils" "github.com/fatih/color" "github.com/urfave/cli/v2" + _ "go.uber.org/automaxprocs" ) var goos string diff --git a/go.mod b/go.mod index 95da4548..af528b60 100644 --- a/go.mod +++ b/go.mod @@ -18,6 +18,7 @@ require ( github.com/spf13/viper v1.14.0 github.com/stretchr/testify v1.8.1 github.com/urfave/cli/v2 v2.2.0 + go.uber.org/automaxprocs v1.5.3 golang.org/x/sync v0.1.0 gorm.io/gorm v1.23.5 ) diff --git a/go.sum b/go.sum index 4c2d79f3..07c55f2f 100644 --- a/go.sum +++ b/go.sum @@ -650,6 +650,7 @@ 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/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= @@ -762,6 +763,8 @@ go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +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/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU= diff --git a/webapp/backend/cmd/scrutiny/scrutiny.go b/webapp/backend/cmd/scrutiny/scrutiny.go index ead9ff99..717f6e53 100644 --- a/webapp/backend/cmd/scrutiny/scrutiny.go +++ b/webapp/backend/cmd/scrutiny/scrutiny.go @@ -16,6 +16,7 @@ import ( utils "github.com/analogj/go-util/utils" "github.com/fatih/color" "github.com/urfave/cli/v2" + _ "go.uber.org/automaxprocs" ) var goos string @@ -36,8 +37,8 @@ func main() { } //we're going to load the config file manually, since we need to validate it. - err = config.ReadConfig(configFilePath) // Find and read the config file - if _, ok := err.(errors.ConfigFileMissingError); ok { // Handle errors reading the config file + err = config.ReadConfig(configFilePath) // Find and read the config file + if _, ok := err.(errors.ConfigFileMissingError); ok { // Handle errors reading the config file //ignore "could not find config file" } else if err != nil { log.Print(color.HiRedString("CONFIG ERROR: %v", err)) diff --git a/webapp/backend/pkg/models/testdata/helper.go b/webapp/backend/pkg/models/testdata/helper.go index 5e2c6234..e90a9418 100644 --- a/webapp/backend/pkg/models/testdata/helper.go +++ b/webapp/backend/pkg/models/testdata/helper.go @@ -12,6 +12,7 @@ import ( "time" "github.com/analogj/scrutiny/webapp/backend/pkg/models/collector" + _ "go.uber.org/automaxprocs" ) func main() {