Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DEVOPS-633] Change maximum concurrency approach #11

Merged
merged 1 commit into from
Dec 28, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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