Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(env): support GOGC default value #7776

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions cmd/thanos/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"regexp"
"runtime"
"runtime/debug"
"strconv"
"syscall"

"github.com/go-kit/log"
Expand Down Expand Up @@ -45,6 +46,10 @@ import (
// Name is the name registered for the proto compressor.
const Name = "proto"

// Use lower GOGC if it isn't set yet.
// It is recommended increasing GOGC if go_memstats_gc_cpu_fraction exceeds 0.05 for extended periods of time.
const DefaultGOGC = 75
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the user be responsible for tweaking this to make it work for their setup? I believe some CPU heavy/bound workloads like receivers will suffer from this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. For advanced users it is reserved for the user to adjust it to suit their setup, but in container scenarios giving it a default value (which is pretty good) is more suitable for most scenarios.


// vtprotoCodec is like the vtprotobuf codec
// but also handles non-vtproto messages that are needed
// for stuff like OpenTelemetry. Otherwise, such errors appear:
Expand Down Expand Up @@ -111,6 +116,17 @@ func main() {
runtime.SetBlockProfileRate(10)
}

if v := os.Getenv("GOGC"); v != "" {
n, err := strconv.ParseFloat(v, 64)
if err != nil {
n = 100
}
debug.SetGCPercent(int(n))
} else {
debug.SetGCPercent(DefaultGOGC)
os.Setenv("GOGC", strconv.Itoa(DefaultGOGC))
}

app := extkingpin.NewApp(kingpin.New(filepath.Base(os.Args[0]), "A block storage based long-term storage for Prometheus.").Version(version.Print("thanos")))
debugName := app.Flag("debug.name", "Name to add as prefix to log lines.").Hidden().String()
logLevel := app.Flag("log.level", "Log filtering level.").
Expand Down
Loading