Merge pull request #177 from iamqizhao/master
Print latency histogram for benchmarks
This commit is contained in:
Коммит
336d9e5ffb
|
@ -1,13 +1,17 @@
|
||||||
package benchmark
|
package benchmark
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"google.golang.org/grpc/benchmark/stats"
|
||||||
testpb "google.golang.org/grpc/interop/grpc_testing"
|
testpb "google.golang.org/grpc/interop/grpc_testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func run(b *testing.B, maxConcurrentCalls int, caller func(testpb.TestServiceClient)) {
|
func run(b *testing.B, maxConcurrentCalls int, caller func(testpb.TestServiceClient)) {
|
||||||
|
s := stats.AddStats(b, 38)
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
target, stopper := StartServer()
|
target, stopper := StartServer()
|
||||||
defer stopper()
|
defer stopper()
|
||||||
|
@ -23,8 +27,6 @@ func run(b *testing.B, maxConcurrentCalls int, caller func(testpb.TestServiceCli
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(maxConcurrentCalls)
|
wg.Add(maxConcurrentCalls)
|
||||||
|
|
||||||
b.StartTimer()
|
|
||||||
|
|
||||||
// Distribute the b.N calls over maxConcurrentCalls workers.
|
// Distribute the b.N calls over maxConcurrentCalls workers.
|
||||||
for i := 0; i < maxConcurrentCalls; i++ {
|
for i := 0; i < maxConcurrentCalls; i++ {
|
||||||
go func() {
|
go func() {
|
||||||
|
@ -35,11 +37,15 @@ func run(b *testing.B, maxConcurrentCalls int, caller func(testpb.TestServiceCli
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
|
b.StartTimer()
|
||||||
|
start := time.Now()
|
||||||
ch <- i
|
ch <- i
|
||||||
|
elapsed := time.Since(start)
|
||||||
|
b.StopTimer()
|
||||||
|
s.Add(elapsed)
|
||||||
}
|
}
|
||||||
close(ch)
|
close(ch)
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
b.StopTimer()
|
|
||||||
conn.Close()
|
conn.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,3 +68,7 @@ func BenchmarkClientSmallc64(b *testing.B) {
|
||||||
func BenchmarkClientSmallc512(b *testing.B) {
|
func BenchmarkClientSmallc512(b *testing.B) {
|
||||||
run(b, 512, smallCaller)
|
run(b, 512, smallCaller)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
os.Exit(stats.RunTestMain(m))
|
||||||
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче