MCPcopy
hub / github.com/grpc/grpc-go / unaryLoop

Method unaryLoop

benchmark/worker/benchmark_client.go:259–294  ·  view source on GitHub ↗
(ctx context.Context, conns []*grpc.ClientConn, rpcCountPerConn int, reqSize int, respSize int, poissonLambda *float64)

Source from the content-addressed store, hash-verified

257}
258
259func (bc *benchmarkClient) unaryLoop(ctx context.Context, conns []*grpc.ClientConn, rpcCountPerConn int, reqSize int, respSize int, poissonLambda *float64) {
260 for ic, conn := range conns {
261 client := testgrpc.NewBenchmarkServiceClient(conn)
262 // For each connection, create rpcCountPerConn goroutines to do rpc.
263 for j := range rpcCountPerConn {
264 // Create histogram for each goroutine.
265 idx := ic*rpcCountPerConn + j
266 bc.lockingHistograms[idx].histogram = stats.NewHistogram(bc.histogramOptions)
267 // Start goroutine on the created mutex and histogram.
268 go func(idx int) {
269 // TODO: do warm up if necessary.
270 // Now relying on worker client to reserve time to do warm up.
271 // The worker client needs to wait for some time after client is created,
272 // before starting benchmark.
273 if poissonLambda == nil { // Closed loop.
274 for {
275 if ctx.Err() != nil {
276 break
277 }
278 start := time.Now()
279 if err := benchmark.DoUnaryCall(client, reqSize, respSize); err != nil {
280 continue
281 }
282 elapse := time.Since(start)
283 bc.lockingHistograms[idx].add(int64(elapse))
284 }
285 } else { // Open loop.
286 timeBetweenRPCs := time.Duration((rand.ExpFloat64() / *poissonLambda) * float64(time.Second))
287 time.AfterFunc(timeBetweenRPCs, func() {
288 bc.poissonUnary(client, idx, reqSize, respSize, *poissonLambda)
289 })
290 }
291 }(idx)
292 }
293 }
294}
295
296func (bc *benchmarkClient) streamingLoop(ctx context.Context, conns []*grpc.ClientConn, rpcCountPerConn int, reqSize int, respSize int, payloadType string, poissonLambda *float64) {
297 var doRPC func(testgrpc.BenchmarkService_StreamingCallClient, int, int) error

Callers 1

performRPCsFunction · 0.80

Calls 6

poissonUnaryMethod · 0.95
NewHistogramFunction · 0.92
DoUnaryCallFunction · 0.92
ErrMethod · 0.80
NowMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected