mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
add random query benchmark
This commit is contained in:
parent
6beef90a82
commit
c8b0fecd4a
4 changed files with 121 additions and 0 deletions
|
|
@ -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:
|
||||
|
|
|
|||
103
bench/randquery.go
Normal file
103
bench/randquery.go
Normal file
|
|
@ -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
|
||||
}
|
||||
|
|
@ -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
|
||||
|
||||
|
||||
|
||||
`)
|
||||
|
|
|
|||
13
cmd/pilosactl/randSetAndQuery.json
Normal file
13
cmd/pilosactl/randSetAndQuery.json
Normal file
|
|
@ -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"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue