diff --git a/bench/query.go b/bench/query.go index 69e375c47..d08fe4d75 100644 --- a/bench/query.go +++ b/bench/query.go @@ -20,6 +20,7 @@ type QueryMaker struct { } func (q *QueryMaker) Random(maxN, depth, maxargs int, idmin, idmax uint64) pql.Call { + // TODO: handle depth==1 or 0 val := q.R.Intn(5) switch val { case 0: diff --git a/bench/randquery.go b/bench/randquery.go new file mode 100644 index 000000000..3723cffdd --- /dev/null +++ b/bench/randquery.go @@ -0,0 +1,103 @@ +package bench + +import ( + "context" + "flag" + "fmt" + "io/ioutil" + "strings" + "time" +) + +// RandomQuery sets bits randomly and deterministically based on a seed. +type RandomQuery struct { + HasClient + MaxDepth int + MaxArgs int + MaxN int + BaseBitmapID int64 + BitmapIDRange int64 + Iterations int // number of queries + Seed int64 + DBs []string // DBs to query. + +} + +func (b *RandomQuery) Usage() string { + return ` +RandomQuery constructs random queries + +Usage: RandomQuery [arguments] + +The following arguments are available: + + -MaxDepth int + Maximum nesting depth of queries + + -MaxArgs int + Maximum number of args for Union/Intersect/Difference Queries + + -MaxN int + Maximum N value for TopN queries. + + -BaseBitmapID int + bitmap id to start from + + -BitmapIDRange 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 + + -ClientType string + Can be 'single' (all agents hitting one host) or 'round_robin' +`[1:] +} + +func (b *RandomQuery) ConsumeFlags(args []string) ([]string, error) { + fs := flag.NewFlagSet("RandomQuery", flag.ContinueOnError) + fs.SetOutput(ioutil.Discard) + fs.IntVar(&b.MaxDepth, "MaxDepth", 4, "") + fs.IntVar(&b.MaxArgs, "MaxArgs", 4, "") + fs.IntVar(&b.MaxN, "MaxN", 4, "") + fs.Int64Var(&b.BaseBitmapID, "BaseBitmapID", 0, "") + fs.Int64Var(&b.BitmapIDRange, "BitmapIDRange", 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, "ClientType", "single", "") + + if err := fs.Parse(args); err != nil { + return nil, err + } + b.DBs = strings.Split(dbs, ",") + return fs.Args(), nil +} + +// Run runs the RandomQuery benchmark +func (b *RandomQuery) Run(agentNum int) map[string]interface{} { + seed := b.Seed + int64(agentNum) + results := make(map[string]interface{}) + if b.cli == nil { + results["error"] = fmt.Errorf("No client set for RandomQuery agent: %v", agentNum) + return results + } + qm := NewQueryMaker(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() + b.cli.ExecuteQuery(context.TODO(), b.DBs[n%len(b.DBs)], call.String(), true) + s.Add(time.Now().Sub(start)) + } + AddToResults(s, results) + return results +} diff --git a/cmd/pilosactl/main.go b/cmd/pilosactl/main.go index c302262c2..4ab54eb1c 100644 --- a/cmd/pilosactl/main.go +++ b/cmd/pilosactl/main.go @@ -1335,6 +1335,8 @@ func (cmd *BagentCommand) ParseFlags(args []string) error { bm = &bench.RandomSetBits{} case "MultiDBSetBits": bm = &bench.MultiDBSetBits{} + case "RandomQuery": + bm = &bench.RandomQuery{} default: return fmt.Errorf("Unknown benchmark cmd: %v", remArgs[0]) } @@ -1374,6 +1376,8 @@ The following arguments are available: DiagonalSetBits RandomSetBits MultiDBSetBits + RandomQuery + `) diff --git a/cmd/pilosactl/randSetAndQuery.json b/cmd/pilosactl/randSetAndQuery.json new file mode 100644 index 000000000..091d2a2c9 --- /dev/null +++ b/cmd/pilosactl/randSetAndQuery.json @@ -0,0 +1,13 @@ +{ + "CreatorArgs": ["-type", "local", "-serverN", "3", "-replicaN", "1"], + "Agents": { "Type": "local" }, + "Benchmarks": [ + { + "Num": 3, + "Args": [ + "RandomSetBits", "-Iterations", "30000", "-ProfileIDRange", "1000000", "-BitmapIDRange", "1000000", "-Seed", "2345", "-ClientType", "round_robin", "-DB", "randsetandquery", + "RandomQuery", "-Iterations", "1000", "-BitmapIDRange", "1000000", "-Seed", "1239", "-DBs", "randsetandquery" + ] + } + ] +}