diff --git a/cmd/thanos/main.go b/cmd/thanos/main.go index a44ac43624..6d88c94ff7 100644 --- a/cmd/thanos/main.go +++ b/cmd/thanos/main.go @@ -35,6 +35,7 @@ import ( "github.com/thanos-io/thanos/pkg/runutil" "github.com/thanos-io/thanos/pkg/tracing" "github.com/thanos-io/thanos/pkg/tracing/client" + "go.uber.org/automaxprocs/maxprocs" "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/credentials" @@ -115,6 +116,18 @@ func main() { logger = log.With(logger, "ts", log.DefaultTimestampUTC, "caller", log.DefaultCaller) } + loggerAdapter := func(template string, args ...interface{}) { + level.Debug(logger).Log("msg", fmt.Sprintf(template, args)) + } + + // Running in container with limits but with empty/wrong value of GOMAXPROCS env var could lead to throttling by cpu + // maxprocs will automate adjustment by using cgroups info about cpu limit if it set as value for runtime.GOMAXPROCS + undo, err := maxprocs.Set(maxprocs.Logger(loggerAdapter)) + defer undo() + if err != nil { + fmt.Fprintln(os.Stderr, errors.Wrapf(err, "failed to set GOMAXPROCS: %v", err)) + } + metrics := prometheus.NewRegistry() metrics.MustRegister( version.NewCollector("thanos"), diff --git a/go.mod b/go.mod index e4409028ff..f42d01413b 100644 --- a/go.mod +++ b/go.mod @@ -39,6 +39,7 @@ require ( github.com/uber/jaeger-client-go v2.16.0+incompatible github.com/uber/jaeger-lib v2.0.0+incompatible go.uber.org/atomic v1.4.0 // indirect + go.uber.org/automaxprocs v1.2.0 golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 golang.org/x/sync v0.0.0-20190423024810-112230192c58 golang.org/x/text v0.3.2 diff --git a/go.sum b/go.sum index 66a71e6670..11a1950b81 100644 --- a/go.sum +++ b/go.sum @@ -410,6 +410,7 @@ go.opencensus.io v0.22.0 h1:C9hSCOW830chIVkdja34wa6Ky+IzWllkUinR+BtRZd4= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.uber.org/atomic v1.4.0 h1:cxzIVoETapQEqDhQu3QfnvXAV4AlzcvUCxkVUFw3+EU= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/automaxprocs v1.2.0/go.mod h1:YfO3fm683kQpzETxlTGZhGIVmXAhaw3gxeBADbpZtnU= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181025213731-e84da0312774/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=