Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

benchdb: support specify a sql query to run. #2395

Merged
merged 2 commits into from Jan 5, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions cmd/benchdb/README.md
Expand Up @@ -7,15 +7,15 @@ BenchDB is a command line tool to test the performance of TiDB.
Make sure you have started PD and TiKV, then run:

```
./benchdb -run="create,truncate,insert:0_10000,update-random:0_10000:100000,select:0_10000:10"
./benchdb -run="create|truncate|insert:0_10000|update-random:0_10000:100000|select:0_10000:10"
```


### Arguments

#### `run`
The `run` argument defines the workflow of the test. You can define
multiple jobs, separated by `,`. The jobs are executed sequentially.
multiple jobs, separated by `|`. The jobs are executed sequentially.
The `run` argument has the following options:

* `create` creates a table. Currently it's just a typical simple table, with a few columns.
Expand All @@ -32,7 +32,9 @@ The `run` argument has the following options:

* `select:xxx_yyy:zzz` select rows with ID range in `[xxx, yyy)`, for `zzz` times.

* `gc` does a manually triggered GC, so we can compare the performance before and after GC.
* `gc` does a manually triggered GC, so we can compare the performance before and after GC.

* `query:xxx:zzz` run a sql query `xxx`, for `zzz` times.

The output shows the execution time.

Expand Down
17 changes: 14 additions & 3 deletions cmd/benchdb/main.go
Expand Up @@ -29,7 +29,7 @@ import (

var (
addr = flag.String("addr", "127.0.0.1:2379", "pd address")
tableName = flag.String("table", "bench_db", "name of the table")
tableName = flag.String("table", "benchdb", "name of the table")
batchSize = flag.Int("batch", 100, "number of statements in a transaction, used for insert and update-random only")
blobSize = flag.Int("blob", 1000, "size of the blob column in the row")
logLevel = flag.String("L", "warn", "log level")
Expand All @@ -43,7 +43,7 @@ var (
"select:0_10000:10",
"gc",
"select:0_10000:10",
}, ","), "jobs to run")
}, "|"), "jobs to run")
)

var blobString string
Expand All @@ -55,7 +55,7 @@ func main() {
tidb.RegisterStore("tikv", tikv.Driver{})
blobString = strings.Repeat("0", *blobSize)
ut := newBenchDB()
works := strings.Split(*runJobs, ",")
works := strings.Split(*runJobs, "|")
for _, v := range works {
work := strings.ToLower(strings.TrimSpace(v))
name, spec := ut.mustParseWork(work)
Expand All @@ -74,6 +74,8 @@ func main() {
ut.selectRows(spec)
case "gc":
ut.manualGC(nil)
case "query":
ut.query(spec)
default:
cLog("Unknown job ", v)
return
Expand Down Expand Up @@ -291,6 +293,15 @@ func (ut *benchDB) manualGC(done chan bool) {
}
}

func (ut *benchDB) query(spec string) {
strs := strings.Split(spec, ":")
sql := strs[0]
count, _ := strconv.Atoi(strs[1])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why discard this error?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The string is manually inputted, we can make sure it's valid int.

ut.runCountTimes("query", count, func() {
ut.mustExec(sql)
})
}

func cLogf(format string, args ...interface{}) {
str := fmt.Sprintf(format, args...)
fmt.Println("\033[0;32m" + str + "\033[0m\n")
Expand Down