adjust benchmark

This commit is contained in:
siddontang 2014-09-04 14:00:32 +08:00
parent c516efa800
commit 9eaab3fba2
1 changed files with 62 additions and 10 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"
"sync" "sync"
"sync/atomic"
"time" "time"
) )
@ -13,6 +14,7 @@ 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 wg sync.WaitGroup var wg sync.WaitGroup
@ -52,9 +54,14 @@ func bench(cmd string, f func()) {
fmt.Printf("%s: %0.2f requests per second\n", cmd, (float64(*number) / delta)) fmt.Printf("%s: %0.2f requests per second\n", cmd, (float64(*number) / delta))
} }
var kvSetBase int64 = 0
var kvGetBase int64 = 0
var kvIncrBase int64 = 0
var kvDelBase int64 = 0
func benchSet() { func benchSet() {
f := func() { f := func() {
n := rand.Int() n := atomic.AddInt64(&kvSetBase, 1)
waitBench("set", n, n) waitBench("set", n, n)
} }
@ -62,6 +69,15 @@ func benchSet() {
} }
func benchGet() { func benchGet() {
f := func() {
n := atomic.AddInt64(&kvGetBase, 1)
waitBench("get", n)
}
bench("get", f)
}
func benchRandGet() {
f := func() { f := func() {
n := rand.Int() n := rand.Int()
waitBench("get", n) waitBench("get", n)
@ -72,13 +88,22 @@ func benchGet() {
func benchIncr() { func benchIncr() {
f := func() { f := func() {
n := rand.Int() n := atomic.AddInt64(&kvIncrBase, 1)
waitBench("incr", n) waitBench("incr", n)
} }
bench("incr", f) bench("incr", f)
} }
func benchDel() {
f := func() {
n := atomic.AddInt64(&kvDelBase, 1)
waitBench("del", n)
}
bench("del", f)
}
func benchPushList() { func benchPushList() {
f := func() { f := func() {
n := rand.Int() n := rand.Int()
@ -120,9 +145,14 @@ func benchPopList() {
bench("lpop", f) bench("lpop", f)
} }
var hashSetBase int64 = 0
var hashIncrBase int64 = 0
var hashGetBase int64 = 0
var hashDelBase int64 = 0
func benchHset() { func benchHset() {
f := func() { f := func() {
n := rand.Int() n := atomic.AddInt64(&hashSetBase, 1)
waitBench("hset", "myhashkey", n, n) waitBench("hset", "myhashkey", n, n)
} }
@ -131,7 +161,7 @@ func benchHset() {
func benchHIncr() { func benchHIncr() {
f := func() { f := func() {
n := rand.Int() n := atomic.AddInt64(&hashIncrBase, 1)
waitBench("hincrby", "myhashkey", n, 1) waitBench("hincrby", "myhashkey", n, 1)
} }
@ -139,6 +169,15 @@ func benchHIncr() {
} }
func benchHGet() { func benchHGet() {
f := func() {
n := atomic.AddInt64(&hashGetBase, 1)
waitBench("hget", "myhashkey", n)
}
bench("hget", f)
}
func benchHRandGet() {
f := func() { f := func() {
n := rand.Int() n := rand.Int()
waitBench("hget", "myhashkey", n) waitBench("hget", "myhashkey", n)
@ -149,16 +188,20 @@ func benchHGet() {
func benchHDel() { func benchHDel() {
f := func() { f := func() {
n := rand.Int() n := atomic.AddInt64(&hashDelBase, 1)
waitBench("hdel", "myhashkey", n) waitBench("hdel", "myhashkey", n)
} }
bench("hdel", f) bench("hdel", f)
} }
var zsetAddBase int64 = 0
var zsetDelBase int64 = 0
var zsetIncrBase int64 = 0
func benchZAdd() { func benchZAdd() {
f := func() { f := func() {
n := rand.Int() n := atomic.AddInt64(&zsetAddBase, 1)
waitBench("zadd", "myzsetkey", n, n) waitBench("zadd", "myzsetkey", n, n)
} }
@ -167,7 +210,7 @@ func benchZAdd() {
func benchZDel() { func benchZDel() {
f := func() { f := func() {
n := rand.Int() n := atomic.AddInt64(&zsetDelBase, 1)
waitBench("zrem", "myzsetkey", n) waitBench("zrem", "myzsetkey", n)
} }
@ -176,7 +219,7 @@ func benchZDel() {
func benchZIncr() { func benchZIncr() {
f := func() { f := func() {
n := rand.Int() n := atomic.AddInt64(&zsetIncrBase, 1)
waitBench("zincrby", "myzsetkey", 1, n) waitBench("zincrby", "myzsetkey", 1, n)
} }
@ -239,6 +282,8 @@ func main() {
benchSet() benchSet()
benchIncr() benchIncr()
benchGet() benchGet()
benchRandGet()
benchDel()
benchPushList() benchPushList()
benchRangeList10() benchRangeList10()
@ -249,13 +294,20 @@ func main() {
benchHset() benchHset()
benchHGet() benchHGet()
benchHIncr() benchHIncr()
benchHRandGet()
benchHDel() benchHDel()
benchZAdd() benchZAdd()
benchZIncr() benchZIncr()
benchZRangeByRank() benchZRangeByRank()
benchZRangeByScore() benchZRangeByScore()
//rev is too slow in leveldb, rocksdb or other
//maybe disable for huge data benchmark
if *reverse == true {
benchZRevRangeByRank() benchZRevRangeByRank()
benchZRevRangeByScore() benchZRevRangeByScore()
}
benchZDel() benchZDel()
} }