Skip to content

Commit

Permalink
Auto set GOMAXPROCS based on container limits in executor and operator
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-valkov committed Aug 6, 2021
1 parent 83717e8 commit 701fa92
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 93 deletions.
8 changes: 8 additions & 0 deletions executor/cmd/executor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
predictor2 "github.com/seldonio/seldon-core/executor/predictor"
"github.com/seldonio/seldon-core/executor/proto/tensorflow/serving"
v1 "github.com/seldonio/seldon-core/operator/apis/machinelearning.seldon.io/v1"
"go.uber.org/automaxprocs/maxprocs"
"go.uber.org/zap"
"google.golang.org/grpc/reflection"
zapf "sigs.k8s.io/controller-runtime/pkg/log/zap"
Expand Down Expand Up @@ -259,6 +260,13 @@ func main() {
setupLogger()
logger := logf.Log.WithName("entrypoint")

// Set runtime.GOMAXPROCS to respect container limits if the env var GOMAXPROCS is not set or is invalid, preventing CPU throttling.
undo, err := maxprocs.Set(maxprocs.Logger(logger.Info))
defer undo()
if err != nil {
logger.Error(err, "failed to set GOMAXPROCS")
}

// Set hostname
if *hostname == "" {
*hostname = os.Getenv("POD_NAME")
Expand Down
11 changes: 10 additions & 1 deletion executor/cmd/proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package main

import (
"flag"
"os"

"github.com/prometheus/common/log"
"github.com/seldonio/seldon-core/executor/api"
"github.com/seldonio/seldon-core/executor/api/kafka"
"github.com/seldonio/seldon-core/executor/api/rest"
"github.com/seldonio/seldon-core/executor/k8s"
predictor2 "github.com/seldonio/seldon-core/executor/predictor"
"os"
"go.uber.org/automaxprocs/maxprocs"
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
)

Expand Down Expand Up @@ -64,6 +66,13 @@ func main() {
logf.SetLogger(logf.ZapLogger(false))
logger := logf.Log.WithName("entrypoint")

// Set runtime.GOMAXPROCS to respect container limits if the env var GOMAXPROCS is not set or is invalid, preventing CPU throttling.
undo, err := maxprocs.Set(maxprocs.Logger(logger.Info))
defer undo()
if err != nil {
logger.Error(err, "failed to set GOMAXPROCS")
}

kafkaProxy := kafka.NewKafkaProxy(client, *modelName, *predictorName, *sdepName, *namespace, *broker, *hostname, int32(*httpPort), logger)

err = kafkaProxy.Consume()
Expand Down
2 changes: 1 addition & 1 deletion executor/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ require (
github.com/tensorflow/tensorflow/tensorflow/go/core v0.0.0-00010101000000-000000000000
github.com/uber/jaeger-client-go v2.25.0+incompatible
github.com/uber/jaeger-lib v2.2.0+incompatible // indirect
go.uber.org/automaxprocs v1.4.0
go.uber.org/zap v1.16.0
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
google.golang.org/grpc v1.32.0
gotest.tools v2.2.0+incompatible
k8s.io/api v0.18.8
k8s.io/apimachinery v0.18.8
sigs.k8s.io/controller-runtime v0.6.4
)

Expand Down
43 changes: 5 additions & 38 deletions executor/go.sum

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions operator/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/kedacore/keda v0.0.0-20200911122749-717aab81817f
github.com/onsi/ginkgo v1.15.0
github.com/onsi/gomega v1.10.4
go.uber.org/automaxprocs v1.4.0
go.uber.org/zap v1.15.0
gopkg.in/yaml.v2 v2.4.0
istio.io/api v0.0.0-20200513175333-ae3da0d240e3
Expand Down
57 changes: 4 additions & 53 deletions operator/go.sum

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
machinelearningv1alpha3 "github.com/seldonio/seldon-core/operator/apis/machinelearning.seldon.io/v1alpha3"
"github.com/seldonio/seldon-core/operator/controllers"
k8sutils "github.com/seldonio/seldon-core/operator/utils/k8s"
"go.uber.org/automaxprocs/maxprocs"
"go.uber.org/zap"
istio "istio.io/client-go/pkg/apis/networking/v1alpha3"
appsv1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -135,6 +136,13 @@ func main() {

config := ctrl.GetConfigOrDie()

// Set runtime.GOMAXPROCS to respect container limits if the env var GOMAXPROCS is not set or is invalid, preventing CPU throttling.
undo, err := maxprocs.Set(maxprocs.Logger(setupLog.Info))
defer undo()
if err != nil {
setupLog.Error(err, "failed to set GOMAXPROCS")
}

//Override operator namespace from environment variable as the source of truth
operatorNamespace = utils.GetEnv("POD_NAMESPACE", operatorNamespace)

Expand Down

0 comments on commit 701fa92

Please sign in to comment.