all: Use automaxprocs

automaxprocs tunes GOMAXPROCS to match Linux container CPU quota. This is useful
in containerized environments were your NumCPU can be much larger than your
effective CPU amount. We have observed in those environments performance
degredation in the go runtime. Tuning this should help.

Change-Id: Iccdaebb9345f8bb41084f4a82804e60b68a16e02
diff --git a/cmd/zoekt-archive-index/main.go b/cmd/zoekt-archive-index/main.go
index 1685c62..24c362e 100644
--- a/cmd/zoekt-archive-index/main.go
+++ b/cmd/zoekt-archive-index/main.go
@@ -22,6 +22,9 @@
 	"github.com/google/zoekt/build"
 	"github.com/google/zoekt/cmd"
 	"github.com/google/zoekt/gitindex"
+
+	// Tune GOMAXPROCS to match Linux container CPU quota.
+	_ "go.uber.org/automaxprocs"
 )
 
 // stripComponents removes the specified number of leading path
diff --git a/cmd/zoekt-git-index/main.go b/cmd/zoekt-git-index/main.go
index 59f7d6e..b0acf33 100644
--- a/cmd/zoekt-git-index/main.go
+++ b/cmd/zoekt-git-index/main.go
@@ -23,6 +23,9 @@
 
 	"github.com/google/zoekt/cmd"
 	"github.com/google/zoekt/gitindex"
+
+	// Tune GOMAXPROCS to match Linux container CPU quota.
+	_ "go.uber.org/automaxprocs"
 )
 
 func main() {
diff --git a/cmd/zoekt-index/main.go b/cmd/zoekt-index/main.go
index 3ac304a..cde9fbf 100644
--- a/cmd/zoekt-index/main.go
+++ b/cmd/zoekt-index/main.go
@@ -27,6 +27,9 @@
 	"github.com/google/zoekt"
 	"github.com/google/zoekt/build"
 	"github.com/google/zoekt/cmd"
+
+	// Tune GOMAXPROCS to match Linux container CPU quota.
+	_ "go.uber.org/automaxprocs"
 )
 
 type fileInfo struct {
diff --git a/cmd/zoekt-repo-index/main.go b/cmd/zoekt-repo-index/main.go
index fd8bd97..4469906 100644
--- a/cmd/zoekt-repo-index/main.go
+++ b/cmd/zoekt-repo-index/main.go
@@ -48,6 +48,9 @@
 
 	git "gopkg.in/src-d/go-git.v4"
 	"gopkg.in/src-d/go-git.v4/plumbing"
+
+	// Tune GOMAXPROCS to match Linux container CPU quota.
+	_ "go.uber.org/automaxprocs"
 )
 
 var _ = log.Println
diff --git a/cmd/zoekt-webserver/main.go b/cmd/zoekt-webserver/main.go
index fcb2f28..3478bee 100644
--- a/cmd/zoekt-webserver/main.go
+++ b/cmd/zoekt-webserver/main.go
@@ -35,6 +35,9 @@
 	"github.com/google/zoekt/build"
 	"github.com/google/zoekt/shards"
 	"github.com/google/zoekt/web"
+
+	// Tune GOMAXPROCS to match Linux container CPU quota.
+	_ "go.uber.org/automaxprocs"
 )
 
 const logFormat = "2006-01-02T15-04-05.999999999Z07"
diff --git a/go.mod b/go.mod
index 6eb793c..defd494 100644
--- a/go.mod
+++ b/go.mod
@@ -10,6 +10,7 @@
 	github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348
 	github.com/mitchellh/mapstructure v1.1.2 // indirect
 	github.com/xanzy/go-gitlab v0.13.0
+	go.uber.org/automaxprocs v1.2.0
 	golang.org/x/net v0.0.0-20181114220301-adae6a3d119a
 	golang.org/x/oauth2 v0.0.0-20181120190819-8f65e3013eba
 	golang.org/x/sync v0.0.0-20181108010431-42b317875d0f
diff --git a/go.sum b/go.sum
index 442bc74..3a2563e 100644
--- a/go.sum
+++ b/go.sum
@@ -60,6 +60,8 @@
 github.com/xanzy/go-gitlab v0.13.0/go.mod h1:8zdQa/ri1dfn8eS3Ir1SyfvOKlw7WBJ8DVThkpGiXrs=
 github.com/xanzy/ssh-agent v0.2.0 h1:Adglfbi5p9Z0BmK2oKU9nTG+zKfniSfnaMYB+ULd+Ro=
 github.com/xanzy/ssh-agent v0.2.0/go.mod h1:0NyE30eGUDliuLEHJgYte/zncp2zdTStcOnWhgSqHD8=
+go.uber.org/automaxprocs v1.2.0 h1:+RUihKM+nmYUoB9w0D0Ov5TJ2PpFO2FgenTxMJiZBZA=
+go.uber.org/automaxprocs v1.2.0/go.mod h1:YfO3fm683kQpzETxlTGZhGIVmXAhaw3gxeBADbpZtnU=
 golang.org/x/crypto v0.0.0-20180904163835-0709b304e793 h1:u+LnwYTOOW7Ukr/fppxEb1Nwz0AtPflrblfvUudpo+I=
 golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
 golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=