Skip to content

Commit 08c45bc

Browse files
committed
refactor: minor changes
1 parent f3c53df commit 08c45bc

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

benchmark/worker/benchmark_client.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,6 @@ func (bc *benchmarkClient) unaryLoop(ctx context.Context, conns []*grpc.ClientCo
264264
// Create histogram for each goroutine.
265265
idx := ic*rpcCountPerConn + j
266266
bc.lockingHistograms[idx].histogram = stats.NewHistogram(bc.histogramOptions)
267-
if ctx.Err() != nil {
268-
return
269-
}
270267
// Start goroutine on the created mutex and histogram.
271268
go func(idx int) {
272269
// TODO: do warm up if necessary.
@@ -277,7 +274,10 @@ func (bc *benchmarkClient) unaryLoop(ctx context.Context, conns []*grpc.ClientCo
277274
for {
278275
start := time.Now()
279276
if err := benchmark.DoUnaryCall(ctx, client, reqSize, respSize); err != nil {
280-
return
277+
if status.Code(err) == codes.Canceled {
278+
return
279+
}
280+
continue
281281
}
282282
elapse := time.Since(start)
283283
bc.lockingHistograms[idx].add(int64(elapse))
@@ -311,9 +311,6 @@ func (bc *benchmarkClient) streamingLoop(ctx context.Context, conns []*grpc.Clie
311311
idx := ic*rpcCountPerConn + j
312312
bc.lockingHistograms[idx].histogram = stats.NewHistogram(bc.histogramOptions)
313313
if poissonLambda == nil { // Closed loop.
314-
if stream.Context().Err() != nil {
315-
return
316-
}
317314
// Start goroutine on the created mutex and histogram.
318315
go func(idx int) {
319316
// TODO: do warm up if necessary.
@@ -342,7 +339,6 @@ func (bc *benchmarkClient) streamingLoop(ctx context.Context, conns []*grpc.Clie
342339
func (bc *benchmarkClient) poissonUnary(ctx context.Context, client testgrpc.BenchmarkServiceClient, idx int, reqSize int, respSize int, lambda float64) {
343340
go func() {
344341
start := time.Now()
345-
346342
if err := benchmark.DoUnaryCall(ctx, client, reqSize, respSize); err != nil {
347343
return
348344
}

benchmark/worker/main.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ func (s *workerServer) RunServer(stream testgrpc.WorkerService_RunServerServer)
139139

140140
func (s *workerServer) RunClient(stream testgrpc.WorkerService_RunClientServer) error {
141141
var bc *benchmarkClient
142+
ctx, cancel := context.WithCancel(stream.Context())
142143
defer func() {
144+
cancel()
143145
// Shut down benchmark client when stream ends.
144146
logger.Infof("shutting down benchmark client")
145147
if bc != nil {
@@ -163,9 +165,6 @@ func (s *workerServer) RunClient(stream testgrpc.WorkerService_RunClientServer)
163165
logger.Infof("client setup received when client already exists, shutting down the existing client")
164166
bc.shutdown()
165167
}
166-
167-
ctx, cancel := context.WithCancel(stream.Context())
168-
defer cancel()
169168
bc, err = startBenchmarkClient(ctx, t.Setup)
170169
if err != nil {
171170
return err

0 commit comments

Comments
 (0)