Skip to content

Commit

Permalink
Adding benchmarks for new pre-allocated buffer
Browse files Browse the repository at this point in the history
S3 GetBucketPolicy benchmark:

name                old time/op    new time/op    delta
GetBucketPolicy-12    12.7ms ± 2%     8.7ms ± 2%  -31.60%  (p=0.000 n=9+9)

name                old alloc/op   new alloc/op   delta
GetBucketPolicy-12    83.4MB ± 0%    50.4MB ± 0%  -39.60%  (p=0.000 n=10+10)

name                old allocs/op  new allocs/op  delta
GetBucketPolicy-12       256 ± 0%       216 ± 0%  -15.49%  (p=0.000 n=10+10)

Schemas GetCodeBindingSource benchmarks:

name                     old time/op    new time/op    delta
GetCodeBindingSource-12    10.8ms ± 3%     7.4ms ± 4%  -31.79%  (p=0.000 n=10+10)

name                     old alloc/op   new alloc/op   delta
GetCodeBindingSource-12    70.8MB ± 0%    37.8MB ± 0%  -46.64%  (p=0.000 n=10+10)

name                     old allocs/op  new allocs/op  delta
GetCodeBindingSource-12       241 ± 0%       200 ± 0%  -17.01%  (p=0.000 n=10+10)
  • Loading branch information
jasdel committed Jan 20, 2022
1 parent 67873f2 commit d95c2dd
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 0 deletions.
6 changes: 6 additions & 0 deletions service/internal/benchmark/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ require (
github.com/aws/aws-sdk-go-v2 v1.13.0
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.13.0
github.com/aws/aws-sdk-go-v2/service/lexruntimeservice v1.10.0
github.com/aws/aws-sdk-go-v2/service/s3 v1.24.0 // indirect
github.com/aws/aws-sdk-go-v2/service/schemas v1.12.0 // indirect
github.com/aws/smithy-go v1.10.0
)

Expand All @@ -23,3 +25,7 @@ replace github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding => ../../.
replace github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery => ../../../service/internal/endpoint-discovery/

replace github.com/aws/aws-sdk-go-v2/service/lexruntimeservice => ../../../service/lexruntimeservice/

replace github.com/aws/aws-sdk-go-v2/service/s3 => ../../../service/s3/

replace github.com/aws/aws-sdk-go-v2/service/schemas => ../../../service/schemas/
10 changes: 10 additions & 0 deletions service/internal/benchmark/go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
github.com/aws/aws-sdk-go v1.34.33 h1:ymkFm0rNPEOlgjyX3ojEd4zqzW6kGICBkqWs7LqgHtU=
github.com/aws/aws-sdk-go v1.34.33/go.mod h1:H7NKnBqNVzoTJpGfLrQkkD+ytBA93eiDYi/+8rV9s48=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.2.0 h1:scBthy70MB3m4LCMFaBcmYCyR2XWOz6MxSfdSu/+fQo=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.2.0/go.mod h1:oZHzg1OVbuCiRTY0oRPM+c2HQvwnFCGJwKeSqqAJ/yM=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.7.0 h1:4QAOB3KrvI1ApJK14sliGr3Ie2pjyvNypn/lfzDHfUw=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.7.0/go.mod h1:K/qPe6AP2TGYv4l6n7c88zh9jWBDf6nHhvg1fx/EWfU=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.11.0 h1:XAe+PDnaBELHr25qaJKfB415V4CKFWE8H+prUreql8k=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.11.0/go.mod h1:RMlgnt1LbOT2BxJ3cdw+qVz7KL84714LFkWtF6sLI7A=
github.com/aws/aws-sdk-go-v2/service/s3 v1.24.0 h1:REKac2iT0HYxUSzqOSuncnmsZnE3m4MlGfo1dOUN3vg=
github.com/aws/aws-sdk-go-v2/service/s3 v1.24.0/go.mod h1:oIUXg/5F0x0gy6nkwEnlxZboueddwPEKO6Xl+U6/3a0=
github.com/aws/aws-sdk-go-v2/service/schemas v1.12.0 h1:RfqnMV7sOkLxqUjltYY2FdsNaxuzqDrmp89/E9Jyj70=
github.com/aws/aws-sdk-go-v2/service/schemas v1.12.0/go.mod h1:znm7/t+tVXzCzcS3UOLaMsaB9xNkWIT/jvRUNRLB4A0=
github.com/aws/smithy-go v1.10.0 h1:gsoZQMNHnX+PaghNw4ynPsyGP7aUCqx5sY2dlPQsZ0w=
github.com/aws/smithy-go v1.10.0/go.mod h1:SObp3lf9smib00L/v3U2eAKG8FyQ7iLrJnQiAmR5n+E=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
Expand Down
1 change: 1 addition & 0 deletions service/internal/benchmark/s3/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package s3
66 changes: 66 additions & 0 deletions service/internal/benchmark/s3/get_bucket_policy_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package s3

