update bench tool

This commit is contained in:
siddontang 2014-10-28 17:57:29 +08:00
parent d0a40c411d
commit c365f3902d
2 changed files with 82 additions and 27 deletions

View File

@ -6,6 +6,7 @@ import (
"github.com/siddontang/ledisdb/client/go/ledis" "github.com/siddontang/ledisdb/client/go/ledis"
"math/rand" "math/rand"
"runtime" "runtime"
"strings"
"sync" "sync"
"sync/atomic" "sync/atomic"
"time" "time"
@ -15,10 +16,9 @@ var ip = flag.String("ip", "127.0.0.1", "redis/ledis/ssdb server ip")
var port = flag.Int("port", 6380, "redis/ledis/ssdb server port") var port = flag.Int("port", 6380, "redis/ledis/ssdb server port")
var number = flag.Int("n", 1000, "request number") var number = flag.Int("n", 1000, "request number")
var clients = flag.Int("c", 50, "number of clients") var clients = flag.Int("c", 50, "number of clients")
var reverse = flag.Bool("rev", false, "enable zset rev benchmark")
var round = flag.Int("r", 1, "benchmark round number") var round = flag.Int("r", 1, "benchmark round number")
var del = flag.Bool("del", true, "enable del benchmark")
var valueSize = flag.Int("vsize", 100, "kv value size") var valueSize = flag.Int("vsize", 100, "kv value size")
var tests = flag.String("t", "", "only run the comma separated list of tests, set,get,del,lpush,lrange,lpop,hset,hget,hdel,zadd,zincr,zrange,zrevrange,zdel")
var wg sync.WaitGroup var wg sync.WaitGroup
var client *ledis.Client var client *ledis.Client
@ -53,7 +53,13 @@ func bench(cmd string, f func()) {
t2 := time.Now() t2 := time.Now()
fmt.Printf("%s: %0.2f op/s\n", cmd, (float64(*number) / t2.Sub(t1).Seconds())) d := t2.Sub(t1)
fmt.Printf("%s: %s %0.3f micros/op, %0.2fop/s\n",
cmd,
d.String(),
float64(d.Nanoseconds()/1e3)/float64(*number),
float64(*number)/d.Seconds())
} }
var kvSetBase int64 = 0 var kvSetBase int64 = 0
@ -276,45 +282,90 @@ func main() {
*round = 1 *round = 1
} }
for i := 0; i < *round; i++ { runAll := true
benchSet() ts := strings.Split(*tests, ",")
benchGet() if len(ts) > 0 && len(ts[0]) != 0 {
benchRandGet() runAll = false
}
if *del == true { println(*tests, len(ts))
needTest := make(map[string]struct{})
for _, s := range ts {
needTest[strings.ToLower(s)] = struct{}{}
}
checkTest := func(cmd string) bool {
if runAll {
return true
} else if _, ok := needTest[cmd]; ok {
return ok
}
return false
}
for i := 0; i < *round; i++ {
if checkTest("set") {
benchSet()
}
if checkTest("get") {
benchGet()
benchRandGet()
}
if checkTest("del") {
benchDel() benchDel()
} }
benchPushList() if checkTest("lpush") {
benchRangeList10() benchPushList()
benchRangeList50() }
benchRangeList100()
if *del == true { if checkTest("lrange") {
benchRangeList10()
benchRangeList50()
benchRangeList100()
}
if checkTest("lpop") {
benchPopList() benchPopList()
} }
benchHset() if checkTest("hset") {
benchHGet() benchHset()
benchHRandGet() }
if *del == true { if checkTest("hget") {
benchHGet()
benchHRandGet()
}
if checkTest("hdel") {
benchHDel() benchHDel()
} }
benchZAdd() if checkTest("zadd") {
benchZIncr() benchZAdd()
benchZRangeByRank() }
benchZRangeByScore()
//rev is too slow in leveldb, rocksdb or other if checkTest("zincr") {
//maybe disable for huge data benchmark benchZIncr()
if *reverse == true { }
if checkTest("zrange") {
benchZRangeByRank()
benchZRangeByScore()
}
if checkTest("zrevrange") {
//rev is too slow in leveldb, rocksdb or other
//maybe disable for huge data benchmark
benchZRevRangeByRank() benchZRevRangeByRank()
benchZRevRangeByScore() benchZRevRangeByScore()
} }
if *del == true { if checkTest("zdel") {
benchZDel() benchZDel()
} }

View File

@ -46,8 +46,12 @@ func bench(cmd string, f func()) {
t2 := time.Now() t2 := time.Now()
d := t2.Sub(t1) d := t2.Sub(t1)
fmt.Printf("%s: %0.3f micros/op, %0.2fmb/s %0.2fop/s\n", cmd, float64(d.Nanoseconds()/1e3)/float64(*number), fmt.Printf("%s %s: %0.3f micros/op, %0.2fmb/s %0.2fop/s\n",
float64((*valueSize+16)*(*number))/(1024.0*1024.0*(d.Seconds())), float64(*number)/d.Seconds()) cmd,
d.String(),
float64(d.Nanoseconds()/1e3)/float64(*number),
float64((*valueSize+16)*(*number))/(1024.0*1024.0*(d.Seconds())),
float64(*number)/d.Seconds())
} }
var kvSetBase int64 = 0 var kvSetBase int64 = 0