forked from mirror/ledisdb
parent
522d94e31e
commit
9282c7223e
|
@ -4,11 +4,6 @@ import (
|
||||||
"container/list"
|
"container/list"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
pingPeriod time.Duration = 3 * time.Second
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
@ -98,7 +93,6 @@ func (c *Client) put(conn *Conn) {
|
||||||
c.Unlock()
|
c.Unlock()
|
||||||
conn.finalize()
|
conn.finalize()
|
||||||
} else {
|
} else {
|
||||||
conn.lastActive = time.Now()
|
|
||||||
c.conns.PushFront(conn)
|
c.conns.PushFront(conn)
|
||||||
c.Unlock()
|
c.Unlock()
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Error represents an error returned in a command reply.
|
// Error represents an error returned in a command reply.
|
||||||
|
@ -28,8 +27,6 @@ type Conn struct {
|
||||||
rSize int
|
rSize int
|
||||||
wSize int
|
wSize int
|
||||||
|
|
||||||
lastActive time.Time
|
|
||||||
|
|
||||||
// Scratch space for formatting argument length.
|
// Scratch space for formatting argument length.
|
||||||
// '*' or '$', length, "\r\n"
|
// '*' or '$', length, "\r\n"
|
||||||
lenScratch [32]byte
|
lenScratch [32]byte
|
||||||
|
|
|
@ -22,29 +22,27 @@ var tests = flag.String("t", "", "only run the comma separated list of tests, se
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
|
|
||||||
var client *ledis.Client
|
var client *ledis.Client
|
||||||
|
|
||||||
var loop int = 0
|
var loop int = 0
|
||||||
|
|
||||||
func waitBench(cmd string, args ...interface{}) {
|
func waitBench(c *ledis.Conn, cmd string, args ...interface{}) {
|
||||||
c := client.Get()
|
|
||||||
defer c.Close()
|
|
||||||
|
|
||||||
_, err := c.Do(strings.ToUpper(cmd), args...)
|
_, err := c.Do(strings.ToUpper(cmd), args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("do %s error %s\n", cmd, err.Error())
|
fmt.Printf("do %s error %s\n", cmd, err.Error())
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func bench(cmd string, f func()) {
|
}
|
||||||
|
|
||||||
|
func bench(cmd string, f func(c *ledis.Conn)) {
|
||||||
wg.Add(*clients)
|
wg.Add(*clients)
|
||||||
|
|
||||||
t1 := time.Now()
|
t1 := time.Now()
|
||||||
for i := 0; i < *clients; i++ {
|
for i := 0; i < *clients; i++ {
|
||||||
go func() {
|
go func() {
|
||||||
|
c := client.Get()
|
||||||
for j := 0; j < loop; j++ {
|
for j := 0; j < loop; j++ {
|
||||||
f()
|
f(c)
|
||||||
}
|
}
|
||||||
|
c.Close()
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
@ -68,78 +66,78 @@ var kvIncrBase int64 = 0
|
||||||
var kvDelBase int64 = 0
|
var kvDelBase int64 = 0
|
||||||
|
|
||||||
func benchSet() {
|
func benchSet() {
|
||||||
f := func() {
|
f := func(c *ledis.Conn) {
|
||||||
value := make([]byte, *valueSize)
|
value := make([]byte, *valueSize)
|
||||||
n := atomic.AddInt64(&kvSetBase, 1)
|
n := atomic.AddInt64(&kvSetBase, 1)
|
||||||
waitBench("set", n, value)
|
waitBench(c, "SET", n, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
bench("set", f)
|
bench("set", f)
|
||||||
}
|
}
|
||||||
|
|
||||||
func benchGet() {
|
func benchGet() {
|
||||||
f := func() {
|
f := func(c *ledis.Conn) {
|
||||||
n := atomic.AddInt64(&kvGetBase, 1)
|
n := atomic.AddInt64(&kvGetBase, 1)
|
||||||
waitBench("get", n)
|
waitBench(c, "GET", n)
|
||||||
}
|
}
|
||||||
|
|
||||||
bench("get", f)
|
bench("get", f)
|
||||||
}
|
}
|
||||||
|
|
||||||
func benchRandGet() {
|
func benchRandGet() {
|
||||||
f := func() {
|
f := func(c *ledis.Conn) {
|
||||||
n := rand.Int() % *number
|
n := rand.Int() % *number
|
||||||
waitBench("get", n)
|
waitBench(c, "GET", n)
|
||||||
}
|
}
|
||||||
|
|
||||||
bench("randget", f)
|
bench("randget", f)
|
||||||
}
|
}
|
||||||
|
|
||||||
func benchDel() {
|
func benchDel() {
|
||||||
f := func() {
|
f := func(c *ledis.Conn) {
|
||||||
n := atomic.AddInt64(&kvDelBase, 1)
|
n := atomic.AddInt64(&kvDelBase, 1)
|
||||||
waitBench("del", n)
|
waitBench(c, "DEL", n)
|
||||||
}
|
}
|
||||||
|
|
||||||
bench("del", f)
|
bench("del", f)
|
||||||
}
|
}
|
||||||
|
|
||||||
func benchPushList() {
|
func benchPushList() {
|
||||||
f := func() {
|
f := func(c *ledis.Conn) {
|
||||||
value := make([]byte, 100)
|
value := make([]byte, 100)
|
||||||
waitBench("rpush", "mytestlist", value)
|
waitBench(c, "RPUSH", "mytestlist", value)
|
||||||
}
|
}
|
||||||
|
|
||||||
bench("rpush", f)
|
bench("rpush", f)
|
||||||
}
|
}
|
||||||
|
|
||||||
func benchRangeList10() {
|
func benchRangeList10() {
|
||||||
f := func() {
|
f := func(c *ledis.Conn) {
|
||||||
waitBench("lrange", "mytestlist", 0, 10)
|
waitBench(c, "LRANGE", "mytestlist", 0, 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
bench("lrange10", f)
|
bench("lrange10", f)
|
||||||
}
|
}
|
||||||
|
|
||||||
func benchRangeList50() {
|
func benchRangeList50() {
|
||||||
f := func() {
|
f := func(c *ledis.Conn) {
|
||||||
waitBench("lrange", "mytestlist", 0, 50)
|
waitBench(c, "LRANGE", "mytestlist", 0, 50)
|
||||||
}
|
}
|
||||||
|
|
||||||
bench("lrange50", f)
|
bench("lrange50", f)
|
||||||
}
|
}
|
||||||
|
|
||||||
func benchRangeList100() {
|
func benchRangeList100() {
|
||||||
f := func() {
|
f := func(c *ledis.Conn) {
|
||||||
waitBench("lrange", "mytestlist", 0, 100)
|
waitBench(c, "LRANGE", "mytestlist", 0, 100)
|
||||||
}
|
}
|
||||||
|
|
||||||
bench("lrange100", f)
|
bench("lrange100", f)
|
||||||
}
|
}
|
||||||
|
|
||||||
func benchPopList() {
|
func benchPopList() {
|
||||||
f := func() {
|
f := func(c *ledis.Conn) {
|
||||||
waitBench("lpop", "mytestlist")
|
waitBench(c, "LPOP", "mytestlist")
|
||||||
}
|
}
|
||||||
|
|
||||||
bench("lpop", f)
|
bench("lpop", f)
|
||||||
|
@ -151,38 +149,38 @@ var hashGetBase int64 = 0
|
||||||
var hashDelBase int64 = 0
|
var hashDelBase int64 = 0
|
||||||
|
|
||||||
func benchHset() {
|
func benchHset() {
|
||||||
f := func() {
|
f := func(c *ledis.Conn) {
|
||||||
value := make([]byte, 100)
|
value := make([]byte, 100)
|
||||||
|
|
||||||
n := atomic.AddInt64(&hashSetBase, 1)
|
n := atomic.AddInt64(&hashSetBase, 1)
|
||||||
waitBench("hset", "myhashkey", n, value)
|
waitBench(c, "HSET", "myhashkey", n, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
bench("hset", f)
|
bench("hset", f)
|
||||||
}
|
}
|
||||||
|
|
||||||
func benchHGet() {
|
func benchHGet() {
|
||||||
f := func() {
|
f := func(c *ledis.Conn) {
|
||||||
n := atomic.AddInt64(&hashGetBase, 1)
|
n := atomic.AddInt64(&hashGetBase, 1)
|
||||||
waitBench("hget", "myhashkey", n)
|
waitBench(c, "HGET", "myhashkey", n)
|
||||||
}
|
}
|
||||||
|
|
||||||
bench("hget", f)
|
bench("hget", f)
|
||||||
}
|
}
|
||||||
|
|
||||||
func benchHRandGet() {
|
func benchHRandGet() {
|
||||||
f := func() {
|
f := func(c *ledis.Conn) {
|
||||||
n := rand.Int() % *number
|
n := rand.Int() % *number
|
||||||
waitBench("hget", "myhashkey", n)
|
waitBench(c, "HGET", "myhashkey", n)
|
||||||
}
|
}
|
||||||
|
|
||||||
bench("hrandget", f)
|
bench("hrandget", f)
|
||||||
}
|
}
|
||||||
|
|
||||||
func benchHDel() {
|
func benchHDel() {
|
||||||
f := func() {
|
f := func(c *ledis.Conn) {
|
||||||
n := atomic.AddInt64(&hashDelBase, 1)
|
n := atomic.AddInt64(&hashDelBase, 1)
|
||||||
waitBench("hdel", "myhashkey", n)
|
waitBench(c, "HDEL", "myhashkey", n)
|
||||||
}
|
}
|
||||||
|
|
||||||
bench("hdel", f)
|
bench("hdel", f)
|
||||||
|
@ -193,60 +191,60 @@ var zsetDelBase int64 = 0
|
||||||
var zsetIncrBase int64 = 0
|
var zsetIncrBase int64 = 0
|
||||||
|
|
||||||
func benchZAdd() {
|
func benchZAdd() {
|
||||||
f := func() {
|
f := func(c *ledis.Conn) {
|
||||||
member := make([]byte, 16)
|
member := make([]byte, 16)
|
||||||
n := atomic.AddInt64(&zsetAddBase, 1)
|
n := atomic.AddInt64(&zsetAddBase, 1)
|
||||||
waitBench("zadd", "myzsetkey", n, member)
|
waitBench(c, "ZADD", "myzsetkey", n, member)
|
||||||
}
|
}
|
||||||
|
|
||||||
bench("zadd", f)
|
bench("zadd", f)
|
||||||
}
|
}
|
||||||
|
|
||||||
func benchZDel() {
|
func benchZDel() {
|
||||||
f := func() {
|
f := func(c *ledis.Conn) {
|
||||||
n := atomic.AddInt64(&zsetDelBase, 1)
|
n := atomic.AddInt64(&zsetDelBase, 1)
|
||||||
waitBench("zrem", "myzsetkey", n)
|
waitBench(c, "ZREM", "myzsetkey", n)
|
||||||
}
|
}
|
||||||
|
|
||||||
bench("zrem", f)
|
bench("zrem", f)
|
||||||
}
|
}
|
||||||
|
|
||||||
func benchZIncr() {
|
func benchZIncr() {
|
||||||
f := func() {
|
f := func(c *ledis.Conn) {
|
||||||
n := atomic.AddInt64(&zsetIncrBase, 1)
|
n := atomic.AddInt64(&zsetIncrBase, 1)
|
||||||
waitBench("zincrby", "myzsetkey", 1, n)
|
waitBench(c, "ZINCRBY", "myzsetkey", 1, n)
|
||||||
}
|
}
|
||||||
|
|
||||||
bench("zincrby", f)
|
bench("zincrby", f)
|
||||||
}
|
}
|
||||||
|
|
||||||
func benchZRangeByScore() {
|
func benchZRangeByScore() {
|
||||||
f := func() {
|
f := func(c *ledis.Conn) {
|
||||||
waitBench("zrangebyscore", "myzsetkey", 0, rand.Int(), "withscores", "limit", rand.Int()%100, 100)
|
waitBench(c, "ZRANGEBYSCORE", "myzsetkey", 0, rand.Int(), "withscores", "limit", rand.Int()%100, 100)
|
||||||
}
|
}
|
||||||
|
|
||||||
bench("zrangebyscore", f)
|
bench("zrangebyscore", f)
|
||||||
}
|
}
|
||||||
|
|
||||||
func benchZRangeByRank() {
|
func benchZRangeByRank() {
|
||||||
f := func() {
|
f := func(c *ledis.Conn) {
|
||||||
waitBench("zrange", "myzsetkey", 0, rand.Int()%100)
|
waitBench(c, "ZRANGE", "myzsetkey", 0, rand.Int()%100)
|
||||||
}
|
}
|
||||||
|
|
||||||
bench("zrange", f)
|
bench("zrange", f)
|
||||||
}
|
}
|
||||||
|
|
||||||
func benchZRevRangeByScore() {
|
func benchZRevRangeByScore() {
|
||||||
f := func() {
|
f := func(c *ledis.Conn) {
|
||||||
waitBench("zrevrangebyscore", "myzsetkey", 0, rand.Int(), "withscores", "limit", rand.Int()%100, 100)
|
waitBench(c, "ZREVRANGEBYSCORE", "myzsetkey", 0, rand.Int(), "withscores", "limit", rand.Int()%100, 100)
|
||||||
}
|
}
|
||||||
|
|
||||||
bench("zrevrangebyscore", f)
|
bench("zrevrangebyscore", f)
|
||||||
}
|
}
|
||||||
|
|
||||||
func benchZRevRangeByRank() {
|
func benchZRevRangeByRank() {
|
||||||
f := func() {
|
f := func(c *ledis.Conn) {
|
||||||
waitBench("zrevrange", "myzsetkey", 0, rand.Int()%100)
|
waitBench(c, "ZREVRANGE", "myzsetkey", 0, rand.Int()%100)
|
||||||
}
|
}
|
||||||
|
|
||||||
bench("zrevrange", f)
|
bench("zrevrange", f)
|
||||||
|
@ -278,6 +276,11 @@ func main() {
|
||||||
cfg.WriteBufferSize = 10240
|
cfg.WriteBufferSize = 10240
|
||||||
client = ledis.NewClient(cfg)
|
client = ledis.NewClient(cfg)
|
||||||
|
|
||||||
|
for i := 0; i < *clients; i++ {
|
||||||
|
c := client.Get()
|
||||||
|
c.Close()
|
||||||
|
}
|
||||||
|
|
||||||
if *round <= 0 {
|
if *round <= 0 {
|
||||||
*round = 1
|
*round = 1
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue