Skip to content

Commit

Permalink
Add configurable workers for each controller, defaults to 10
Browse files Browse the repository at this point in the history
Signed-off-by: Dilip Tadepalli <[email protected]>
  • Loading branch information
dilipmighty245 committed Mar 16, 2024
1 parent f8f0a65 commit 5c1623a
Show file tree
Hide file tree
Showing 5 changed files with 247 additions and 33 deletions.
30 changes: 30 additions & 0 deletions cmd/kcp/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package main
import (
"fmt"
"io"
"strconv"
"strings"

"github.com/spf13/cobra"
"github.com/spf13/pflag"
Expand Down Expand Up @@ -67,3 +69,31 @@ func printMostImportantFlags(w io.Writer, fss cliflag.NamedFlagSets, cols int, v

cliflag.PrintSections(w, filteredFFS, cols)
}

func parseControllerSettings(flagString string) map[string]int {
settingsMap := make(map[string]int)

// Split the flag string based on commas
settings := strings.Split(flagString, ",")

// Iterate over each setting
for _, setting := range settings {
// Split the setting into key and value based on '='
parts := strings.Split(setting, "=")
if len(parts) == 2 {
key := strings.TrimSpace(parts[0])
value := strings.TrimSpace(parts[1])
num, err := strconv.Atoi(value)
if err != nil {
fmt.Println("Error:", err)
continue
}
settingsMap[key] = num
} else {
// Handle invalid format
fmt.Printf("Invalid format for setting: %s\n", setting)
}
}

return settingsMap
}
8 changes: 7 additions & 1 deletion cmd/kcp/kcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func main() {

// manually extract root directory from flags first as it influence all other flags
rootDir := ".kcp"
controllerThreadsStr := ""
for i, f := range os.Args {
if f == "--root-directory" {
if i < len(os.Args)-1 {
Expand All @@ -76,6 +77,10 @@ func main() {
} else if strings.HasPrefix(f, "--root-directory=") {
rootDir = strings.TrimPrefix(f, "--root-directory=")
}

if strings.HasPrefix(f, "--controller-threads=") {
controllerThreadsStr = strings.TrimPrefix(f, "--controller-threads=")
}
}

serverOptions := options.NewOptions(rootDir)
Expand Down Expand Up @@ -136,7 +141,8 @@ func main() {
}
}

s, err := server.NewServer(completedConfig)
controllerThreads := parseControllerSettings(controllerThreadsStr)
s, err := server.NewServer(completedConfig, server.WithControllerThreads(controllerThreads))
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit 5c1623a

Please sign in to comment.