Skip to content

Commit

Permalink
Automatically set GOMAXPROCS to match the number of CPUs available to…
Browse files Browse the repository at this point in the history
… the container

Signed-off-by: Rajat Vig <rajat.vig@gmail.com>
Signed-off-by: Rajat Vig <rvig@etsy.com>
  • Loading branch information
rajatvig committed Mar 20, 2023
1 parent 43f7f4b commit faa5e67
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/5211-rajatvig-small.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Contour now sets GOMAXPROCS to match the number of CPUs available to the container which results in lower and more stable CPU usage under high loads and where the container and node CPU counts differ significantly.
4 changes: 4 additions & 0 deletions cmd/contour/contour.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package main

import (
"go.uber.org/automaxprocs/maxprocs"
"os"

"github.com/alecthomas/kingpin/v2"
Expand All @@ -29,6 +30,9 @@ func main() {
log := logrus.StandardLogger()
k8s.InitLogging(k8s.LogWriterOption(log.WithField("context", "kubernetes")))

// set GOMAXPROCS
maxprocs.Set(maxprocs.Logger(log.Printf))

// NOTE: when add a new subcommand, we'll have to remember to add it to 'TestOptionFlagsAreSorted'
// to ensure the option flags in lexicographic order.

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ require (
github.com/stretchr/testify v1.8.2
github.com/tsaarni/certyaml v0.9.2
github.com/vektra/mockery/v2 v2.22.1
go.uber.org/automaxprocs v1.5.2
golang.org/x/oauth2 v0.6.0
gonum.org/v1/plot v0.12.0
google.golang.org/genproto v0.0.0-20230117162540-28d6b9783ac4
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZ
github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g=
github.com/projectcontour/yages v0.1.0 h1:vcFpregOq5TVF0/AXLive1MY4CVMDkgL7/+qbUeIbDs=
github.com/projectcontour/yages v0.1.0/go.mod h1:pcJrPa3dP17HwGj2YOfBZ4w5WmC1rSpv/X/sV4wauSw=
github.com/prometheus/client_golang v1.14.0 h1:nJdhIvne2eSX/XRAFV9PcvFFRbrjbcTUj0VP62TMhnw=
Expand Down Expand Up @@ -412,6 +413,8 @@ go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk=
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
go.uber.org/automaxprocs v1.5.2 h1:2LxUOGiR3O6tw8ui5sZa2LAaHnsviZdVOUZw4fvbnME=
go.uber.org/automaxprocs v1.5.2/go.mod h1:eRbA25aqJrxAbsLO0xy5jVwPt7FQnRgjW+efnwa1WM0=
go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/multierr v1.8.0 h1:dg6GjLku4EH+249NNmoIciG9N/jURbDG+pFlTkhzIC8=
Expand Down

0 comments on commit faa5e67

Please sign in to comment.