import (
"context"
"io"
"io/ioutil"
"net/http"
"strings"
"testing"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/s3"
smithyhttp "github.com/aws/smithy-go/transport/http"
)

func init() {
var s strings.Builder
io.Copy(&s, io.LimitReader(byteReader('a'), 1024*1024*12))
largeStringPayload = s.String()
}

type byteReader byte

func (b byteReader) Read(p []byte) (int, error) {
for i := 0; i < len(p); i++ {
p[i] = byte(b)
}
return len(p), nil
}

var largeStringPayload string

func BenchmarkGetBucketPolicy(b *testing.B) {
client := s3.New(s3.Options{
Region: "us-west-2",
HTTPClient: smithyhttp.ClientDoFunc(
func(r *http.Request) (*http.Response, error) {
return newGetBucketPolicyHTTPResponse(largeStringPayload), nil
}),
})

ctx := context.Background()
params := s3.GetBucketPolicyInput{
Bucket: aws.String("fooBucket"),
}

b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := client.GetBucketPolicy(ctx, &params)
if err != nil {
b.Fatalf("failed to send: %v", err)
}
}

}

func newGetBucketPolicyHTTPResponse(payload string) *http.Response {
return &http.Response{
StatusCode: 200,
Header: map[string][]string{
"Content-Type": {"application/json"},
},
ContentLength: int64(len(payload)),
Body: ioutil.NopCloser(strings.NewReader(payload)),
}
}
1 change: 1 addition & 0 deletions service/internal/benchmark/schemas/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package schemas
56 changes: 56 additions & 0 deletions service/internal/benchmark/schemas/get_code_binding_source_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package schemas

import (
"bytes"
"context"
"io/ioutil"
"net/http"
"testing"

"github.com/aws/aws-sdk-go-v2/service/schemas"
"github.com/aws/smithy-go/ptr"
smithyhttp "github.com/aws/smithy-go/transport/http"
)

func init() {
largeBytePayload = make([]byte, 1024*1024*12)
}

var largeBytePayload []byte

func BenchmarkGetCodeBindingSource(b *testing.B) {
client := schemas.New(schemas.Options{
Region: "us-west-2",
HTTPClient: smithyhttp.ClientDoFunc(
func(r *http.Request) (*http.Response, error) {
return newGetCodeBindingSourceHTTPResponse(largeBytePayload), nil
}),
})

ctx := context.Background()
params := schemas.GetCodeBindingSourceInput{
Language: ptr.String("fooLanguage"),
RegistryName: ptr.String("fooRegistry"),
SchemaName: ptr.String("fooSchema"),
}

b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := client.GetCodeBindingSource(ctx, &params)
if err != nil {
b.Fatalf("failed to send: %v", err)
}
}

}

func newGetCodeBindingSourceHTTPResponse(payload []byte) *http.Response {
return &http.Response{
StatusCode: 200,
Header: map[string][]string{
"Content-Type": {"application/octet-stream"},
},
ContentLength: int64(len(payload)),
Body: ioutil.NopCloser(bytes.NewReader(payload)),
}
}

0 comments on commit d95c2dd

Please sign in to comment.