mirror of https://github.com/ledisdb/ledisdb.git
update benchmark tool
This commit is contained in:
parent
4668350862
commit
c14ea7a3a7
|
@ -18,7 +18,7 @@ var number = flag.Int("n", 1000, "request number")
|
|||
var clients = flag.Int("c", 50, "number of clients")
|
||||
var round = flag.Int("r", 1, "benchmark round number")
|
||||
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 client *ledis.Client
|
||||
|
@ -285,93 +285,50 @@ func main() {
|
|||
*round = 1
|
||||
}
|
||||
|
||||
runAll := true
|
||||
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++ {
|
||||
if checkTest("set") {
|
||||
for _, s := range ts {
|
||||
switch strings.ToLower(s) {
|
||||
case "set":
|
||||
benchSet()
|
||||
}
|
||||
|
||||
if checkTest("get") {
|
||||
case "get":
|
||||
benchGet()
|
||||
}
|
||||
|
||||
if checkTest("randget") {
|
||||
case "randget":
|
||||
benchRandGet()
|
||||
}
|
||||
|
||||
if checkTest("del") {
|
||||
case "del":
|
||||
benchDel()
|
||||
}
|
||||
|
||||
if checkTest("lpush") {
|
||||
case "lpush":
|
||||
benchPushList()
|
||||
}
|
||||
|
||||
if checkTest("lrange") {
|
||||
case "lrange":
|
||||
benchRangeList10()
|
||||
benchRangeList50()
|
||||
benchRangeList100()
|
||||
}
|
||||
|
||||
if checkTest("lpop") {
|
||||
case "lpop":
|
||||
benchPopList()
|
||||
}
|
||||
|
||||
if checkTest("hset") {
|
||||
case "hset":
|
||||
benchHset()
|
||||
}
|
||||
|
||||
if checkTest("hget") {
|
||||
case "hget":
|
||||
benchHGet()
|
||||
benchHRandGet()
|
||||
}
|
||||
|
||||
if checkTest("hdel") {
|
||||
case "hdel":
|
||||
benchHDel()
|
||||
}
|
||||
|
||||
if checkTest("zadd") {
|
||||
case "zadd":
|
||||
benchZAdd()
|
||||
}
|
||||
|
||||
if checkTest("zincr") {
|
||||
case "zincr":
|
||||
benchZIncr()
|
||||
}
|
||||
|
||||
if checkTest("zrange") {
|
||||
case "zrange":
|
||||
benchZRangeByRank()
|
||||
benchZRangeByScore()
|
||||
}
|
||||
|
||||
if checkTest("zrevrange") {
|
||||
case "zrevrange":
|
||||
//rev is too slow in leveldb, rocksdb or other
|
||||
//maybe disable for huge data benchmark
|
||||
benchZRevRangeByRank()
|
||||
benchZRevRangeByScore()
|
||||
}
|
||||
|
||||
if checkTest("zdel") {
|
||||
case "zdel":
|
||||
benchZDel()
|
||||
}
|
||||
}
|
||||
|
||||
println("")
|
||||
}
|
||||
|
|
|
@ -6,13 +6,41 @@ import (
|
|||
"flag"
|
||||
"fmt"
|
||||
"github.com/siddontang/go/arena"
|
||||
"github.com/siddontang/ledisdb/config"
|
||||
"github.com/siddontang/ledisdb/ledis"
|
||||
"github.com/siddontang/ledisdb/server"
|
||||
"net"
|
||||
"os"
|
||||
"runtime"
|
||||
"time"
|
||||
)
|
||||
|
||||
var KB = config.KB
|
||||
var MB = config.MB
|
||||
var GB = config.GB
|
||||
|
||||
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() {
|
||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||
|
@ -27,6 +55,31 @@ func main() {
|
|||
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 {
|
||||
c, err := l.Accept()
|
||||
if err != nil {
|
||||
|
@ -69,11 +122,26 @@ func run(c net.Conn) {
|
|||
cmd := string(bytes.ToUpper(req[0]))
|
||||
switch cmd {
|
||||
case "SET":
|
||||
if db != nil {
|
||||
db.Set(req[1], req[2])
|
||||
}
|
||||
wb.Write(ok)
|
||||
case "GET":
|
||||
if db != nil {
|
||||
d, _ := db.GetSlice(req[1])
|
||||
if d == nil {
|
||||
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:
|
||||
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()
|
||||
|
|
Loading…
Reference in New Issue