From 069484ab0eec3b4cb22523fc5ccaf4ea5ce3e8ab Mon Sep 17 00:00:00 2001 From: jaffee Date: Wed, 16 Nov 2016 15:47:07 -0600 Subject: [PATCH] bspawn can create and tear down cluster for benchmarks --- cmd/pilosactl/main.go | 30 +++++++++++++++++++++++++++--- cmd/pilosactl/multidbspawn.json | 4 ++-- cmd/pilosactl/randspawn.json | 4 ++-- cmd/pilosactl/spawn.json | 4 ++-- 4 files changed, 33 insertions(+), 9 deletions(-) diff --git a/cmd/pilosactl/main.go b/cmd/pilosactl/main.go index 903a32a7a..c302262c2 100644 --- a/cmd/pilosactl/main.go +++ b/cmd/pilosactl/main.go @@ -1225,14 +1225,27 @@ The following flags are allowed: `) } -// Run executes the main program execution. +// create separates creation from running for use programmatically by other +// commands like bspawn. +func (cmd *CreateCommand) create() (creator.Cluster, error) { + switch cmd.Type { + case "local": + return creator.NewLocalCluster(cmd.ReplicaN, cmd.ServerN) + case "AWS": + return nil, fmt.Errorf("unimplemented create type: %v", cmd.Type) + default: + return nil, fmt.Errorf("unsupported create type: %v", cmd.Type) + } +} + +// Run executes cluster creation. func (cmd *CreateCommand) Run() error { var clus creator.Cluster switch cmd.Type { case "local": var err error if cmd.run { - clus, err = creator.NewLocalCluster(cmd.ReplicaN, cmd.ServerN) + clus, err = cmd.create() if err != nil { return fmt.Errorf("running create command: %v", err) } @@ -1436,7 +1449,7 @@ func (cmd *BspawnCommand) ParseFlags(args []string) error { // Usage returns the usage message to be printed. func (cmd *BspawnCommand) Usage() string { return strings.TrimSpace(` -pilosactl bspaw is a tool for running multiple instances of bagent against a cluster. +pilosactl bspawn is a tool for running multiple instances of bagent against a cluster. Usage: @@ -1446,6 +1459,17 @@ pilosactl spawn configfile // Run executes the main program execution. func (cmd *BspawnCommand) Run() error { + if len(cmd.PilosaHosts) == 0 { + // must create cluster + createCmd := NewCreateCommand(cmd.Stdin, cmd.Stdout, cmd.Stderr) + createCmd.ParseFlags(cmd.CreatorArgs) + clus, err := createCmd.create() + if err != nil { + return fmt.Errorf("Cluster creation error while spawning: %v", err) + } + defer clus.Shutdown() + cmd.PilosaHosts = clus.Hosts() + } switch cmd.Agents.Type { case "local": return cmd.spawnLocal() diff --git a/cmd/pilosactl/multidbspawn.json b/cmd/pilosactl/multidbspawn.json index b3b58fc38..a22db6fbd 100644 --- a/cmd/pilosactl/multidbspawn.json +++ b/cmd/pilosactl/multidbspawn.json @@ -1,10 +1,10 @@ { - "PilosaHosts": ["localhost:19327","localhost:19328","localhost:19329"], + "CreatorArgs": ["-type", "local", "-serverN", "3", "-replicaN", "1"], "Agents": { "Type": "local" }, "Benchmarks": [ { "Num": 3, - "Args": ["MultiDBSetBits", "-Iterations", "100000", "-ClientType", "round_robin"] + "Args": ["MultiDBSetBits", "-Iterations", "30000", "-ClientType", "round_robin"] } ] } diff --git a/cmd/pilosactl/randspawn.json b/cmd/pilosactl/randspawn.json index a0956d38d..91a6d5866 100644 --- a/cmd/pilosactl/randspawn.json +++ b/cmd/pilosactl/randspawn.json @@ -1,10 +1,10 @@ { - "PilosaHosts": ["localhost:19327","localhost:19328","localhost:19329"], + "CreatorArgs": ["-type", "local", "-serverN", "3", "-replicaN", "1"], "Agents": { "Type": "local" }, "Benchmarks": [ { "Num": 3, - "Args": ["RandomSetBits", "-Iterations", "10000", "-ProfileIDRange", "1000000", "-BitmapIDRange", "1000000", "-Seed", "2345", "-ClientType", "round_robin"] + "Args": ["RandomSetBits", "-Iterations", "30000", "-ProfileIDRange", "1000000", "-BitmapIDRange", "1000000", "-Seed", "2345", "-ClientType", "round_robin"] } ] } diff --git a/cmd/pilosactl/spawn.json b/cmd/pilosactl/spawn.json index 942a4610e..35743c0b3 100644 --- a/cmd/pilosactl/spawn.json +++ b/cmd/pilosactl/spawn.json @@ -1,10 +1,10 @@ { - "PilosaHosts": ["localhost:19327","localhost:19328","localhost:19329"], + "CreatorArgs": ["-type", "local", "-serverN", "3", "-replicaN", "1"], "Agents": { "Type": "local" }, "Benchmarks": [ { "Num": 3, - "Args": ["DiagonalSetBits", "-Iterations", "100000", "-ClientType", "round_robin"] + "Args": ["DiagonalSetBits", "-Iterations", "30000", "-ClientType", "round_robin"] } ] }