diff --git a/bench/client.go b/bench/client.go new file mode 100644 index 000000000..c8a4c2c05 --- /dev/null +++ b/bench/client.go @@ -0,0 +1,43 @@ +package bench + +import ( + "fmt" + "github.com/umbel/pilosa" +) + +func firstHostClient(hosts []string) (*pilosa.Client, error) { + cli, err := pilosa.NewClient(hosts[0]) + if err != nil { + return nil, err + } + return cli, nil +} + +func roundRobinClient(hosts []string, agentNum int) (*pilosa.Client, error) { + cliNum := agentNum % len(hosts) + return firstHostClient(hosts[cliNum:]) +} + +// HasClient provides a reusable component for Benchmark implementations which +// provides the Init method, a ClientType argument and a cli internal variable. +type HasClient struct { + cli *pilosa.Client + ClientType string +} + +// Init for HasClient looks at the ClientType field and creates a pilosa client +// either using the first host in the list of hosts or based on the agent +// number mod len(hosts) +func (h *HasClient) Init(hosts []string, agentNum int) error { + var err error + switch h.ClientType { + case "single": + h.cli, err = firstHostClient(hosts) + return err + case "round_robin": + h.cli, err = roundRobinClient(hosts, agentNum) + return err + default: + return fmt.Errorf("Unsupported ClientType: %v", h.ClientType) + } +} diff --git a/bench/diagonal.go b/bench/diagonal.go index 6caad1e49..623310243 100644 --- a/bench/diagonal.go +++ b/bench/diagonal.go @@ -7,12 +7,11 @@ import ( "io/ioutil" "context" - "github.com/umbel/pilosa" ) // DiagonalSetBits sets bits with increasing profile id and bitmap id. type DiagonalSetBits struct { - cli *pilosa.Client + HasClient BaseBitmapID int BaseProfileID int Iterations int @@ -38,6 +37,10 @@ The following arguments are available: -DB string pilosa db to use + + -ClientType string + Can be 'single' (all agents hitting one host) or 'round_robin' + `[1:] } @@ -48,6 +51,7 @@ func (b *DiagonalSetBits) ConsumeFlags(args []string) ([]string, error) { fs.IntVar(&b.BaseProfileID, "BaseProfileID", 0, "") fs.IntVar(&b.Iterations, "Iterations", 100, "") fs.StringVar(&b.DB, "DB", "benchdb", "") + fs.StringVar(&b.ClientType, "ClientType", "single", "") if err := fs.Parse(args); err != nil { return nil, err @@ -55,18 +59,6 @@ func (b *DiagonalSetBits) ConsumeFlags(args []string) ([]string, error) { return fs.Args(), nil } -// Init connects to pilosa and sets the client on b. -func (b *DiagonalSetBits) Init(hosts []string, agentNum int) (err error) { - b.cli, err = pilosa.NewClient(hosts[0]) - if err != nil { - return err - } - if b.DB == "" { - b.DB = "DiagonalSetBits" - } - return nil -} - // Run runs the DiagonalSetBits benchmark func (b *DiagonalSetBits) Run(agentNum int) map[string]interface{} { results := make(map[string]interface{}) diff --git a/bench/multidb.go b/bench/multidb.go index cd347f0e1..46f61cf1c 100644 --- a/bench/multidb.go +++ b/bench/multidb.go @@ -8,12 +8,11 @@ import ( "io/ioutil" "context" - "github.com/umbel/pilosa" ) // MultiDBSetBits sets bits with increasing profile id and bitmap id. type MultiDBSetBits struct { - cli *pilosa.Client + HasClient BaseBitmapID int BaseProfileID int Iterations int @@ -36,6 +35,9 @@ The following arguments are available: -Iterations int number of bits to set + -ClientType string + Can be 'single' (all agents hitting one host) or 'round_robin' + `[1:] } @@ -45,6 +47,7 @@ func (b *MultiDBSetBits) ConsumeFlags(args []string) ([]string, error) { fs.IntVar(&b.BaseBitmapID, "BaseBitmapID", 0, "") fs.IntVar(&b.BaseProfileID, "BaseProfileID", 0, "") fs.IntVar(&b.Iterations, "Iterations", 100, "") + fs.StringVar(&b.ClientType, "ClientType", "single", "") if err := fs.Parse(args); err != nil { return nil, err @@ -52,15 +55,6 @@ func (b *MultiDBSetBits) ConsumeFlags(args []string) ([]string, error) { return fs.Args(), nil } -// Init connects to pilosa and sets the client on b. -func (b *MultiDBSetBits) Init(hosts []string, agentNum int) (err error) { - b.cli, err = pilosa.NewClient(hosts[0]) - if err != nil { - return err - } - return nil -} - // Run runs the MultiDBSetBits benchmark func (b *MultiDBSetBits) Run(agentNum int) map[string]interface{} { results := make(map[string]interface{}) diff --git a/bench/random.go b/bench/random.go index 8e92cdbea..697395918 100644 --- a/bench/random.go +++ b/bench/random.go @@ -7,13 +7,12 @@ import ( "io/ioutil" "context" - "github.com/umbel/pilosa" "math/rand" ) // RandomSetBits sets bits randomly and deterministically based on a seed. type RandomSetBits struct { - cli *pilosa.Client + HasClient BaseBitmapID int64 BaseProfileID int64 BitmapIDRange int64 @@ -52,6 +51,9 @@ The following arguments are available: -DB string pilosa db to use + + -ClientType string + Can be 'single' (all agents hitting one host) or 'round_robin' `[1:] } @@ -65,6 +67,7 @@ func (b *RandomSetBits) ConsumeFlags(args []string) ([]string, error) { fs.Int64Var(&b.Seed, "Seed", 1, "") fs.IntVar(&b.Iterations, "Iterations", 100, "") fs.StringVar(&b.DB, "DB", "benchdb", "") + fs.StringVar(&b.ClientType, "ClientType", "single", "") if err := fs.Parse(args); err != nil { return nil, err @@ -72,18 +75,6 @@ func (b *RandomSetBits) ConsumeFlags(args []string) ([]string, error) { return fs.Args(), nil } -// Init connects to pilosa and sets the client on b. -func (b *RandomSetBits) Init(hosts []string, agentNum int) (err error) { - b.cli, err = pilosa.NewClient(hosts[0]) - if err != nil { - return err - } - if b.DB == "" { - b.DB = "RandomSetBits" - } - return nil -} - // Run runs the RandomSetBits benchmark func (b *RandomSetBits) Run(agentNum int) map[string]interface{} { src := rand.NewSource(b.Seed + int64(agentNum)) diff --git a/cmd/pilosactl/multidbspawn.json b/cmd/pilosactl/multidbspawn.json index 338e35d4c..b3b58fc38 100644 --- a/cmd/pilosactl/multidbspawn.json +++ b/cmd/pilosactl/multidbspawn.json @@ -3,8 +3,8 @@ "Agents": { "Type": "local" }, "Benchmarks": [ { - "Num": 4, - "Args": ["MultiDBSetBits", "-Iterations", "100000"] + "Num": 3, + "Args": ["MultiDBSetBits", "-Iterations", "100000", "-ClientType", "round_robin"] } ] } diff --git a/cmd/pilosactl/randspawn.json b/cmd/pilosactl/randspawn.json index 67b34e14f..a0956d38d 100644 --- a/cmd/pilosactl/randspawn.json +++ b/cmd/pilosactl/randspawn.json @@ -3,8 +3,8 @@ "Agents": { "Type": "local" }, "Benchmarks": [ { - "Num": 1, - "Args": ["RandomSetBits", "-Iterations", "10000", "-ProfileIDRange", "1000000", "-BitmapIDRange", "1000000", "-Seed", "2345"] + "Num": 3, + "Args": ["RandomSetBits", "-Iterations", "10000", "-ProfileIDRange", "1000000", "-BitmapIDRange", "1000000", "-Seed", "2345", "-ClientType", "round_robin"] } ] } diff --git a/cmd/pilosactl/spawn.json b/cmd/pilosactl/spawn.json index cd9078d90..942a4610e 100644 --- a/cmd/pilosactl/spawn.json +++ b/cmd/pilosactl/spawn.json @@ -3,8 +3,8 @@ "Agents": { "Type": "local" }, "Benchmarks": [ { - "Num": 1, - "Args": ["DiagonalSetBits", "-Iterations", "100000"] + "Num": 3, + "Args": ["DiagonalSetBits", "-Iterations", "100000", "-ClientType", "round_robin"] } ] }