Skip to content

Commit

Permalink
Add bencher for raw API (pingcap#2109)
Browse files Browse the repository at this point in the history
* cmd: Add raw API bencher
  • Loading branch information
ngaut authored Nov 29, 2016
1 parent 743e587 commit 24fb8c9
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ LDFLAGS += -X "github.com/pingcap/tidb/util/printer.TiDBGitHash=$(shell git rev-

TARGET = ""

.PHONY: all build update parser clean todo test gotest interpreter server dev benchkv check
.PHONY: all build update parser clean todo test gotest interpreter server dev benchkv benchraw check

default: server buildsucc

Expand Down Expand Up @@ -110,6 +110,9 @@ endif
benchkv:
$(GOBUILD) -ldflags '$(LDFLAGS)' -o bin/benchkv cmd/benchkv/main.go

benchraw:
$(GOBUILD) -ldflags '$(LDFLAGS)' -o bin/benchraw cmd/benchraw/main.go

benchdb:
$(GOBUILD) -ldflags '$(LDFLAGS)' -o bin/benchdb cmd/benchdb/main.go

Expand Down
74 changes: 74 additions & 0 deletions cmd/benchraw/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright 2016 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
"flag"
"fmt"
"github.com/juju/errors"
"net/http"
_ "net/http/pprof"
"strings"
"sync"
"time"

"github.com/ngaut/log"
"github.com/pingcap/tidb/store/tikv"
)

var (
dataCnt = flag.Int("N", 1000000, "data num")
workerCnt = flag.Int("C", 100, "concurrent num")
pdAddr = flag.String("pd", "localhost:2379", "pd address:localhost:2379")
valueSize = flag.Int("V", 5, "value size in byte")
)

// blind put bench
func batchRawPut(value []byte) {
cli, err := tikv.NewRawKVClient(strings.Split(*pdAddr, ","))
if err != nil {
log.Fatal(err)
}

wg := sync.WaitGroup{}
base := *dataCnt / *workerCnt
wg.Add(*workerCnt)
for i := 0; i < *workerCnt; i++ {
go func(i int) {
defer wg.Done()

for j := 0; j < base; j++ {
k := base*i + j
key := fmt.Sprintf("key_%d", k)
err = cli.Put([]byte(key), value)
if err != nil {
log.Fatal(errors.ErrorStack(err))
}
}
}(i)
}
wg.Wait()
}

func main() {
flag.Parse()
log.SetLevelByString("warn")
go http.ListenAndServe(":9191", nil)

value := make([]byte, *valueSize)
t := time.Now()
batchRawPut(value)

fmt.Printf("\nelapse:%v, total %v\n", time.Since(t), *dataCnt)
}

0 comments on commit 24fb8c9

Please sign in to comment.