Skip to content

Commit d6b87c8

Browse files
authored
Add benchmark tests for gRPC instrumentation (#296)
* Add benchmark test to grpc instrumentation * Set instrumentation name as const in testing * Update to v0.11.0 otel * Update Changelog * lint
1 parent a586915 commit d6b87c8

File tree

4 files changed

+118
-0
lines changed

4 files changed

+118
-0
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
88

99
## [Unreleased]
1010

11+
### Added
12+
13+
- Benchmark tests for the gRPC instrumentation. (#296)
14+
1115
## [0.11.0] - 2020-08-25
1216

1317
### Added
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
// Copyright The OpenTelemetry Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package grpc_test
16+
17+
import (
18+
"context"
19+
"net"
20+
"testing"
21+
22+
"google.golang.org/grpc"
23+
"google.golang.org/grpc/interop"
24+
pb "google.golang.org/grpc/interop/grpc_testing"
25+
"google.golang.org/grpc/test/bufconn"
26+
27+
otelgrpc "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc"
28+
"go.opentelemetry.io/otel/api/trace/tracetest"
29+
)
30+
31+
const (
32+
bufSize = 2048
33+
instName = "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc"
34+
)
35+
36+
var tracer = tracetest.NewProvider().Tracer(instName)
37+
38+
func benchmark(b *testing.B, cOpt []grpc.DialOption, sOpt []grpc.ServerOption) {
39+
l := bufconn.Listen(bufSize)
40+
defer l.Close()
41+
42+
s := grpc.NewServer(sOpt...)
43+
pb.RegisterTestServiceServer(s, interop.NewTestServer())
44+
go func() {
45+
if err := s.Serve(l); err != nil {
46+
panic(err)
47+
}
48+
}()
49+
defer s.Stop()
50+
51+
ctx := context.Background()
52+
dial := func(context.Context, string) (net.Conn, error) { return l.Dial() }
53+
conn, err := grpc.DialContext(
54+
ctx,
55+
"bufnet",
56+
append([]grpc.DialOption{
57+
grpc.WithContextDialer(dial),
58+
grpc.WithInsecure(),
59+
}, cOpt...)...,
60+
)
61+
if err != nil {
62+
b.Fatalf("Failed to dial bufnet: %v", err)
63+
}
64+
defer conn.Close()
65+
client := pb.NewTestServiceClient(conn)
66+
67+
b.ReportAllocs()
68+
b.ResetTimer()
69+
70+
for n := 0; n < b.N; n++ {
71+
interop.DoEmptyUnaryCall(client)
72+
interop.DoLargeUnaryCall(client)
73+
interop.DoClientStreaming(client)
74+
interop.DoServerStreaming(client)
75+
interop.DoPingPong(client)
76+
interop.DoEmptyStream(client)
77+
}
78+
79+
b.StopTimer()
80+
}
81+
82+
func BenchmarkNoInstrumentation(b *testing.B) {
83+
benchmark(b, nil, nil)
84+
}
85+
86+
func BenchmarkUnaryServerInterceptor(b *testing.B) {
87+
benchmark(b, nil, []grpc.ServerOption{
88+
grpc.UnaryInterceptor(otelgrpc.UnaryServerInterceptor(tracer)),
89+
})
90+
}
91+
92+
func BenchmarkStreamServerInterceptor(b *testing.B) {
93+
benchmark(b, nil, []grpc.ServerOption{
94+
grpc.StreamInterceptor(otelgrpc.StreamServerInterceptor(tracer)),
95+
})
96+
}
97+
98+
func BenchmarkUnaryClientInterceptor(b *testing.B) {
99+
benchmark(b, []grpc.DialOption{
100+
grpc.WithUnaryInterceptor(otelgrpc.UnaryClientInterceptor(tracer)),
101+
}, nil)
102+
}
103+
104+
func BenchmarkStreamClientInterceptor(b *testing.B) {
105+
benchmark(b, []grpc.DialOption{
106+
grpc.WithStreamInterceptor(otelgrpc.StreamClientInterceptor(tracer)),
107+
}, nil)
108+
}

instrumentation/google.golang.org/grpc/example/go.sum

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
cloud.google.com/go v0.26.0 h1:e0WKqKTd5BnrG8aKH3J3h+QvEIQtSUcf2n5UZ5ZgLtQ=
12
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
23
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
34
github.com/DataDog/sketches-go v0.0.1 h1:RtG+76WKgZuz6FIaGsjoPePmadDBkuD/KC6+ZWu78b8=
@@ -57,6 +58,7 @@ golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn
5758
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
5859
golang.org/x/net v0.0.0-20200707034311-ab3426394381 h1:VXak5I6aEWmAXeQjA+QSZzlgNrpq9mjcfDemuexIKsU=
5960
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
61+
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be h1:vEDujvNQGv4jgYKudGeI/+DAX4Jffq6hpD55MmoEvKs=
6062
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
6163
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
6264
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -75,6 +77,7 @@ golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBn
7577
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
7678
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
7779
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
80+
google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508=
7881
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
7982
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
8083
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 h1:gSJIx1SDwno+2ElGhA4+qG2zF97qiUzTM+rQ0klBOcE=

instrumentation/google.golang.org/grpc/go.sum

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
cloud.google.com/go v0.26.0 h1:e0WKqKTd5BnrG8aKH3J3h+QvEIQtSUcf2n5UZ5ZgLtQ=
12
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
23
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
34
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
@@ -44,6 +45,7 @@ golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73r
4445
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
4546
golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628=
4647
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
48+
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be h1:vEDujvNQGv4jgYKudGeI/+DAX4Jffq6hpD55MmoEvKs=
4749
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
4850
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
4951
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -60,6 +62,7 @@ golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBn
6062
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
6163
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
6264
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
65+
google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508=
6366
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
6467
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
6568
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 h1:gSJIx1SDwno+2ElGhA4+qG2zF97qiUzTM+rQ0klBOcE=

0 commit comments

Comments
 (0)