Skip to content

Commit

Permalink
benchdb: support specify a sql query to run. (pingcap#2395)
Browse files Browse the repository at this point in the history
  • Loading branch information
coocood authored Jan 5, 2017
1 parent c8cc389 commit 27c3a37
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
8 changes: 5 additions & 3 deletions cmd/benchdb/README.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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])
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

0 comments on commit 27c3a37

Please sign in to comment.