@@ -53,6 +53,7 @@ import (
53
53
"reflect"
54
54
"runtime"
55
55
"runtime/pprof"
56
+ "strconv"
56
57
"strings"
57
58
"sync"
58
59
"sync/atomic"
81
82
traceMode = flags .StringWithAllowedValues ("trace" , toggleModeOff ,
82
83
fmt .Sprintf ("Trace mode - One of: %v" , strings .Join (allToggleModes , ", " )), allToggleModes )
83
84
preloaderMode = flags .StringWithAllowedValues ("preloader" , toggleModeOff ,
84
- fmt .Sprintf ("Preloader mode - One of: %v" , strings .Join (allToggleModes , ", " )), allToggleModes )
85
+ fmt .Sprintf ("Preloader mode - One of: %v, preloader works only in streaming and unconstrained modes and will be ignored in unary mode" ,
86
+ strings .Join (allToggleModes , ", " )), allToggleModes )
85
87
channelzOn = flags .StringWithAllowedValues ("channelz" , toggleModeOff ,
86
88
fmt .Sprintf ("Channelz mode - One of: %v" , strings .Join (allToggleModes , ", " )), allToggleModes )
87
89
compressorMode = flags .StringWithAllowedValues ("compression" , compModeOff ,
@@ -401,20 +403,11 @@ func makeFuncUnary(bf stats.Features) (rpcCallFunc, rpcCleanupFunc) {
401
403
}
402
404
403
405
func makeFuncStream (bf stats.Features ) (rpcCallFunc , rpcCleanupFunc ) {
404
- clients , cleanup := makeClients (bf )
406
+ streams , req , cleanup := setupStream (bf , false )
405
407
406
- streams := make ([][]testgrpc.BenchmarkService_StreamingCallClient , bf .Connections )
407
- for cn := 0 ; cn < bf .Connections ; cn ++ {
408
- tc := clients [cn ]
409
- streams [cn ] = make ([]testgrpc.BenchmarkService_StreamingCallClient , bf .MaxConcurrentCalls )
410
- for pos := 0 ; pos < bf .MaxConcurrentCalls ; pos ++ {
411
-
412
- stream , err := tc .StreamingCall (context .Background ())
413
- if err != nil {
414
- logger .Fatalf ("%v.StreamingCall(_) = _, %v" , tc , err )
415
- }
416
- streams [cn ][pos ] = stream
417
- }
408
+ var preparedMsg [][]* grpc.PreparedMsg
409
+ if bf .EnablePreloader {
410
+ preparedMsg = prepareMessages (streams , req )
418
411
}
419
412
420
413
return func (cn , pos int ) {
@@ -426,24 +419,25 @@ func makeFuncStream(bf stats.Features) (rpcCallFunc, rpcCleanupFunc) {
426
419
if bf .RespPayloadCurve != nil {
427
420
respSizeBytes = bf .RespPayloadCurve .ChooseRandom ()
428
421
}
429
- streamCaller (streams [cn ][pos ], reqSizeBytes , respSizeBytes )
422
+ var req interface {}
423
+ if bf .EnablePreloader {
424
+ req = preparedMsg [cn ][pos ]
425
+ } else {
426
+ pl := bm .NewPayload (testpb .PayloadType_COMPRESSABLE , reqSizeBytes )
427
+ req = & testpb.SimpleRequest {
428
+ ResponseType : pl .Type ,
429
+ ResponseSize : int32 (respSizeBytes ),
430
+ Payload : pl ,
431
+ }
432
+ }
433
+ streamCaller (streams [cn ][pos ], req )
430
434
}, cleanup
431
435
}
432
436
433
437
func makeFuncUnconstrainedStreamPreloaded (bf stats.Features ) (rpcSendFunc , rpcRecvFunc , rpcCleanupFunc ) {
434
- streams , req , cleanup := setupUnconstrainedStream (bf )
438
+ streams , req , cleanup := setupStream (bf , true )
435
439
436
- preparedMsg := make ([][]* grpc.PreparedMsg , len (streams ))
437
- for cn , connStreams := range streams {
438
- preparedMsg [cn ] = make ([]* grpc.PreparedMsg , len (connStreams ))
439
- for pos , stream := range connStreams {
440
- preparedMsg [cn ][pos ] = & grpc.PreparedMsg {}
441
- err := preparedMsg [cn ][pos ].Encode (stream , req )
442
- if err != nil {
443
- logger .Fatalf ("%v.Encode(%v, %v) = %v" , preparedMsg [cn ][pos ], req , stream , err )
444
- }
445
- }
446
- }
440
+ preparedMsg := prepareMessages (streams , req )
447
441
448
442
return func (cn , pos int ) {
449
443
streams [cn ][pos ].SendMsg (preparedMsg [cn ][pos ])
@@ -453,7 +447,7 @@ func makeFuncUnconstrainedStreamPreloaded(bf stats.Features) (rpcSendFunc, rpcRe
453
447
}
454
448
455
449
func makeFuncUnconstrainedStream (bf stats.Features ) (rpcSendFunc , rpcRecvFunc , rpcCleanupFunc ) {
456
- streams , req , cleanup := setupUnconstrainedStream (bf )
450
+ streams , req , cleanup := setupStream (bf , true )
457
451
458
452
return func (cn , pos int ) {
459
453
streams [cn ][pos ].Send (req )
@@ -462,13 +456,19 @@ func makeFuncUnconstrainedStream(bf stats.Features) (rpcSendFunc, rpcRecvFunc, r
462
456
}, cleanup
463
457
}
464
458
465
- func setupUnconstrainedStream (bf stats.Features ) ([][]testgrpc.BenchmarkService_StreamingCallClient , * testpb.SimpleRequest , rpcCleanupFunc ) {
459
+ func setupStream (bf stats.Features , unconstrained bool ) ([][]testgrpc.BenchmarkService_StreamingCallClient , * testpb.SimpleRequest , rpcCleanupFunc ) {
466
460
clients , cleanup := makeClients (bf )
467
461
468
462
streams := make ([][]testgrpc.BenchmarkService_StreamingCallClient , bf .Connections )
469
- md := metadata .Pairs (benchmark .UnconstrainedStreamingHeader , "1" ,
470
- benchmark .UnconstrainedStreamingDelayHeader , bf .SleepBetweenRPCs .String ())
471
- ctx := metadata .NewOutgoingContext (context .Background (), md )
463
+ ctx := context .Background ()
464
+ if unconstrained {
465
+ md := metadata .Pairs (benchmark .UnconstrainedStreamingHeader , "1" , benchmark .UnconstrainedStreamingDelayHeader , bf .SleepBetweenRPCs .String ())
466
+ ctx = metadata .NewOutgoingContext (ctx , md )
467
+ }
468
+ if bf .EnablePreloader {
469
+ md := metadata .Pairs (benchmark .PreloadMsgSizeHeader , strconv .Itoa (bf .RespSizeBytes ), benchmark .UnconstrainedStreamingDelayHeader , bf .SleepBetweenRPCs .String ())
470
+ ctx = metadata .NewOutgoingContext (ctx , md )
471
+ }
472
472
for cn := 0 ; cn < bf .Connections ; cn ++ {
473
473
tc := clients [cn ]
474
474
streams [cn ] = make ([]testgrpc.BenchmarkService_StreamingCallClient , bf .MaxConcurrentCalls )
@@ -491,6 +491,20 @@ func setupUnconstrainedStream(bf stats.Features) ([][]testgrpc.BenchmarkService_
491
491
return streams , req , cleanup
492
492
}
493
493
494
+ func prepareMessages (streams [][]testgrpc.BenchmarkService_StreamingCallClient , req * testpb.SimpleRequest ) [][]* grpc.PreparedMsg {
495
+ preparedMsg := make ([][]* grpc.PreparedMsg , len (streams ))
496
+ for cn , connStreams := range streams {
497
+ preparedMsg [cn ] = make ([]* grpc.PreparedMsg , len (connStreams ))
498
+ for pos , stream := range connStreams {
499
+ preparedMsg [cn ][pos ] = & grpc.PreparedMsg {}
500
+ if err := preparedMsg [cn ][pos ].Encode (stream , req ); err != nil {
501
+ logger .Fatalf ("%v.Encode(%v, %v) = %v" , preparedMsg [cn ][pos ], req , stream , err )
502
+ }
503
+ }
504
+ }
505
+ return preparedMsg
506
+ }
507
+
494
508
// Makes a UnaryCall gRPC request using the given BenchmarkServiceClient and
495
509
// request and response sizes.
496
510
func unaryCaller (client testgrpc.BenchmarkServiceClient , reqSize , respSize int ) {
@@ -499,8 +513,8 @@ func unaryCaller(client testgrpc.BenchmarkServiceClient, reqSize, respSize int)
499
513
}
500
514
}
501
515
502
- func streamCaller (stream testgrpc.BenchmarkService_StreamingCallClient , reqSize , respSize int ) {
503
- if err := bm .DoStreamingRoundTrip (stream , reqSize , respSize ); err != nil {
516
+ func streamCaller (stream testgrpc.BenchmarkService_StreamingCallClient , req interface {} ) {
517
+ if err := bm .DoStreamingRoundTripPreloaded (stream , req ); err != nil {
504
518
logger .Fatalf ("DoStreamingRoundTrip failed: %v" , err )
505
519
}
506
520
}
@@ -790,6 +804,9 @@ func processFlags() *benchOpts {
790
804
if len (opts .features .reqSizeBytes ) != 0 {
791
805
log .Fatalf ("you may not specify -reqPayloadCurveFiles and -reqSizeBytes at the same time" )
792
806
}
807
+ if len (opts .features .enablePreloader ) != 0 {
808
+ log .Fatalf ("you may not specify -reqPayloadCurveFiles and -preloader at the same time" )
809
+ }
793
810
for _ , file := range * reqPayloadCurveFiles {
794
811
pc , err := stats .NewPayloadCurve (file )
795
812
if err != nil {
@@ -807,6 +824,9 @@ func processFlags() *benchOpts {
807
824
if len (opts .features .respSizeBytes ) != 0 {
808
825
log .Fatalf ("you may not specify -respPayloadCurveFiles and -respSizeBytes at the same time" )
809
826
}
827
+ if len (opts .features .enablePreloader ) != 0 {
828
+ log .Fatalf ("you may not specify -respPayloadCurveFiles and -preloader at the same time" )
829
+ }
810
830
for _ , file := range * respPayloadCurveFiles {
811
831
pc , err := stats .NewPayloadCurve (file )
812
832
if err != nil {
0 commit comments