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 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,92 +285,49 @@ 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 {
|
||||||
benchSet()
|
switch strings.ToLower(s) {
|
||||||
}
|
case "set":
|
||||||
|
benchSet()
|
||||||
if checkTest("get") {
|
case "get":
|
||||||
benchGet()
|
benchGet()
|
||||||
}
|
case "randget":
|
||||||
|
benchRandGet()
|
||||||
if checkTest("randget") {
|
case "del":
|
||||||
benchRandGet()
|
benchDel()
|
||||||
}
|
case "lpush":
|
||||||
|
benchPushList()
|
||||||
if checkTest("del") {
|
case "lrange":
|
||||||
benchDel()
|
benchRangeList10()
|
||||||
}
|
benchRangeList50()
|
||||||
|
benchRangeList100()
|
||||||
if checkTest("lpush") {
|
case "lpop":
|
||||||
benchPushList()
|
benchPopList()
|
||||||
}
|
case "hset":
|
||||||
|
benchHset()
|
||||||
if checkTest("lrange") {
|
case "hget":
|
||||||
benchRangeList10()
|
benchHGet()
|
||||||
benchRangeList50()
|
benchHRandGet()
|
||||||
benchRangeList100()
|
case "hdel":
|
||||||
}
|
benchHDel()
|
||||||
|
case "zadd":
|
||||||
if checkTest("lpop") {
|
benchZAdd()
|
||||||
benchPopList()
|
case "zincr":
|
||||||
}
|
benchZIncr()
|
||||||
|
case "zrange":
|
||||||
if checkTest("hset") {
|
benchZRangeByRank()
|
||||||
benchHset()
|
benchZRangeByScore()
|
||||||
}
|
case "zrevrange":
|
||||||
|
//rev is too slow in leveldb, rocksdb or other
|
||||||
if checkTest("hget") {
|
//maybe disable for huge data benchmark
|
||||||
benchHGet()
|
benchZRevRangeByRank()
|
||||||
benchHRandGet()
|
benchZRevRangeByScore()
|
||||||
}
|
case "zdel":
|
||||||
|
benchZDel()
|
||||||
if checkTest("hdel") {
|
}
|
||||||
benchHDel()
|
|
||||||
}
|
|
||||||
|
|
||||||
if checkTest("zadd") {
|
|
||||||
benchZAdd()
|
|
||||||
}
|
|
||||||
|
|
||||||
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 checkTest("zdel") {
|
|
||||||
benchZDel()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
println("")
|
println("")
|
||||||
|
|
|
@ -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":
|
||||||
wb.Write(data)
|
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:
|
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()
|
||||||
|
|
Loading…
Reference in New Issue