forked from mirror/redis
fix: update some argument counts in pre-allocs
In some cases number of pre-allocated places in argument array is missing 1 or 2 elements, which results in re-allocation of twice as large array
This commit is contained in:
parent
47ac23e055
commit
f6974ebb5c
|
@ -4,6 +4,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -233,6 +234,45 @@ func BenchmarkZAdd(b *testing.B) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BenchmarkXRead(b *testing.B) {
|
||||||
|
ctx := context.Background()
|
||||||
|
client := benchmarkRedisClient(ctx, 10)
|
||||||
|
defer client.Close()
|
||||||
|
|
||||||
|
args := redis.XAddArgs{
|
||||||
|
Stream: "1",
|
||||||
|
ID: "*",
|
||||||
|
Values: map[string]string{"uno": "dos"},
|
||||||
|
}
|
||||||
|
|
||||||
|
lenStreams := 16
|
||||||
|
streams := make([]string, 0, lenStreams)
|
||||||
|
for i := 0; i < lenStreams; i++ {
|
||||||
|
streams = append(streams, strconv.Itoa(i))
|
||||||
|
}
|
||||||
|
for i := 0; i < lenStreams; i++ {
|
||||||
|
streams = append(streams, "0")
|
||||||
|
}
|
||||||
|
|
||||||
|
b.ReportAllocs()
|
||||||
|
b.ResetTimer()
|
||||||
|
|
||||||
|
b.RunParallel(func(pb *testing.PB) {
|
||||||
|
for pb.Next() {
|
||||||
|
client.XAdd(ctx, &args)
|
||||||
|
|
||||||
|
err := client.XRead(ctx, &redis.XReadArgs{
|
||||||
|
Streams: streams,
|
||||||
|
Count: 1,
|
||||||
|
Block: time.Second,
|
||||||
|
}).Err()
|
||||||
|
if err != nil {
|
||||||
|
b.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
var clientSink *redis.Client
|
var clientSink *redis.Client
|
||||||
|
|
||||||
func BenchmarkWithContext(b *testing.B) {
|
func BenchmarkWithContext(b *testing.B) {
|
||||||
|
|
|
@ -1778,7 +1778,7 @@ type XReadArgs struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c cmdable) XRead(ctx context.Context, a *XReadArgs) *XStreamSliceCmd {
|
func (c cmdable) XRead(ctx context.Context, a *XReadArgs) *XStreamSliceCmd {
|
||||||
args := make([]interface{}, 0, 5+len(a.Streams))
|
args := make([]interface{}, 0, 6+len(a.Streams))
|
||||||
args = append(args, "xread")
|
args = append(args, "xread")
|
||||||
|
|
||||||
keyPos := int8(1)
|
keyPos := int8(1)
|
||||||
|
@ -1860,7 +1860,7 @@ type XReadGroupArgs struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c cmdable) XReadGroup(ctx context.Context, a *XReadGroupArgs) *XStreamSliceCmd {
|
func (c cmdable) XReadGroup(ctx context.Context, a *XReadGroupArgs) *XStreamSliceCmd {
|
||||||
args := make([]interface{}, 0, 8+len(a.Streams))
|
args := make([]interface{}, 0, 10+len(a.Streams))
|
||||||
args = append(args, "xreadgroup", "group", a.Group, a.Consumer)
|
args = append(args, "xreadgroup", "group", a.Group, a.Consumer)
|
||||||
|
|
||||||
keyPos := int8(4)
|
keyPos := int8(4)
|
||||||
|
@ -1957,7 +1957,7 @@ func (c cmdable) XAutoClaimJustID(ctx context.Context, a *XAutoClaimArgs) *XAuto
|
||||||
}
|
}
|
||||||
|
|
||||||
func xAutoClaimArgs(ctx context.Context, a *XAutoClaimArgs) []interface{} {
|
func xAutoClaimArgs(ctx context.Context, a *XAutoClaimArgs) []interface{} {
|
||||||
args := make([]interface{}, 0, 9)
|
args := make([]interface{}, 0, 8)
|
||||||
args = append(args, "xautoclaim", a.Stream, a.Group, a.Consumer, formatMs(ctx, a.MinIdle), a.Start)
|
args = append(args, "xautoclaim", a.Stream, a.Group, a.Consumer, formatMs(ctx, a.MinIdle), a.Start)
|
||||||
if a.Count > 0 {
|
if a.Count > 0 {
|
||||||
args = append(args, "count", a.Count)
|
args = append(args, "count", a.Count)
|
||||||
|
@ -1989,7 +1989,7 @@ func (c cmdable) XClaimJustID(ctx context.Context, a *XClaimArgs) *StringSliceCm
|
||||||
}
|
}
|
||||||
|
|
||||||
func xClaimArgs(a *XClaimArgs) []interface{} {
|
func xClaimArgs(a *XClaimArgs) []interface{} {
|
||||||
args := make([]interface{}, 0, 4+len(a.Messages))
|
args := make([]interface{}, 0, 5+len(a.Messages))
|
||||||
args = append(args,
|
args = append(args,
|
||||||
"xclaim",
|
"xclaim",
|
||||||
a.Stream,
|
a.Stream,
|
||||||
|
|
Loading…
Reference in New Issue