Skip to content

Commit

Permalink
Merge pull request #11 from spotahome/devops-633-set-multiple-threads
Browse files Browse the repository at this point in the history
[DEVOPS-633] Change maximum concurrency approach
  • Loading branch information
jchanam authored Dec 28, 2017
2 parents da955e4 + 0e580bd commit 63f0208
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions cmd/operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"net/http"
"os"
"os/signal"
"runtime"

apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/client-go/kubernetes"
Expand All @@ -18,10 +17,10 @@ import (
)

type flags struct {
kubeConfig string
listenAddr string
metricsPath string
maxThreads int
kubeConfig string
listenAddr string
metricsPath string
maxConcurrency int
}

func initFlags() flags {
Expand All @@ -31,7 +30,7 @@ func initFlags() flags {
flag.StringVar(&f.kubeConfig, "kubeconfig", "", "Path to a kube config. Only required if out-of-cluster.")
flag.StringVar(&f.listenAddr, "listen-address", ":9710", "Address to listen on for metrics.")
flag.StringVar(&f.metricsPath, "metrics-path", "/metrics", "Path to serve the metrics.")
flag.IntVar(&f.maxThreads, "max-threads", 0, "Maximum number of threads.")
flag.IntVar(&f.maxConcurrency, "max-concurrency", 3, "Maximum number of concurrent routines.")

// Parse flags & return.
flag.Parse()
Expand Down Expand Up @@ -65,12 +64,16 @@ func main() {
panic(err)
}

if flags.maxThreads == 0 {
flags.maxThreads = runtime.GOMAXPROCS(0)
if flags.maxConcurrency <= 0 {
log.Panic("The given max concurrency number is invalid")
}

if flags.maxConcurrency == 1 {
log.Warnf("The given max concurrency number (%d) is dangerous", flags.maxConcurrency)
}

stop := make(chan int, 1)
crd, err := failover.NewRedisFailoverCRD(m, clientset, *config, stop, flags.maxThreads)
crd, err := failover.NewRedisFailoverCRD(m, clientset, *config, stop, flags.maxConcurrency)
if err != nil {
log.Panic(err)
}
Expand Down

0 comments on commit 63f0208

Please sign in to comment.