update benchmark tool

This commit is contained in:
siddontang 2014-10-30 16:48:15 +08:00
parent 4668350862
commit c14ea7a3a7
2 changed files with 111 additions and 86 deletions

View File

@ -18,7 +18,7 @@ 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 round = flag.Int("r", 1, "benchmark round number") var round = flag.Int("r", 1, "benchmark round number")
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,randget,del,lpush,lrange,lpop,hset,hget,hdel,zadd,zincr,zrange,zrevrange,zdel") var tests = flag.String("t", "set,get,randget,del,lpush,lrange,lpop,hset,hget,hdel,zadd,zincr,zrange,zrevrange,zdel", "only run the comma separated list of tests")
var wg sync.WaitGroup var wg sync.WaitGroup
var client *ledis.Client var client *ledis.Client
@ -285,93 +285,50 @@ func main() {
*round = 1 *round = 1
} }
runAll := true
ts := strings.Split(*tests, ",") ts := strings.Split(*tests, ",")
if len(ts) > 0 && len(ts[0]) != 0 {
runAll = false
}
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++ { for i := 0; i < *round; i++ {
if checkTest("set") { for _, s := range ts {
switch strings.ToLower(s) {
case "set":
benchSet() benchSet()
} case "get":
if checkTest("get") {
benchGet() benchGet()
} case "randget":
if checkTest("randget") {
benchRandGet() benchRandGet()
} case "del":
if checkTest("del") {
benchDel() benchDel()
} case "lpush":
if checkTest("lpush") {
benchPushList() benchPushList()
} case "lrange":
if checkTest("lrange") {
benchRangeList10() benchRangeList10()
benchRangeList50() benchRangeList50()
benchRangeList100() benchRangeList100()
} case "lpop":
if checkTest("lpop") {
benchPopList() benchPopList()
} case "hset":
if checkTest("hset") {
benchHset() benchHset()
} case "hget":
if checkTest("hget") {
benchHGet() benchHGet()
benchHRandGet() benchHRandGet()
} case "hdel":
if checkTest("hdel") {
benchHDel() benchHDel()
} case "zadd":
if checkTest("zadd") {
benchZAdd() benchZAdd()
} case "zincr":
if checkTest("zincr") {
benchZIncr() benchZIncr()
} case "zrange":
if checkTest("zrange") {
benchZRangeByRank() benchZRangeByRank()
benchZRangeByScore() benchZRangeByScore()
} case "zrevrange":
if checkTest("zrevrange") {
//rev is too slow in leveldb, rocksdb or other //rev is too slow in leveldb, rocksdb or other
//maybe disable for huge data benchmark //maybe disable for huge data benchmark
benchZRevRangeByRank() benchZRevRangeByRank()
benchZRevRangeByScore() benchZRevRangeByScore()
} case "zdel":
if checkTest("zdel") {
benchZDel() benchZDel()
} }
}
println("") println("")
} }

View File

@ -6,13 +6,41 @@ import (
"flag" "flag"
"fmt" "fmt"
"github.com/siddontang/go/arena" "github.com/siddontang/go/arena"
"github.com/siddontang/ledisdb/config"
"github.com/siddontang/ledisdb/ledis"
"github.com/siddontang/ledisdb/server" "github.com/siddontang/ledisdb/server"
"net" "net"
"os"
"runtime" "runtime"
"time" "time"
) )
var KB = config.KB
var MB = config.MB
var GB = config.GB
var addr = flag.String("addr", ":6380", "listen addr") var addr = flag.String("addr", ":6380", "listen addr")
var name = flag.String("db_name", "", "db name")
var ldb *ledis.Ledis
var db *ledis.DB
func setRocksDB(cfg *config.RocksDBConfig) {
cfg.BlockSize = 64 * KB
cfg.WriteBufferSize = 64 * MB
cfg.MaxWriteBufferNum = 2
cfg.MaxBytesForLevelBase = 512 * MB
cfg.TargetFileSizeBase = 64 * MB
cfg.BackgroundThreads = 4
cfg.HighPriorityBackgroundThreads = 1
cfg.MaxBackgroundCompactions = 3
cfg.MaxBackgroundFlushes = 1
cfg.CacheSize = 512 * MB
cfg.EnableStatistics = true
cfg.StatsDumpPeriodSec = 5
cfg.Level0FileNumCompactionTrigger = 8
cfg.MaxBytesForLevelMultiplier = 8
}
func main() { func main() {
runtime.GOMAXPROCS(runtime.NumCPU()) runtime.GOMAXPROCS(runtime.NumCPU())
@ -27,6 +55,31 @@ func main() {
return return
} }
if len(*name) > 0 {
cfg := config.NewConfigDefault()
cfg.DataDir = "./var/ledis_respbench"
cfg.DBName = *name
os.RemoveAll(cfg.DBPath)
defer os.RemoveAll(cfg.DBPath)
os.MkdirAll(cfg.DBPath, 0755)
cfg.LevelDB.BlockSize = 32 * KB
cfg.LevelDB.CacheSize = 512 * MB
cfg.LevelDB.WriteBufferSize = 64 * MB
cfg.LevelDB.MaxOpenFiles = 1000
setRocksDB(&cfg.RocksDB)
ldb, err = ledis.Open(cfg)
if err != nil {
println(err.Error())
return
}
db, _ = ldb.Select(0)
}
for { for {
c, err := l.Accept() c, err := l.Accept()
if err != nil { if err != nil {
@ -69,11 +122,26 @@ func run(c net.Conn) {
cmd := string(bytes.ToUpper(req[0])) cmd := string(bytes.ToUpper(req[0]))
switch cmd { switch cmd {
case "SET": case "SET":
if db != nil {
db.Set(req[1], req[2])
}
wb.Write(ok) wb.Write(ok)
case "GET": case "GET":
if db != nil {
d, _ := db.GetSlice(req[1])
if d == nil {
wb.Write(data) wb.Write(data)
} else {
wb.WriteString(fmt.Sprintf("$%d\r\n", d.Size()))
wb.Write(d.Data())
wb.WriteString("\r\n")
d.Free()
}
} else {
wb.Write(data)
}
default: default:
wb.WriteString(fmt.Sprintf("-Err %s Not Supported Now", req[0])) wb.WriteString(fmt.Sprintf("-Err %s Not Supported Now\r\n", req[0]))
} }
wb.Flush() wb.Flush()