mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-09 06:31:02 +00:00
split benchmarks into separate files
This commit is contained in:
parent
256d516726
commit
0dc8548f45
4 changed files with 263 additions and 237 deletions
238
bench/bench.go
238
bench/bench.go
|
|
@ -2,18 +2,9 @@ package bench
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"strconv"
|
||||
|
||||
"flag"
|
||||
"io/ioutil"
|
||||
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"context"
|
||||
"github.com/umbel/pilosa"
|
||||
"math/rand"
|
||||
)
|
||||
|
||||
// Benchmark is an interface to guide the creation of new pilosa benchmarks or
|
||||
|
|
@ -45,233 +36,6 @@ type Command interface {
|
|||
Usage() string
|
||||
}
|
||||
|
||||
// DiagonalSetBits sets bits with increasing profile id and bitmap id.
|
||||
type DiagonalSetBits struct {
|
||||
cli *pilosa.Client
|
||||
BaseBitmapID int
|
||||
BaseProfileID int
|
||||
Iterations int
|
||||
DB string
|
||||
}
|
||||
|
||||
func (b *DiagonalSetBits) Usage() string {
|
||||
return `
|
||||
DiagonalSetBits sets bits with increasing profile id and bitmap id.
|
||||
|
||||
Usage: DiagonalSetBits [arguments]
|
||||
|
||||
The following arguments are available:
|
||||
|
||||
-BaseBitmapID int
|
||||
bits being set will all be greater than BaseBitmapID
|
||||
|
||||
-BaseProfileID int
|
||||
profile id num to start from
|
||||
|
||||
-Iterations int
|
||||
number of bits to set
|
||||
|
||||
-DB string
|
||||
pilosa db to use
|
||||
`[1:]
|
||||
}
|
||||
|
||||
func (b *DiagonalSetBits) ConsumeFlags(args []string) ([]string, error) {
|
||||
fs := flag.NewFlagSet("DiagonalSetBits", flag.ContinueOnError)
|
||||
fs.SetOutput(ioutil.Discard)
|
||||
fs.IntVar(&b.BaseBitmapID, "BaseBitmapID", 0, "")
|
||||
fs.IntVar(&b.BaseProfileID, "BaseProfileID", 0, "")
|
||||
fs.IntVar(&b.Iterations, "Iterations", 100, "")
|
||||
fs.StringVar(&b.DB, "DB", "benchdb", "")
|
||||
|
||||
if err := fs.Parse(args); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return fs.Args(), nil
|
||||
}
|
||||
|
||||
// Init connects to pilosa and sets the client on b.
|
||||
func (b *DiagonalSetBits) Init(hosts []string) (err error) {
|
||||
b.cli, err = pilosa.NewClient(hosts[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if b.DB == "" {
|
||||
b.DB = "DiagonalSetBits"
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Run runs the DiagonalSetBits benchmark
|
||||
func (b *DiagonalSetBits) Run(agentNum int) map[string]interface{} {
|
||||
results := make(map[string]interface{})
|
||||
if b.cli == nil {
|
||||
results["error"] = fmt.Errorf("No client set for DiagonalSetBits agent: %v", agentNum)
|
||||
return results
|
||||
}
|
||||
for n := 0; n < b.Iterations; n++ {
|
||||
iterID := agentizeNum(n, b.Iterations, agentNum)
|
||||
query := fmt.Sprintf("SetBit(%d, 'frame.n', %d)", b.BaseBitmapID+iterID, b.BaseProfileID+iterID)
|
||||
b.cli.ExecuteQuery(context.TODO(), b.DB, query, true)
|
||||
}
|
||||
return results
|
||||
}
|
||||
|
||||
// MultiDBSetBits sets bits with increasing profile id and bitmap id.
|
||||
type MultiDBSetBits struct {
|
||||
cli *pilosa.Client
|
||||
BaseBitmapID int
|
||||
BaseProfileID int
|
||||
Iterations int
|
||||
}
|
||||
|
||||
func (b *MultiDBSetBits) Usage() string {
|
||||
return `
|
||||
MultiDBSetBits sets bits with increasing profile id and bitmap id using a different DB for each agent.
|
||||
|
||||
Usage: MultiDBSetBits [arguments]
|
||||
|
||||
The following arguments are available:
|
||||
|
||||
-BaseBitmapID int
|
||||
bits being set will all be greater than BaseBitmapID
|
||||
|
||||
-BaseProfileID int
|
||||
profile id num to start from
|
||||
|
||||
-Iterations int
|
||||
number of bits to set
|
||||
|
||||
`[1:]
|
||||
}
|
||||
|
||||
func (b *MultiDBSetBits) ConsumeFlags(args []string) ([]string, error) {
|
||||
fs := flag.NewFlagSet("MultiDBSetBits", flag.ContinueOnError)
|
||||
fs.SetOutput(ioutil.Discard)
|
||||
fs.IntVar(&b.BaseBitmapID, "BaseBitmapID", 0, "")
|
||||
fs.IntVar(&b.BaseProfileID, "BaseProfileID", 0, "")
|
||||
fs.IntVar(&b.Iterations, "Iterations", 100, "")
|
||||
|
||||
if err := fs.Parse(args); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return fs.Args(), nil
|
||||
}
|
||||
|
||||
// Init connects to pilosa and sets the client on b.
|
||||
func (b *MultiDBSetBits) Init(hosts []string) (err error) {
|
||||
b.cli, err = pilosa.NewClient(hosts[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Run runs the MultiDBSetBits benchmark
|
||||
func (b *MultiDBSetBits) Run(agentNum int) map[string]interface{} {
|
||||
results := make(map[string]interface{})
|
||||
if b.cli == nil {
|
||||
results["error"] = fmt.Errorf("No client set for MultiDBSetBits agent: %v", agentNum)
|
||||
return results
|
||||
}
|
||||
for n := 0; n < b.Iterations; n++ {
|
||||
query := fmt.Sprintf("SetBit(%d, 'frame.n', %d)", b.BaseBitmapID+n, b.BaseProfileID+n)
|
||||
b.cli.ExecuteQuery(context.TODO(), "multidb"+strconv.Itoa(agentNum), query, true)
|
||||
}
|
||||
return results
|
||||
}
|
||||
|
||||
// RandomSetBits sets bits randomly and deterministically based on a seed.
|
||||
type RandomSetBits struct {
|
||||
cli *pilosa.Client
|
||||
BaseBitmapID int64
|
||||
BaseProfileID int64
|
||||
BitmapIDRange int64
|
||||
ProfileIDRange int64
|
||||
Iterations int // number of bits that will be set
|
||||
Seed int64
|
||||
DB string // DB to use in pilosa.
|
||||
|
||||
}
|
||||
|
||||
func (b *RandomSetBits) Usage() string {
|
||||
return `
|
||||
RandomSetBits sets random bits
|
||||
|
||||
Usage: RandomSetBits [arguments]
|
||||
|
||||
The following arguments are available:
|
||||
|
||||
-BaseBitmapID int
|
||||
bitmap id to start from
|
||||
|
||||
-BitmapIDRange int
|
||||
number of possible bitmap ids that can be set
|
||||
|
||||
-BaseProfileID int
|
||||
profile id num to start from
|
||||
|
||||
-ProfileIDRange int
|
||||
number of possible profile ids that can be set
|
||||
|
||||
-Iterations int
|
||||
number of bits to set
|
||||
|
||||
-Seed int
|
||||
Seed for RNG
|
||||
|
||||
-DB string
|
||||
pilosa db to use
|
||||
`[1:]
|
||||
}
|
||||
|
||||
func (b *RandomSetBits) ConsumeFlags(args []string) ([]string, error) {
|
||||
fs := flag.NewFlagSet("RandomSetBits", flag.ContinueOnError)
|
||||
fs.SetOutput(ioutil.Discard)
|
||||
fs.Int64Var(&b.BaseBitmapID, "BaseBitmapID", 0, "")
|
||||
fs.Int64Var(&b.BitmapIDRange, "BitmapIDRange", 100000, "")
|
||||
fs.Int64Var(&b.BaseProfileID, "BaseProfileID", 0, "")
|
||||
fs.Int64Var(&b.ProfileIDRange, "ProfileIDRange", 100000, "")
|
||||
fs.Int64Var(&b.Seed, "Seed", 1, "")
|
||||
fs.IntVar(&b.Iterations, "Iterations", 100, "")
|
||||
fs.StringVar(&b.DB, "DB", "benchdb", "")
|
||||
|
||||
if err := fs.Parse(args); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return fs.Args(), nil
|
||||
}
|
||||
|
||||
// Init connects to pilosa and sets the client on b.
|
||||
func (b *RandomSetBits) Init(hosts []string) (err error) {
|
||||
b.cli, err = pilosa.NewClient(hosts[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if b.DB == "" {
|
||||
b.DB = "RandomSetBits"
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Run runs the RandomSetBits benchmark
|
||||
func (b *RandomSetBits) Run(agentNum int) map[string]interface{} {
|
||||
src := rand.NewSource(b.Seed + int64(agentNum))
|
||||
rng := rand.New(src)
|
||||
results := make(map[string]interface{})
|
||||
if b.cli == nil {
|
||||
results["error"] = fmt.Errorf("No client set for RandomSetBits agent: %v", agentNum)
|
||||
return results
|
||||
}
|
||||
for n := 0; n < b.Iterations; n++ {
|
||||
bitmapID := rng.Int63n(b.BitmapIDRange)
|
||||
profID := rng.Int63n(b.ProfileIDRange)
|
||||
query := fmt.Sprintf("SetBit(%d, 'frame.n', %d)", b.BaseBitmapID+bitmapID, b.BaseProfileID+profID)
|
||||
b.cli.ExecuteQuery(context.TODO(), b.DB, query, true)
|
||||
}
|
||||
return results
|
||||
}
|
||||
|
||||
// agentizeNum is a helper which combines the loop iteration (n) with the total
|
||||
// number of iterations and the agentNum in order to produce a globally unique
|
||||
// number across all loop iterations on all agents.
|
||||
|
|
|
|||
83
bench/diagonal.go
Normal file
83
bench/diagonal.go
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
package bench
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"flag"
|
||||
"io/ioutil"
|
||||
|
||||
"context"
|
||||
"github.com/umbel/pilosa"
|
||||
)
|
||||
|
||||
// DiagonalSetBits sets bits with increasing profile id and bitmap id.
|
||||
type DiagonalSetBits struct {
|
||||
cli *pilosa.Client
|
||||
BaseBitmapID int
|
||||
BaseProfileID int
|
||||
Iterations int
|
||||
DB string
|
||||
}
|
||||
|
||||
func (b *DiagonalSetBits) Usage() string {
|
||||
return `
|
||||
DiagonalSetBits sets bits with increasing profile id and bitmap id.
|
||||
|
||||
Usage: DiagonalSetBits [arguments]
|
||||
|
||||
The following arguments are available:
|
||||
|
||||
-BaseBitmapID int
|
||||
bits being set will all be greater than BaseBitmapID
|
||||
|
||||
-BaseProfileID int
|
||||
profile id num to start from
|
||||
|
||||
-Iterations int
|
||||
number of bits to set
|
||||
|
||||
-DB string
|
||||
pilosa db to use
|
||||
`[1:]
|
||||
}
|
||||
|
||||
func (b *DiagonalSetBits) ConsumeFlags(args []string) ([]string, error) {
|
||||
fs := flag.NewFlagSet("DiagonalSetBits", flag.ContinueOnError)
|
||||
fs.SetOutput(ioutil.Discard)
|
||||
fs.IntVar(&b.BaseBitmapID, "BaseBitmapID", 0, "")
|
||||
fs.IntVar(&b.BaseProfileID, "BaseProfileID", 0, "")
|
||||
fs.IntVar(&b.Iterations, "Iterations", 100, "")
|
||||
fs.StringVar(&b.DB, "DB", "benchdb", "")
|
||||
|
||||
if err := fs.Parse(args); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return fs.Args(), nil
|
||||
}
|
||||
|
||||
// Init connects to pilosa and sets the client on b.
|
||||
func (b *DiagonalSetBits) Init(hosts []string) (err error) {
|
||||
b.cli, err = pilosa.NewClient(hosts[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if b.DB == "" {
|
||||
b.DB = "DiagonalSetBits"
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Run runs the DiagonalSetBits benchmark
|
||||
func (b *DiagonalSetBits) Run(agentNum int) map[string]interface{} {
|
||||
results := make(map[string]interface{})
|
||||
if b.cli == nil {
|
||||
results["error"] = fmt.Errorf("No client set for DiagonalSetBits agent: %v", agentNum)
|
||||
return results
|
||||
}
|
||||
for n := 0; n < b.Iterations; n++ {
|
||||
iterID := agentizeNum(n, b.Iterations, agentNum)
|
||||
query := fmt.Sprintf("SetBit(%d, 'frame.n', %d)", b.BaseBitmapID+iterID, b.BaseProfileID+iterID)
|
||||
b.cli.ExecuteQuery(context.TODO(), b.DB, query, true)
|
||||
}
|
||||
return results
|
||||
}
|
||||
76
bench/multidb.go
Normal file
76
bench/multidb.go
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
package bench
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"flag"
|
||||
"io/ioutil"
|
||||
|
||||
"context"
|
||||
"github.com/umbel/pilosa"
|
||||
)
|
||||
|
||||
// MultiDBSetBits sets bits with increasing profile id and bitmap id.
|
||||
type MultiDBSetBits struct {
|
||||
cli *pilosa.Client
|
||||
BaseBitmapID int
|
||||
BaseProfileID int
|
||||
Iterations int
|
||||
}
|
||||
|
||||
func (b *MultiDBSetBits) Usage() string {
|
||||
return `
|
||||
MultiDBSetBits sets bits with increasing profile id and bitmap id using a different DB for each agent.
|
||||
|
||||
Usage: MultiDBSetBits [arguments]
|
||||
|
||||
The following arguments are available:
|
||||
|
||||
-BaseBitmapID int
|
||||
bits being set will all be greater than BaseBitmapID
|
||||
|
||||
-BaseProfileID int
|
||||
profile id num to start from
|
||||
|
||||
-Iterations int
|
||||
number of bits to set
|
||||
|
||||
`[1:]
|
||||
}
|
||||
|
||||
func (b *MultiDBSetBits) ConsumeFlags(args []string) ([]string, error) {
|
||||
fs := flag.NewFlagSet("MultiDBSetBits", flag.ContinueOnError)
|
||||
fs.SetOutput(ioutil.Discard)
|
||||
fs.IntVar(&b.BaseBitmapID, "BaseBitmapID", 0, "")
|
||||
fs.IntVar(&b.BaseProfileID, "BaseProfileID", 0, "")
|
||||
fs.IntVar(&b.Iterations, "Iterations", 100, "")
|
||||
|
||||
if err := fs.Parse(args); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return fs.Args(), nil
|
||||
}
|
||||
|
||||
// Init connects to pilosa and sets the client on b.
|
||||
func (b *MultiDBSetBits) Init(hosts []string) (err error) {
|
||||
b.cli, err = pilosa.NewClient(hosts[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Run runs the MultiDBSetBits benchmark
|
||||
func (b *MultiDBSetBits) Run(agentNum int) map[string]interface{} {
|
||||
results := make(map[string]interface{})
|
||||
if b.cli == nil {
|
||||
results["error"] = fmt.Errorf("No client set for MultiDBSetBits agent: %v", agentNum)
|
||||
return results
|
||||
}
|
||||
for n := 0; n < b.Iterations; n++ {
|
||||
query := fmt.Sprintf("SetBit(%d, 'frame.n', %d)", b.BaseBitmapID+n, b.BaseProfileID+n)
|
||||
b.cli.ExecuteQuery(context.TODO(), "multidb"+strconv.Itoa(agentNum), query, true)
|
||||
}
|
||||
return results
|
||||
}
|
||||
103
bench/random.go
Normal file
103
bench/random.go
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
package bench
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"flag"
|
||||
"io/ioutil"
|
||||
|
||||
"context"
|
||||
"github.com/umbel/pilosa"
|
||||
"math/rand"
|
||||
)
|
||||
|
||||
// RandomSetBits sets bits randomly and deterministically based on a seed.
|
||||
type RandomSetBits struct {
|
||||
cli *pilosa.Client
|
||||
BaseBitmapID int64
|
||||
BaseProfileID int64
|
||||
BitmapIDRange int64
|
||||
ProfileIDRange int64
|
||||
Iterations int // number of bits that will be set
|
||||
Seed int64
|
||||
DB string // DB to use in pilosa.
|
||||
|
||||
}
|
||||
|
||||
func (b *RandomSetBits) Usage() string {
|
||||
return `
|
||||
RandomSetBits sets random bits
|
||||
|
||||
Usage: RandomSetBits [arguments]
|
||||
|
||||
The following arguments are available:
|
||||
|
||||
-BaseBitmapID int
|
||||
bitmap id to start from
|
||||
|
||||
-BitmapIDRange int
|
||||
number of possible bitmap ids that can be set
|
||||
|
||||
-BaseProfileID int
|
||||
profile id num to start from
|
||||
|
||||
-ProfileIDRange int
|
||||
number of possible profile ids that can be set
|
||||
|
||||
-Iterations int
|
||||
number of bits to set
|
||||
|
||||
-Seed int
|
||||
Seed for RNG
|
||||
|
||||
-DB string
|
||||
pilosa db to use
|
||||
`[1:]
|
||||
}
|
||||
|
||||
func (b *RandomSetBits) ConsumeFlags(args []string) ([]string, error) {
|
||||
fs := flag.NewFlagSet("RandomSetBits", flag.ContinueOnError)
|
||||
fs.SetOutput(ioutil.Discard)
|
||||
fs.Int64Var(&b.BaseBitmapID, "BaseBitmapID", 0, "")
|
||||
fs.Int64Var(&b.BitmapIDRange, "BitmapIDRange", 100000, "")
|
||||
fs.Int64Var(&b.BaseProfileID, "BaseProfileID", 0, "")
|
||||
fs.Int64Var(&b.ProfileIDRange, "ProfileIDRange", 100000, "")
|
||||
fs.Int64Var(&b.Seed, "Seed", 1, "")
|
||||
fs.IntVar(&b.Iterations, "Iterations", 100, "")
|
||||
fs.StringVar(&b.DB, "DB", "benchdb", "")
|
||||
|
||||
if err := fs.Parse(args); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return fs.Args(), nil
|
||||
}
|
||||
|
||||
// Init connects to pilosa and sets the client on b.
|
||||
func (b *RandomSetBits) Init(hosts []string) (err error) {
|
||||
b.cli, err = pilosa.NewClient(hosts[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if b.DB == "" {
|
||||
b.DB = "RandomSetBits"
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Run runs the RandomSetBits benchmark
|
||||
func (b *RandomSetBits) Run(agentNum int) map[string]interface{} {
|
||||
src := rand.NewSource(b.Seed + int64(agentNum))
|
||||
rng := rand.New(src)
|
||||
results := make(map[string]interface{})
|
||||
if b.cli == nil {
|
||||
results["error"] = fmt.Errorf("No client set for RandomSetBits agent: %v", agentNum)
|
||||
return results
|
||||
}
|
||||
for n := 0; n < b.Iterations; n++ {
|
||||
bitmapID := rng.Int63n(b.BitmapIDRange)
|
||||
profID := rng.Int63n(b.ProfileIDRange)
|
||||
query := fmt.Sprintf("SetBit(%d, 'frame.n', %d)", b.BaseBitmapID+bitmapID, b.BaseProfileID+profID)
|
||||
b.cli.ExecuteQuery(context.TODO(), b.DB, query, true)
|
||||
}
|
||||
return results
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue