5 * Copyright 2017 gRPC authors.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
30 "google.golang.org/grpc"
31 "google.golang.org/grpc/benchmark/stats"
34 func BenchmarkClient(b *testing.B) {
35 enableTrace := []bool{true, false} // run both enable and disable by default
36 // When set the latency to 0 (no delay), the result is slower than the real result with no delay
37 // because latency simulation section has extra operations
38 latency := []time.Duration{0, 40 * time.Millisecond} // if non-positive, no delay.
39 kbps := []int{0, 10240} // if non-positive, infinite
40 mtu := []int{0} // if non-positive, infinite
41 maxConcurrentCalls := []int{1, 8, 64, 512}
42 reqSizeBytes := []int{1, 1024 * 1024}
43 respSizeBytes := []int{1, 1024 * 1024}
44 featuresCurPos := make([]int, 7)
46 // 0:enableTracing 1:md 2:ltc 3:kbps 4:mtu 5:maxC 6:connCount 7:reqSize 8:respSize
47 featuresMaxPosition := []int{len(enableTrace), len(latency), len(kbps), len(mtu), len(maxConcurrentCalls), len(reqSizeBytes), len(respSizeBytes)}
48 initalPos := make([]int, len(featuresCurPos))
52 for !reflect.DeepEqual(featuresCurPos, initalPos) || start {
55 if !enableTrace[featuresCurPos[0]] {
59 benchFeature := stats.Features{
60 EnableTrace: enableTrace[featuresCurPos[0]],
61 Latency: latency[featuresCurPos[1]],
62 Kbps: kbps[featuresCurPos[2]],
63 Mtu: mtu[featuresCurPos[3]],
64 MaxConcurrentCalls: maxConcurrentCalls[featuresCurPos[4]],
65 ReqSizeBytes: reqSizeBytes[featuresCurPos[5]],
66 RespSizeBytes: respSizeBytes[featuresCurPos[6]],
69 grpc.EnableTracing = enableTrace[featuresCurPos[0]]
70 b.Run(fmt.Sprintf("Unary-%s-%s",
71 tracing, benchFeature.String()), func(b *testing.B) {
72 runUnary(b, benchFeature)
75 b.Run(fmt.Sprintf("Stream-%s-%s",
76 tracing, benchFeature.String()), func(b *testing.B) {
77 runStream(b, benchFeature)
79 AddOne(featuresCurPos, featuresMaxPosition)
83 func TestMain(m *testing.M) {
84 os.Exit(stats.RunTestMain(m))