remove some leftovers from benchmark removal

This commit is contained in:
Matt Jaffee 2017-02-24 16:13:46 -06:00
parent 33d2ecf6b7
commit bcff80abad
2 changed files with 0 additions and 316 deletions

View file

@ -1,197 +0,0 @@
package bench
import (
"math/rand"
"github.com/pilosa/pilosa/pql"
)
// NewQueryGenerator initializes a new QueryGenerator
func NewQueryGenerator(seed int64) *QueryGenerator {
return &QueryGenerator{
IDToFrameFn: func(id uint64) string { return "frame.n" },
R: rand.New(rand.NewSource(seed)),
Frames: []string{"frame.n"},
}
}
// QueryGenerator holds the configuration and state for randomly generating
// queries.
type QueryGenerator struct {
IDToFrameFn func(id uint64) string
R *rand.Rand
Frames []string
}
// Random returns a randomly generated query.
func (q *QueryGenerator) 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:
return q.RandomTopN(maxN, depth, maxargs, idmin, idmax)
default:
return q.RandomBitmapCall(depth, maxargs, idmin, idmax)
}
}
// RandomTopN returns a randomly generated TopN query.
func (q *QueryGenerator) RandomTopN(maxN, depth, maxargs int, idmin, idmax uint64) *pql.Call {
frameIdx := q.R.Intn(len(q.Frames))
return &pql.Call{
Args: map[string]interface{}{
"frame": q.Frames[frameIdx],
"n": uint64(q.R.Intn(maxN-1) + 1),
},
Children: []*pql.Call{q.RandomBitmapCall(depth, maxargs, idmin, idmax)},
}
}
// RandomBitmapCall returns a randomly generate query which returns a bitmap.
func (q *QueryGenerator) RandomBitmapCall(depth, maxargs int, idmin, idmax uint64) *pql.Call {
if depth <= 1 {
bitmapID := q.R.Int63n(int64(idmax)-int64(idmin)) + int64(idmin)
return Bitmap(uint64(bitmapID), q.IDToFrameFn(uint64(bitmapID)))
}
call := q.R.Intn(4)
if call == 0 {
return q.RandomBitmapCall(1, 0, idmin, idmax)
}
var numargs int
if maxargs <= 2 {
numargs = 2
} else {
numargs = q.R.Intn(maxargs-2) + 2
}
calls := make([]*pql.Call, numargs)
for i := 0; i < numargs; i++ {
calls[i] = q.RandomBitmapCall(depth-1, maxargs, idmin, idmax)
}
switch call {
case 1:
return Difference(calls...)
case 2:
return Intersect(calls...)
case 3:
return Union(calls...)
}
return nil
}
///////////////////////////////////////////////////
// Helpers TODO: move elsewhere
///////////////////////////////////////////////////
func ClearBit(id uint64, frame string, profileID uint64) *pql.Call {
return &pql.Call{
Name: "ClearBit",
Args: map[string]interface{}{
"id": id,
"frame": frame,
"profileID": profileID,
},
}
}
func Count(child *pql.Call) *pql.Call {
return &pql.Call{
Name: "Count",
Children: []*pql.Call{child},
}
}
func Profile(id uint64) *pql.Call {
return &pql.Call{
Name: "Profile",
Args: map[string]interface{}{"id": id},
}
}
func SetBit(id uint64, frame string, profileID uint64) *pql.Call {
return &pql.Call{
Name: "SetBit",
Args: map[string]interface{}{
"id": id,
"frame": frame,
"profileID": profileID,
},
}
}
func SetBitmapAttrs(id uint64, frame string, attrs map[string]interface{}) *pql.Call {
args := copyArgs(attrs)
args["id"] = id
args["profileID"] = frame
return &pql.Call{
Name: "SetBitmapAttrs",
Args: args,
}
}
func SetProfileAttrs(id uint64, attrs map[string]interface{}) *pql.Call {
args := copyArgs(attrs)
args["id"] = id
return &pql.Call{
Name: "SetProfileAttrs",
Args: args,
}
}
func TopN(frame string, n int, src *pql.Call, bmids []uint64, field string, filters []interface{}) *pql.Call {
return &pql.Call{
Name: "TopN",
Children: []*pql.Call{src},
Args: map[string]interface{}{
"frame": frame,
"n": n,
"ids": bmids,
"field": field,
"filters": filters,
},
}
}
func Difference(bms ...*pql.Call) *pql.Call {
// TODO does this need to be limited to two inputs?
return &pql.Call{
Name: "Difference",
Children: bms,
}
}
func Intersect(bms ...*pql.Call) *pql.Call {
return &pql.Call{
Name: "Intersect",
Children: bms,
}
}
func Union(bms ...*pql.Call) *pql.Call {
return &pql.Call{
Name: "Union",
Children: bms,
}
}
func Bitmap(id uint64, frame string) *pql.Call {
return &pql.Call{
Name: "Bitmap",
Args: map[string]interface{}{
"id": id,
"frame": frame,
},
}
}
// copyArgs returns a shallow copy of m.
func copyArgs(m map[string]interface{}) map[string]interface{} {
other := make(map[string]interface{}, len(m))
for k, v := range m {
other[k] = v
}
return other
}

View file

@ -1,119 +0,0 @@
package bench
import (
"context"
"flag"
"fmt"
"io/ioutil"
"strings"
"time"
)
// RandomQuery queries randomly and deterministically based on a seed.
type RandomQuery 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 *RandomQuery) Init(hosts []string, agentNum int) error {
b.Name = "random-query"
b.Seed = b.Seed + int64(agentNum)
return b.HasClient.Init(hosts, agentNum)
}
// Usage returns the usage message to be printed.
func (b *RandomQuery) Usage() string {
return `
random-query constructs random queries
Agent number modifies the random seed.
Usage: random-query [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'
-content-type string
protobuf or pql
`[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 *RandomQuery) ConsumeFlags(args []string) ([]string, error) {
fs := flag.NewFlagSet("RandomQuery", 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", "")
fs.StringVar(&b.ContentType, "content-type", "protobuf", "")
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(ctx context.Context) map[string]interface{} {
results := make(map[string]interface{})
if b.client == nil {
results["error"] = fmt.Errorf("No client set for RandomQuery")
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()
b.ExecuteQuery(b.ContentType, b.DBs[n%len(b.DBs)], call.String(), ctx)
s.Add(time.Now().Sub(start))
}
AddToResults(s, results)
return results
}