From 14f25982cbf6c4821fd7fa5a06224cedf1770850 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Fri, 24 Mar 2017 12:48:32 +0200 Subject: [PATCH 1/2] Remove manual strconv --- commands.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/commands.go b/commands.go index cac75fe..fb0e910 100644 --- a/commands.go +++ b/commands.go @@ -2,7 +2,6 @@ package redis import ( "io" - "strconv" "time" "github.com/go-redis/redis/internal" @@ -19,24 +18,24 @@ func usePrecise(dur time.Duration) bool { return dur < time.Second || dur%time.Second != 0 } -func formatMs(dur time.Duration) string { +func formatMs(dur time.Duration) int64 { if dur > 0 && dur < time.Millisecond { internal.Logf( "specified duration is %s, but minimal supported value is %s", dur, time.Millisecond, ) } - return strconv.FormatInt(int64(dur/time.Millisecond), 10) + return int64(dur / time.Millisecond) } -func formatSec(dur time.Duration) string { +func formatSec(dur time.Duration) int64 { if dur > 0 && dur < time.Second { internal.Logf( "specified duration is %s, but minimal supported value is %s", dur, time.Second, ) } - return strconv.FormatInt(int64(dur/time.Second), 10) + return int64(dur / time.Second) } type Cmdable interface { @@ -1340,7 +1339,7 @@ func (c *cmdable) ZInterStore(destination string, store ZStore, keys ...string) args := make([]interface{}, 3+len(keys)) args[0] = "zinterstore" args[1] = destination - args[2] = strconv.Itoa(len(keys)) + args[2] = len(keys) for i, key := range keys { args[3+i] = key } @@ -1536,7 +1535,7 @@ func (c *cmdable) ZUnionStore(dest string, store ZStore, keys ...string) *IntCmd args := make([]interface{}, 3+len(keys)) args[0] = "zunionstore" args[1] = dest - args[2] = strconv.Itoa(len(keys)) + args[2] = len(keys) for i, key := range keys { args[3+i] = key } @@ -1755,7 +1754,7 @@ func (c *cmdable) Eval(script string, keys []string, args ...interface{}) *Cmd { cmdArgs := make([]interface{}, 3+len(keys)+len(args)) cmdArgs[0] = "eval" cmdArgs[1] = script - cmdArgs[2] = strconv.Itoa(len(keys)) + cmdArgs[2] = len(keys) for i, key := range keys { cmdArgs[3+i] = key } @@ -1772,7 +1771,7 @@ func (c *cmdable) EvalSha(sha1 string, keys []string, args ...interface{}) *Cmd cmdArgs := make([]interface{}, 3+len(keys)+len(args)) cmdArgs[0] = "evalsha" cmdArgs[1] = sha1 - cmdArgs[2] = strconv.Itoa(len(keys)) + cmdArgs[2] = len(keys) for i, key := range keys { cmdArgs[3+i] = key } @@ -1984,7 +1983,7 @@ func (c *cmdable) ClusterAddSlots(slots ...int) *StatusCmd { args[0] = "cluster" args[1] = "addslots" for i, num := range slots { - args[2+i] = strconv.Itoa(num) + args[2+i] = num } cmd := NewStatusCmd(args...) c.process(cmd) From 5a99b806bd516fdaff2395019c2590357c15e544 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Fri, 24 Mar 2017 12:48:43 +0200 Subject: [PATCH 2/2] Add cluster benchmark --- cluster_test.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/cluster_test.go b/cluster_test.go index 53a3363..d9db897 100644 --- a/cluster_test.go +++ b/cluster_test.go @@ -1,6 +1,7 @@ package redis_test import ( + "bytes" "fmt" "net" "strconv" @@ -704,3 +705,36 @@ func BenchmarkRedisClusterPing(b *testing.B) { } }) } + +func BenchmarkRedisClusterSetString(b *testing.B) { + if testing.Short() { + b.Skip("skipping in short mode") + } + + cluster := &clusterScenario{ + ports: []string{"8220", "8221", "8222", "8223", "8224", "8225"}, + nodeIds: make([]string, 6), + processes: make(map[string]*redisProcess, 6), + clients: make(map[string]*redis.Client, 6), + } + + if err := startCluster(cluster); err != nil { + b.Fatal(err) + } + defer stopCluster(cluster) + + client := cluster.clusterClient(redisClusterOptions()) + defer client.Close() + + value := string(bytes.Repeat([]byte{'1'}, 10000)) + + b.ResetTimer() + + b.RunParallel(func(pb *testing.PB) { + for pb.Next() { + if err := client.Set("key", value, 0).Err(); err != nil { + b.Fatal(err) + } + } + }) +}