add slice height benchmark

This commit is contained in:
jaffee 2016-12-06 17:20:38 -06:00
parent af1d35affc
commit b4bb9cf70d
6 changed files with 143 additions and 3 deletions

View file

@ -1,8 +1,9 @@
package bench
import (
"github.com/pilosa/pilosa/pql"
"math/rand"
"github.com/pilosa/pilosa/pql"
)
func NewQueryGenerator(seed int64) *QueryGenerator {

View file

@ -9,7 +9,7 @@ import (
"time"
)
// RandomQuery sets bits randomly and deterministically based on a seed.
// RandomQuery queries randomly and deterministically based on a seed.
type RandomQuery struct {
HasClient
MaxDepth int

126
bench/sliceheight.go Normal file
View file

@ -0,0 +1,126 @@
package bench
import (
"context"
"flag"
"io"
"io/ioutil"
"strconv"
"time"
"github.com/pilosa/pilosa"
"github.com/pilosa/pilosa/pql"
)
func NewSliceHeight(stdin io.Reader, stdout, stderr io.Writer) *SliceHeight {
return &SliceHeight{
Stdin: stdin,
Stdout: stdout,
Stderr: stderr,
}
}
// SliceHeight benchmark tests the effect of an increasing number of bitmaps in
// a single slice on query time.
type SliceHeight struct {
MaxTime time.Duration
hosts []string
MinBitsPerMap int64
MaxBitsPerMap int64
Seed int64
Database string
Frame string
Stdin io.Reader
Stdout io.Writer
Stderr io.Writer
}
func (b *SliceHeight) Usage() string {
return `
slice-height repeatedly imports more bitmaps into a single slice and tests query times in between.
Usage: slice-height [arguments]
The following arguments are available:
-max-time int
stop benchmark after this many seconds
-min-bits-per-map int
minimum number of bits set per bitmap
-max-bits-per-map int
maximum number of bits set per bitmap
-seed int
seed for RNG
-db string
pilosa db to use
-frame string
frame to import into
`[1:]
}
func (b *SliceHeight) ConsumeFlags(args []string) ([]string, error) {
fs := flag.NewFlagSet("SliceHeight", flag.ContinueOnError)
fs.SetOutput(ioutil.Discard)
maxTime := fs.Int("max-time", 30, "")
fs.Int64Var(&b.MinBitsPerMap, "min-bits-per-map", 0, "")
fs.Int64Var(&b.MaxBitsPerMap, "max-bits-per-map", 10, "")
fs.Int64Var(&b.Seed, "seed", 0, "")
fs.StringVar(&b.Database, "db", "benchdb", "")
fs.StringVar(&b.Frame, "frame", "testframe", "")
if err := fs.Parse(args); err != nil {
return nil, err
}
b.MaxTime = time.Duration(*maxTime) * time.Second
return fs.Args(), nil
}
func (b *SliceHeight) Init(hosts []string, agentNum int) error {
b.hosts = hosts
return nil
}
// Run runs the SliceHeight benchmark
func (b *SliceHeight) Run(agentNum int) map[string]interface{} {
results := make(map[string]interface{})
imp := NewImport(b.Stdin, b.Stdout, b.Stderr)
imp.MaxBitmapID = 100
imp.MaxProfileID = pilosa.SliceWidth
imp.MinBitsPerMap = b.MinBitsPerMap
imp.MaxBitsPerMap = b.MaxBitsPerMap
imp.Database = b.Database
imp.Frame = b.Frame
start := time.Now()
for i := 0; i > -1; i++ {
imp.Init(b.hosts, agentNum)
results["import"+strconv.Itoa(i)] = imp.Run(agentNum)
qt := time.Now()
q := &pql.TopN{Frame: b.Frame, N: 50}
_, err := imp.Client.ExecuteQuery(context.TODO(), b.Database, q.String(), true)
if err != nil {
results["query"+strconv.Itoa(i)+"error"] = err.Error()
} else {
qdur := time.Now().Sub(qt)
results["query"+strconv.Itoa(i)] = qdur
}
imp.BaseBitmapID = imp.MaxBitmapID
imp.MaxBitmapID = imp.MaxBitmapID * 10
if time.Now().Sub(start) > b.MaxTime {
break
}
}
return results
}

View file

@ -191,7 +191,7 @@ func (c *Client) ExecuteQuery(ctx context.Context, db, query string, allowRedire
return nil, errors.New(s)
}
return nil, nil
return qresp, nil
}
// Import bulk imports bits for a single slice to a host.

View file

@ -1167,6 +1167,8 @@ func (cmd *BagentCommand) ParseFlags(args []string) error {
bm = &bench.RandomQuery{}
case "import":
bm = bench.NewImport(cmd.Stdin, cmd.Stdout, cmd.Stderr)
case "slice-height":
bm = bench.NewSliceHeight(cmd.Stdin, cmd.Stdout, cmd.Stderr)
default:
return fmt.Errorf("Unknown benchmark cmd: %v", remArgs[0])
}
@ -1208,6 +1210,7 @@ The following arguments are available:
multi-db-set-bits
random-query
import
slice-height
`)
}

View file

@ -0,0 +1,10 @@
{
"CreatorArgs": ["-type", "local", "-serverN", "1", "-replicaN", "1"],
"Agents": { "Type": "local" },
"Benchmarks": [
{
"Num": 1,
"Args": ["slice-height", "-max-time", "10", "-max-bits-per-map", "100"]
}
]
}