mirror of https://github.com/grpc/grpc-go.git
record per-rpc rtt in benchmark_test
This commit is contained in:
parent
93ec6daf9c
commit
f29a6f2d85
|
@ -24,25 +24,30 @@ func run(b *testing.B, maxConcurrentCalls int, caller func(testpb.TestServiceCli
|
|||
}
|
||||
|
||||
ch := make(chan int, maxConcurrentCalls*4)
|
||||
var wg sync.WaitGroup
|
||||
var (
|
||||
mu sync.Mutex
|
||||
wg sync.WaitGroup
|
||||
)
|
||||
wg.Add(maxConcurrentCalls)
|
||||
|
||||
// Distribute the b.N calls over maxConcurrentCalls workers.
|
||||
for i := 0; i < maxConcurrentCalls; i++ {
|
||||
go func() {
|
||||
for _ = range ch {
|
||||
start := time.Now()
|
||||
caller(tc)
|
||||
elapse := time.Since(start)
|
||||
mu.Lock()
|
||||
s.Add(elapse)
|
||||
mu.Unlock()
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
}
|
||||
for i := 0; i < b.N; i++ {
|
||||
b.StartTimer()
|
||||
start := time.Now()
|
||||
ch <- i
|
||||
elapsed := time.Since(start)
|
||||
b.StopTimer()
|
||||
s.Add(elapsed)
|
||||
}
|
||||
close(ch)
|
||||
wg.Wait()
|
||||
|
|
Loading…
Reference in New Issue