@@ -8,7 +8,6 @@ package test
88
99import (
1010 "encoding/json"
11- "flag"
1211 "testing"
1312 "time"
1413
@@ -24,10 +23,8 @@ import (
2423 "go.opentelemetry.io/otel/trace/noop"
2524)
2625
27- var workload = flag .String ("workload" , "ecdsa" , "workload type: cpu or ecdsa" ) // ecdsa is the Default workload
28-
29- func BenchmarkGRPC (b * testing.B ) {
30- srvEndpoint := setupServer (b )
26+ func BenchmarkGRPCSingleConnectionCPU (b * testing.B ) {
27+ srvEndpoint := setupServer (b , "cpu" )
3128
3229 // we share a single connection among all client goroutines
3330 cli , closeF := setupClient (b , srvEndpoint )
@@ -43,7 +40,60 @@ func BenchmarkGRPC(b *testing.B) {
4340 benchmark .ReportTPS (b )
4441}
4542
46- func setupServer (tb testing.TB ) string {
43+ func BenchmarkGRPCMultiConnectionCPU (b * testing.B ) {
44+ srvEndpoint := setupServer (b , "cpu" )
45+
46+ b .RunParallel (func (pb * testing.PB ) {
47+ // each goroutine gets its own client + connection
48+ cli , closeF := setupClient (b , srvEndpoint )
49+ defer closeF ()
50+
51+ for pb .Next () {
52+ resp , err := cli .CallViewWithContext (b .Context (), "fid" , nil )
53+ require .NoError (b , err )
54+ require .NotNil (b , resp )
55+ }
56+ })
57+
58+ benchmark .ReportTPS (b )
59+ }
60+
61+ // --- ECDSA Workload Benchmarks ---
62+
63+ func BenchmarkGRPCSingleConnectionECDSA (b * testing.B ) {
64+ srvEndpoint := setupServer (b , "ecdsa" )
65+ cli , closeF := setupClient (b , srvEndpoint )
66+ defer closeF ()
67+
68+ b .ResetTimer ()
69+ b .RunParallel (func (pb * testing.PB ) {
70+ for pb .Next () {
71+ resp , err := cli .CallViewWithContext (b .Context (), "fid" , nil )
72+ require .NoError (b , err )
73+ require .NotNil (b , resp )
74+ }
75+ })
76+ benchmark .ReportTPS (b )
77+ }
78+
79+ func BenchmarkGRPCMultiConnectionECDSA (b * testing.B ) {
80+ srvEndpoint := setupServer (b , "ecdsa" )
81+
82+ b .ResetTimer ()
83+ b .RunParallel (func (pb * testing.PB ) {
84+ cli , closeF := setupClient (b , srvEndpoint )
85+ defer closeF ()
86+
87+ for pb .Next () {
88+ resp , err := cli .CallViewWithContext (b .Context (), "fid" , nil )
89+ require .NoError (b , err )
90+ require .NotNil (b , resp )
91+ }
92+ })
93+ benchmark .ReportTPS (b )
94+ }
95+
96+ func setupServer (tb testing.TB , workloadType string ) string {
4797 tb .Helper ()
4898
4999 mDefaultIdentity := view .Identity ("server identity" )
@@ -84,7 +134,7 @@ func setupServer(tb testing.TB) string {
84134 require .NotNil (tb , srv )
85135
86136 var v view.View
87- switch * workload {
137+ switch workloadType {
88138 case "cpu" :
89139 parms := & benchviews.CPUParams {N : 200000 }
90140 input , _ := json .Marshal (parms )
@@ -96,7 +146,7 @@ func setupServer(tb testing.TB) string {
96146 factory := & benchviews.ECDSASignViewFactory {}
97147 v , _ = factory .NewView (input )
98148 default :
99- tb .Fatalf ("unknown workload type: %s" , * workload )
149+ tb .Fatalf ("unknown workload type: %s" , workloadType )
100150 }
101151
102152 // our view manager
0 commit comments