add pql option to randquery

This commit is contained in:
Linh Vo 2017-01-25 00:14:20 -06:00
parent 9b9fc8aa11
commit 70222f2a8b
4 changed files with 37 additions and 125 deletions

View file

@ -19,11 +19,13 @@ func roundRobinClient(hosts []string, agentNum int) (*pilosa.Client, error) {
return firstHostClient(hosts[clientNum:])
}
// HasClient provides a reusable component for Benchmark implementations which
// provides the Init method, a ClientType argument and a cli internal variable.
type HasClient struct {
client *pilosa.Client
ClientType string `json:"client-type"`
client *pilosa.Client
ClientType string `json:"client-type"`
ContentType string `json:"content-type"`
}
// Init for HasClient looks at the ClientType field and creates a pilosa client
@ -34,11 +36,24 @@ func (h *HasClient) Init(hosts []string, agentNum int) error {
switch h.ClientType {
case "single":
h.client, err = firstHostClient(hosts)
return err
case "round_robin":
h.client, err = roundRobinClient(hosts, agentNum)
return err
default:
return fmt.Errorf("Unsupported ClientType: %v", h.ClientType)
err = fmt.Errorf("Unsupported ClientType: %v", h.ClientType)
}
if err != nil {
return err
}
switch h.ContentType {
case "protobuf":
return nil
case "pql":
return nil
default:
return fmt.Errorf("Unsupported ContentType: %v", h.ContentType)
}
}

View file

@ -1,117 +0,0 @@
package bench
import (
"context"
"flag"
"fmt"
"io/ioutil"
"strings"
"time"
)
// RandomQuery queries randomly and deterministically based on a seed.
type RandomPql struct {
HasClient
Name string `json:"name"`
MaxDepth int `json:"max-depth"`
MaxArgs int `json:"max-args"`
MaxN int `json:"max-n"`
BaseBitmapID int64 `json:"base-bitmap-id"`
BitmapIDRange int64 `json:"bitmap-id-range"`
Iterations int `json:"iterations"`
Seed int64 `json:"seed"`
DBs []string `json:"dbs"`
}
// Init adds the agent num to the random seed and initializes the client.
func (b *RandomPql) Init(hosts []string, agentNum int) error {
b.Name = "random-pql"
b.Seed = b.Seed + int64(agentNum)
return b.HasClient.Init(hosts, agentNum)
}
// Usage returns the usage message to be printed.
func (b *RandomPql) Usage() string {
return `
random-pql compare random queries between protobuf and pql
Agent number modifies the random seed.
Usage: random-pql[arguments]
The following arguments are available:
-max-depth int
Maximum nesting depth of queries
-max-args int
Maximum number of args for Union/Intersect/Difference Queries
-max-n int
Maximum N value for TopN queries.
-base-bitmap-id int
bitmap id to start from
-bitmap-id-range int
number of possible bitmap ids that can be set
-iterations int
number of bits to set
-seed int
Seed for RNG
-dbs string
Comma separated list of DBs to query against
-client-type string
Can be 'single' (all agents hitting one host) or 'round_robin'
`[1:]
}
// ConsumeFlags parses all flags up to the next non flag argument (argument does
// not start with "-" and isn't the value of a flag). It returns the remaining
// args.
func (b *RandomPql) ConsumeFlags(args []string) ([]string, error) {
fs := flag.NewFlagSet("RandomPql", flag.ContinueOnError)
fs.SetOutput(ioutil.Discard)
fs.IntVar(&b.MaxDepth, "max-depth", 4, "")
fs.IntVar(&b.MaxArgs, "max-args", 4, "")
fs.IntVar(&b.MaxN, "max-n", 4, "")
fs.Int64Var(&b.BaseBitmapID, "base-bitmap-id", 0, "")
fs.Int64Var(&b.BitmapIDRange, "bitmap-id-range", 100000, "")
fs.Int64Var(&b.Seed, "seed", 1, "")
fs.IntVar(&b.Iterations, "iterations", 100, "")
var dbs string
fs.StringVar(&dbs, "dbs", "benchdb", "")
fs.StringVar(&b.ClientType, "client-type", "single", "")
if err := fs.Parse(args); err != nil {
return nil, err
}
b.DBs = strings.Split(dbs, ",")
return fs.Args(), nil
}
// Run runs the RandomPQL benchmark
func (b *RandomPql) Run(ctx context.Context) map[string]interface{} {
results := make(map[string]interface{})
if b.client == nil {
results["error"] = fmt.Errorf("No client set")
return results
}
qm := NewQueryGenerator(b.Seed)
s := NewStats()
var start time.Time
for n := 0; n < b.Iterations; n++ {
call := qm.Random(b.MaxN, b.MaxDepth, b.MaxArgs, uint64(b.BaseBitmapID), uint64(b.BitmapIDRange))
start = time.Now()
queryString := call.String()
b.client.ExecutePql(ctx, b.DBs[n%len(b.DBs)], queryString)
s.Add(time.Now().Sub(start))
}
AddToResults(s, results)
return results
}

View file

@ -7,6 +7,7 @@ import (
"io/ioutil"
"strings"
"time"
"errors"
)
// RandomQuery queries randomly and deterministically based on a seed.
@ -67,6 +68,9 @@ The following arguments are available:
-client-type string
Can be 'single' (all agents hitting one host) or 'round_robin'
-content-type string
protobuf or pql
`[1:]
}
@ -86,6 +90,7 @@ func (b *RandomQuery) ConsumeFlags(args []string) ([]string, error) {
var dbs string
fs.StringVar(&dbs, "dbs", "benchdb", "")
fs.StringVar(&b.ClientType, "client-type", "single", "")
fs.StringVar(&b.ContentType, "content-type", "protobuf", "")
if err := fs.Parse(args); err != nil {
return nil, err
@ -107,9 +112,20 @@ func (b *RandomQuery) Run(ctx context.Context) map[string]interface{} {
for n := 0; n < b.Iterations; n++ {
call := qm.Random(b.MaxN, b.MaxDepth, b.MaxArgs, uint64(b.BaseBitmapID), uint64(b.BitmapIDRange))
start = time.Now()
b.client.ExecuteQuery(ctx, b.DBs[n%len(b.DBs)], call.String(), true)
b.ExecuteQuery(b.ContentType, b.DBs[n % len(b.DBs)], call.String(), ctx)
s.Add(time.Now().Sub(start))
}
AddToResults(s, results)
return results
}
func (b *RandomQuery) ExecuteQuery(contentType, db, query string, ctx context.Context, ) (interface{}, error) {
if contentType == "protobuf" {
return b.client.ExecuteQuery(ctx, db, query, true)
} else if contentType == "pql" {
fmt.Println("HERRR")
return b.client.ExecutePql(ctx, db, query)
} else {
return nil, errors.New("unsupport content type")
}
}

View file

@ -1248,8 +1248,6 @@ func (cmd *BagentCommand) ParseFlags(args []string) error {
bm = bench.NewImport(cmd.Stdin, cmd.Stdout, cmd.Stderr)
case "slice-height":
bm = bench.NewSliceHeight(cmd.Stdin, cmd.Stdout, cmd.Stderr)
case "random-pql":
bm = &bench.RandomPql{}
default:
return fmt.Errorf("Unknown benchmark cmd: %v", remArgs[0])
}