diff --git a/cmd/ledis-benchmark/main.go b/cmd/ledis-benchmark/main.go index d5b5311..640607d 100644 --- a/cmd/ledis-benchmark/main.go +++ b/cmd/ledis-benchmark/main.go @@ -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,92 +285,49 @@ 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") { - benchSet() - } - - if checkTest("get") { - benchGet() - } - - if checkTest("randget") { - benchRandGet() - } - - if checkTest("del") { - benchDel() - } - - if checkTest("lpush") { - benchPushList() - } - - if checkTest("lrange") { - benchRangeList10() - benchRangeList50() - benchRangeList100() - } - - if checkTest("lpop") { - benchPopList() - } - - if checkTest("hset") { - benchHset() - } - - if checkTest("hget") { - benchHGet() - benchHRandGet() - } - - 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() + for _, s := range ts { + switch strings.ToLower(s) { + case "set": + benchSet() + case "get": + benchGet() + case "randget": + benchRandGet() + case "del": + benchDel() + case "lpush": + benchPushList() + case "lrange": + benchRangeList10() + benchRangeList50() + benchRangeList100() + case "lpop": + benchPopList() + case "hset": + benchHset() + case "hget": + benchHGet() + benchHRandGet() + case "hdel": + benchHDel() + case "zadd": + benchZAdd() + case "zincr": + benchZIncr() + case "zrange": + benchZRangeByRank() + benchZRangeByScore() + case "zrevrange": + //rev is too slow in leveldb, rocksdb or other + //maybe disable for huge data benchmark + benchZRevRangeByRank() + benchZRevRangeByScore() + case "zdel": + benchZDel() + } } println("") diff --git a/cmd/ledis-respbench/main.go b/cmd/ledis-respbench/main.go index e21d173..0be7da0 100644 --- a/cmd/ledis-respbench/main.go +++ b/cmd/ledis-respbench/main.go @@ -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": - 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: - 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()