featurebase/bench/multidb.go
jaffee 65ac486b4c 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()
2016-11-28 15:45:17 -07:00

70 lines
1.7 KiB
Go

package bench
import (
"fmt"
"strconv"
"flag"
"io/ioutil"
"context"
)
// MultiDBSetBits sets bits with increasing profile id and bitmap id.
type MultiDBSetBits struct {
HasClient
BaseBitmapID int
BaseProfileID int
Iterations int
}
func (b *MultiDBSetBits) Usage() string {
return `
MultiDBSetBits sets bits with increasing profile id and bitmap id using a different DB for each agent.
Usage: MultiDBSetBits [arguments]
The following arguments are available:
-BaseBitmapID int
bits being set will all be greater than BaseBitmapID
-BaseProfileID int
profile id num to start from
-Iterations int
number of bits to set
-ClientType string
Can be 'single' (all agents hitting one host) or 'round_robin'
`[1:]
}
func (b *MultiDBSetBits) ConsumeFlags(args []string) ([]string, error) {
fs := flag.NewFlagSet("MultiDBSetBits", flag.ContinueOnError)
fs.SetOutput(ioutil.Discard)
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
}
return fs.Args(), nil
}
// Run runs the MultiDBSetBits benchmark
func (b *MultiDBSetBits) Run(agentNum int) map[string]interface{} {
results := make(map[string]interface{})
if b.cli == nil {
results["error"] = fmt.Errorf("No client set for MultiDBSetBits agent: %v", agentNum)
return results
}
for n := 0; n < b.Iterations; n++ {
query := fmt.Sprintf("SetBit(%d, 'frame.n', %d)", b.BaseBitmapID+n, b.BaseProfileID+n)
b.cli.ExecuteQuery(context.TODO(), "multidb"+strconv.Itoa(agentNum), query, true)
}
return results
}