From c365f3902d76bd84ff5b69bfc6db7c5c0fc261aa Mon Sep 17 00:00:00 2001 From: siddontang Date: Tue, 28 Oct 2014 17:57:29 +0800 Subject: [PATCH] update bench tool --- cmd/ledis-benchmark/main.go | 101 ++++++++++++++++++++++++++--------- cmd/ledis-storebench/main.go | 8 ++- 2 files changed, 82 insertions(+), 27 deletions(-) diff --git a/cmd/ledis-benchmark/main.go b/cmd/ledis-benchmark/main.go index 510d436..1fe0c2d 100644 --- a/cmd/ledis-benchmark/main.go +++ b/cmd/ledis-benchmark/main.go @@ -6,6 +6,7 @@ import ( "github.com/siddontang/ledisdb/client/go/ledis" "math/rand" "runtime" + "strings" "sync" "sync/atomic" "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 number = flag.Int("n", 1000, "request number") 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 del = flag.Bool("del", true, "enable del benchmark") 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 client *ledis.Client @@ -53,7 +53,13 @@ func bench(cmd string, f func()) { 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 @@ -276,45 +282,90 @@ func main() { *round = 1 } - for i := 0; i < *round; i++ { - benchSet() - benchGet() - benchRandGet() + runAll := true + ts := strings.Split(*tests, ",") + if len(ts) > 0 && len(ts[0]) != 0 { + 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() } - benchPushList() - benchRangeList10() - benchRangeList50() - benchRangeList100() + if checkTest("lpush") { + benchPushList() + } - if *del == true { + if checkTest("lrange") { + benchRangeList10() + benchRangeList50() + benchRangeList100() + } + + if checkTest("lpop") { benchPopList() } - benchHset() - benchHGet() - benchHRandGet() + if checkTest("hset") { + benchHset() + } - if *del == true { + if checkTest("hget") { + benchHGet() + benchHRandGet() + } + + if checkTest("hdel") { benchHDel() } - benchZAdd() - benchZIncr() - benchZRangeByRank() - benchZRangeByScore() + if checkTest("zadd") { + benchZAdd() + } - //rev is too slow in leveldb, rocksdb or other - //maybe disable for huge data benchmark - if *reverse == true { + if checkTest("zincr") { + benchZIncr() + } + + if checkTest("zrange") { + benchZRangeByRank() + benchZRangeByScore() + } + + if checkTest("zrevrange") { + //rev is too slow in leveldb, rocksdb or other + //maybe disable for huge data benchmark benchZRevRangeByRank() benchZRevRangeByScore() } - if *del == true { + if checkTest("zdel") { benchZDel() } diff --git a/cmd/ledis-storebench/main.go b/cmd/ledis-storebench/main.go index 6d91a89..ce37750 100644 --- a/cmd/ledis-storebench/main.go +++ b/cmd/ledis-storebench/main.go @@ -46,8 +46,12 @@ func bench(cmd string, f func()) { t2 := time.Now() 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), - float64((*valueSize+16)*(*number))/(1024.0*1024.0*(d.Seconds())), float64(*number)/d.Seconds()) + fmt.Printf("%s %s: %0.3f micros/op, %0.2fmb/s %0.2fop/s\n", + 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