update benchmark

This commit is contained in:
siddontang 2014-09-04 15:49:51 +08:00
parent 1dd8720562
commit 8ad6eabd6a
1 changed files with 50 additions and 52 deletions

View File

@ -1,6 +1,7 @@
package main package main
import ( import (
crand "crypto/rand"
"flag" "flag"
"fmt" "fmt"
"github.com/siddontang/ledisdb/client/go/ledis" "github.com/siddontang/ledisdb/client/go/ledis"
@ -15,6 +16,7 @@ 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 reverse = flag.Bool("rev", false, "enable zset rev benchmark")
var round = flag.Int("r", 1, "benchmark round number")
var wg sync.WaitGroup var wg sync.WaitGroup
@ -61,8 +63,10 @@ var kvDelBase int64 = 0
func benchSet() { func benchSet() {
f := func() { f := func() {
value := make([]byte, 100)
crand.Read(value)
n := atomic.AddInt64(&kvSetBase, 1) n := atomic.AddInt64(&kvSetBase, 1)
waitBench("set", n, n) waitBench("set", n, value)
} }
bench("set", f) bench("set", f)
@ -86,15 +90,6 @@ func benchRandGet() {
bench("get", f) bench("get", f)
} }
func benchIncr() {
f := func() {
n := atomic.AddInt64(&kvIncrBase, 1)
waitBench("incr", n)
}
bench("incr", f)
}
func benchDel() { func benchDel() {
f := func() { f := func() {
n := atomic.AddInt64(&kvDelBase, 1) n := atomic.AddInt64(&kvDelBase, 1)
@ -106,8 +101,9 @@ func benchDel() {
func benchPushList() { func benchPushList() {
f := func() { f := func() {
n := rand.Int() value := make([]byte, 10)
waitBench("rpush", "mytestlist", n) crand.Read(value)
waitBench("rpush", "mytestlist", value)
} }
bench("rpush", f) bench("rpush", f)
@ -152,22 +148,16 @@ var hashDelBase int64 = 0
func benchHset() { func benchHset() {
f := func() { f := func() {
value := make([]byte, 100)
crand.Read(value)
n := atomic.AddInt64(&hashSetBase, 1) n := atomic.AddInt64(&hashSetBase, 1)
waitBench("hset", "myhashkey", n, n) waitBench("hset", "myhashkey", n, value)
} }
bench("hset", f) bench("hset", f)
} }
func benchHIncr() {
f := func() {
n := atomic.AddInt64(&hashIncrBase, 1)
waitBench("hincrby", "myhashkey", n, 1)
}
bench("hincrby", f)
}
func benchHGet() { func benchHGet() {
f := func() { f := func() {
n := atomic.AddInt64(&hashGetBase, 1) n := atomic.AddInt64(&hashGetBase, 1)
@ -201,8 +191,10 @@ var zsetIncrBase int64 = 0
func benchZAdd() { func benchZAdd() {
f := func() { f := func() {
member := make([]byte, 16)
crand.Read(member)
n := atomic.AddInt64(&zsetAddBase, 1) n := atomic.AddInt64(&zsetAddBase, 1)
waitBench("zadd", "myzsetkey", n, n) waitBench("zadd", "myzsetkey", n, member)
} }
bench("zadd", f) bench("zadd", f)
@ -279,8 +271,12 @@ func main() {
cfg.Addr = addr cfg.Addr = addr
client = ledis.NewClient(cfg) client = ledis.NewClient(cfg)
if *round <= 0 {
*round = 1
}
for i := 0; i < *round; i++ {
benchSet() benchSet()
benchIncr()
benchGet() benchGet()
benchRandGet() benchRandGet()
benchDel() benchDel()
@ -293,7 +289,6 @@ func main() {
benchHset() benchHset()
benchHGet() benchHGet()
benchHIncr()
benchHRandGet() benchHRandGet()
benchHDel() benchHDel()
@ -310,4 +305,7 @@ func main() {
} }
benchZDel() benchZDel()
println("")
}
} }