record per-rpc latency instead of per-item
This commit is contained in:
Родитель
c0ead53d5e
Коммит
93ec6daf9c
|
@ -2,12 +2,11 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"google.golang.org/grpc/benchmark"
|
"google.golang.org/grpc/benchmark"
|
||||||
"google.golang.org/grpc/benchmark/stats"
|
"google.golang.org/grpc/benchmark/stats"
|
||||||
testpb "google.golang.org/grpc/interop/grpc_testing"
|
testpb "google.golang.org/grpc/interop/grpc_testing"
|
||||||
|
@ -32,14 +31,21 @@ func closeLoop() {
|
||||||
caller(tc)
|
caller(tc)
|
||||||
}
|
}
|
||||||
ch := make(chan int, *maxConcurrentRPCs*4)
|
ch := make(chan int, *maxConcurrentRPCs*4)
|
||||||
var wg sync.WaitGroup
|
var (
|
||||||
|
mu sync.Mutex
|
||||||
|
wg sync.WaitGroup
|
||||||
|
)
|
||||||
wg.Add(*maxConcurrentRPCs)
|
wg.Add(*maxConcurrentRPCs)
|
||||||
|
|
||||||
// Distribute RPCs over maxConcurrentCalls workers.
|
// Distribute RPCs over maxConcurrentCalls workers.
|
||||||
for i := 0; i < *maxConcurrentRPCs; i++ {
|
for i := 0; i < *maxConcurrentRPCs; i++ {
|
||||||
go func() {
|
go func() {
|
||||||
for _ = range ch {
|
for _ = range ch {
|
||||||
|
start := time.Now()
|
||||||
caller(tc)
|
caller(tc)
|
||||||
|
elapse := time.Since(start)
|
||||||
|
mu.Lock()
|
||||||
|
s.Add(elapse)
|
||||||
|
mu.Unlock()
|
||||||
}
|
}
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}()
|
}()
|
||||||
|
@ -52,10 +58,8 @@ func closeLoop() {
|
||||||
}()
|
}()
|
||||||
ok := true
|
ok := true
|
||||||
for ok {
|
for ok {
|
||||||
start := time.Now()
|
|
||||||
select {
|
select {
|
||||||
case ch <-0:
|
case ch <-0:
|
||||||
s.Add(time.Since(start))
|
|
||||||
case <-done:
|
case <-done:
|
||||||
ok = false
|
ok = false
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче