mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-06 16:45:55 +00:00
refactor Init and provide ClientType option
Benchmark implementations can now use 'HasClient' as a component which provides an Init method which sets up the pilosa client in a configurable way. Implementations must still expose the ClientType argument through ConsumeFlags and describe it in Usage()
This commit is contained in:
parent
2f4171bba8
commit
65ac486b4c
7 changed files with 65 additions and 45 deletions
43
bench/client.go
Normal file
43
bench/client.go
Normal file
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
@ -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{})
|
||||
|
|
|
|||
|
|
@ -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{})
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
"Agents": { "Type": "local" },
|
||||
"Benchmarks": [
|
||||
{
|
||||
"Num": 4,
|
||||
"Args": ["MultiDBSetBits", "-Iterations", "100000"]
|
||||
"Num": 3,
|
||||
"Args": ["MultiDBSetBits", "-Iterations", "100000", "-ClientType", "round_robin"]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
"Agents": { "Type": "local" },
|
||||
"Benchmarks": [
|
||||
{
|
||||
"Num": 1,
|
||||
"Args": ["DiagonalSetBits", "-Iterations", "100000"]
|
||||
"Num": 3,
|
||||
"Args": ["DiagonalSetBits", "-Iterations", "100000", "-ClientType", "round_robin"]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue