Skip to content

Commit

Permalink
workload: add new mode for querylog to generate querybench-like file
Browse files Browse the repository at this point in the history
Adds a new mode for querylog workload to write the generated
queries into a file that querybench understands. Also, some fixes
of querylog itself.

Release note: None
  • Loading branch information
yuzefovich committed Mar 25, 2019
1 parent a200cea commit 95b14c5
Show file tree
Hide file tree
Showing 2 changed files with 242 additions and 51 deletions.
18 changes: 14 additions & 4 deletions pkg/workload/querybench/query_bench.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type queryBench struct {
connFlags *workload.ConnFlags
queryFile string
useOpt bool
verbose bool

queries []string
}
Expand All @@ -56,6 +57,7 @@ var queryBenchMeta = workload.Meta{
}
g.flags.StringVar(&g.queryFile, `query-file`, ``, `File of newline separated queries to run`)
g.flags.BoolVar(&g.useOpt, `use-opt`, true, `Use cost-based optimizer`)
g.flags.BoolVar(&g.verbose, `verbose`, true, `Prints out the queries being run as well as histograms`)
g.connFlags = workload.NewConnFlags(&g.flags)
return g
},
Expand Down Expand Up @@ -131,9 +133,10 @@ func (g *queryBench) Ops(urls []string, reg *histogram.Registry) (workload.Query
ql := workload.QueryLoad{SQLDatabase: sqlDatabase}
for i := 0; i < g.connFlags.Concurrency; i++ {
op := queryBenchWorker{
hists: reg.GetHandle(),
db: db,
stmts: stmts,
hists: reg.GetHandle(),
db: db,
stmts: stmts,
verbose: g.verbose,
}
ql.WorkerFns = append(ql.WorkerFns, op.run)
}
Expand All @@ -150,6 +153,8 @@ func getQueries(path string) ([]string, error) {
defer file.Close()

scanner := bufio.NewScanner(file)
// Read lines up to 1 MB in size.
scanner.Buffer(make([]byte, 64*1024), 1024*1024)
var lines []string
for scanner.Scan() {
line := scanner.Text()
Expand All @@ -174,6 +179,7 @@ type queryBenchWorker struct {
stmts []namedStmt

stmtIdx int
verbose bool
}

func (o *queryBenchWorker) run(ctx context.Context) error {
Expand All @@ -193,6 +199,10 @@ func (o *queryBenchWorker) run(ctx context.Context) error {
return err
}
elapsed := timeutil.Since(start)
o.hists.Get(stmt.name).Record(elapsed)
if o.verbose {
o.hists.Get(stmt.name).Record(elapsed)
} else {
o.hists.Get("").Record(elapsed)
}
return nil
}
Loading

0 comments on commit 95b14c5

Please sign in to comment.