@@ -29,7 +29,7 @@ import (
2929 "github.com/stretchr/testify/require"
3030)
3131
32- func Benchmark (b * testing.B ) {
32+ func BenchmarkNode (b * testing.B ) {
3333 benchmarks := []struct {
3434 name string
3535 factory viewregistry.Factory
@@ -92,7 +92,7 @@ func Benchmark(b *testing.B) {
9292 })
9393
9494 // run all benchmarks via grpc view API
95- b .Run (fmt .Sprintf ("grpc /%s" , bm .name ), func (b * testing.B ) {
95+ b .Run (fmt .Sprintf ("grpcSingleConnection /%s" , bm .name ), func (b * testing.B ) {
9696 n , err := setupNode (b , nodeConfPath , namedFactory {
9797 name : bm .name ,
9898 factory : bm .factory ,
@@ -107,8 +107,9 @@ func Benchmark(b *testing.B) {
107107 }
108108
109109 // setup grpc client
110- cli , err := setupClient (b , clientConfPath )
110+ cli , closeF , err := setupClient (b , clientConfPath )
111111 require .NoError (b , err )
112+ b .Cleanup (closeF )
112113
113114 b .RunParallel (func (pb * testing.PB ) {
114115 for pb .Next () {
@@ -118,6 +119,34 @@ func Benchmark(b *testing.B) {
118119 })
119120 benchmark .ReportTPS (b )
120121 })
122+
123+ b .Run (fmt .Sprintf ("grpcMultiConnection/%s" , bm .name ), func (b * testing.B ) {
124+ n , err := setupNode (b , nodeConfPath , namedFactory {
125+ name : bm .name ,
126+ factory : bm .factory ,
127+ })
128+ require .NoError (b , err )
129+ b .Cleanup (n .Stop )
130+
131+ var in []byte
132+ if bm .params != nil {
133+ in , err = json .Marshal (bm .params )
134+ require .NoError (b , err )
135+ }
136+
137+ b .RunParallel (func (pb * testing.PB ) {
138+ // setup grpc client
139+ cli , closeF , err := setupClient (b , clientConfPath )
140+ require .NoError (b , err )
141+ b .Cleanup (closeF )
142+
143+ for pb .Next () {
144+ _ , err := cli .CallViewWithContext (b .Context (), bm .name , in )
145+ assert .NoError (b , err )
146+ }
147+ })
148+ benchmark .ReportTPS (b )
149+ })
121150 }
122151}
123152
@@ -165,22 +194,22 @@ type namedFactory struct {
165194 factory viewregistry.Factory
166195}
167196
168- func setupClient (tb testing.TB , confPath string ) (* benchmark.ViewClient , error ) {
197+ func setupClient (tb testing.TB , confPath string ) (* benchmark.ViewClient , func (), error ) {
169198 tb .Helper ()
170199
171200 config , err := view2 .ConfigFromFile (confPath )
172201 if err != nil {
173- return nil , err
202+ return nil , nil , err
174203 }
175204
176205 signer , err := client .NewX509SigningIdentity (config .SignerConfig .IdentityPath , config .SignerConfig .KeyPath )
177206 if err != nil {
178- return nil , err
207+ return nil , nil , err
179208 }
180209
181210 signerIdentity , err := signer .Serialize ()
182211 if err != nil {
183- return nil , err
212+ return nil , nil , err
184213 }
185214
186215 cc := & grpc.ConnectionConfig {
@@ -192,18 +221,18 @@ func setupClient(tb testing.TB, confPath string) (*benchmark.ViewClient, error)
192221
193222 grpcClient , err := grpc .CreateGRPCClient (cc )
194223 if err != nil {
195- return nil , err
224+ return nil , nil , err
196225 }
197226
198227 conn , err := grpcClient .NewConnection (config .Address )
199228 if err != nil {
200- return nil , err
229+ return nil , nil , err
201230 }
202231
203232 tlsCert := grpcClient .Certificate ()
204233 tlsCertHash , err := grpc .GetTLSCertHash (& tlsCert )
205234 if err != nil {
206- return nil , err
235+ return nil , nil , err
207236 }
208237
209238 vc := & benchmark.ViewClient {
@@ -212,6 +241,11 @@ func setupClient(tb testing.TB, confPath string) (*benchmark.ViewClient, error)
212241 TLSCertHash : tlsCertHash ,
213242 Client : protos .NewViewServiceClient (conn ),
214243 }
244+ closeFunc := func () {
245+ if err := conn .Close (); err != nil {
246+ fmt .Printf ("failed to close connection: %v\n " , err )
247+ }
248+ }
215249
216- return vc , nil
250+ return vc , closeFunc , nil
217251}
0 commit comments