From a4a6a0c57f4f5b92625fa7c0365f8d0866063383 Mon Sep 17 00:00:00 2001 From: Thomas Way Date: Mon, 26 Feb 2024 01:07:28 +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 + webapp/backend/cmd/scrutiny/scrutiny.go | 5 +++-- webapp/backend/pkg/models/testdata/helper.go | 1 + 4 files changed, 8 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/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() {