mirror of
https://github.com/golang/go
synced 2024-10-04 10:31:22 -06:00
net/rpc: use RunParallel in benchmarks
LGTM=bradfitz R=golang-codereviews, bradfitz CC=golang-codereviews https://golang.org/cl/68040044
This commit is contained in:
parent
0ef0d6cd7b
commit
b5705ed9ab
@ -594,7 +594,6 @@ func TestErrorAfterClientClose(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func benchmarkEndToEnd(dial func() (*Client, error), b *testing.B) {
|
func benchmarkEndToEnd(dial func() (*Client, error), b *testing.B) {
|
||||||
b.StopTimer()
|
|
||||||
once.Do(startServer)
|
once.Do(startServer)
|
||||||
client, err := dial()
|
client, err := dial()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -604,33 +603,24 @@ func benchmarkEndToEnd(dial func() (*Client, error), b *testing.B) {
|
|||||||
|
|
||||||
// Synchronous calls
|
// Synchronous calls
|
||||||
args := &Args{7, 8}
|
args := &Args{7, 8}
|
||||||
procs := runtime.GOMAXPROCS(-1)
|
b.ResetTimer()
|
||||||
N := int32(b.N)
|
|
||||||
var wg sync.WaitGroup
|
|
||||||
wg.Add(procs)
|
|
||||||
b.StartTimer()
|
|
||||||
|
|
||||||
for p := 0; p < procs; p++ {
|
b.RunParallel(func(pb *testing.PB) {
|
||||||
go func() {
|
reply := new(Reply)
|
||||||
reply := new(Reply)
|
for pb.Next() {
|
||||||
for atomic.AddInt32(&N, -1) >= 0 {
|
err := client.Call("Arith.Add", args, reply)
|
||||||
err := client.Call("Arith.Add", args, reply)
|
if err != nil {
|
||||||
if err != nil {
|
b.Fatalf("rpc error: Add: expected no error but got string %q", err.Error())
|
||||||
b.Fatalf("rpc error: Add: expected no error but got string %q", err.Error())
|
|
||||||
}
|
|
||||||
if reply.C != args.A+args.B {
|
|
||||||
b.Fatalf("rpc error: Add: expected %d got %d", reply.C, args.A+args.B)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
wg.Done()
|
if reply.C != args.A+args.B {
|
||||||
}()
|
b.Fatalf("rpc error: Add: expected %d got %d", reply.C, args.A+args.B)
|
||||||
}
|
}
|
||||||
wg.Wait()
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func benchmarkEndToEndAsync(dial func() (*Client, error), b *testing.B) {
|
func benchmarkEndToEndAsync(dial func() (*Client, error), b *testing.B) {
|
||||||
const MaxConcurrentCalls = 100
|
const MaxConcurrentCalls = 100
|
||||||
b.StopTimer()
|
|
||||||
once.Do(startServer)
|
once.Do(startServer)
|
||||||
client, err := dial()
|
client, err := dial()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -647,7 +637,7 @@ func benchmarkEndToEndAsync(dial func() (*Client, error), b *testing.B) {
|
|||||||
wg.Add(procs)
|
wg.Add(procs)
|
||||||
gate := make(chan bool, MaxConcurrentCalls)
|
gate := make(chan bool, MaxConcurrentCalls)
|
||||||
res := make(chan *Call, MaxConcurrentCalls)
|
res := make(chan *Call, MaxConcurrentCalls)
|
||||||
b.StartTimer()
|
b.ResetTimer()
|
||||||
|
|
||||||
for p := 0; p < procs; p++ {
|
for p := 0; p < procs; p++ {
|
||||||
go func() {
|
go func() {
|
||||||
|
Loading…
Reference in New Issue
Block a user