Close loop: Create multiple streams on one connection

This commit is contained in:
Menghan Li
2016-04-26 13:46:47 -07:00
parent 9a595041db
commit ad0677d6a9

View File

@ -224,30 +224,32 @@ func doCloseLoopStreamingBenchmark(h *stats.Histogram, conns []*grpc.ClientConn,
} else { } else {
doRPC = benchmark.DoStreamingRoundTrip doRPC = benchmark.DoStreamingRoundTrip
} }
streams := make([]testpb.BenchmarkService_StreamingCallClient, len(conns)) streams := make([]testpb.BenchmarkService_StreamingCallClient, len(conns)*rpcCount)
for ic, conn := range conns { for ic, conn := range conns {
for is := 0; is < rpcCount; is++ {
c := testpb.NewBenchmarkServiceClient(conn) c := testpb.NewBenchmarkServiceClient(conn)
s, err := c.StreamingCall(context.Background()) s, err := c.StreamingCall(context.Background())
if err != nil { if err != nil {
grpclog.Printf("%v.StreamingCall(_) = _, %v", c, err) grpclog.Printf("%v.StreamingCall(_) = _, %v", c, err)
} }
streams[ic] = s streams[ic*rpcCount+is] = s
for j := 0; j < 100/len(conns); j++ { for j := 0; j < 100/len(conns); j++ {
doRPC(streams[ic], reqSize, respSize) doRPC(streams[ic], reqSize, respSize)
} }
} }
}
var wg sync.WaitGroup var wg sync.WaitGroup
wg.Add(len(conns) * rpcCount) wg.Add(len(conns) * rpcCount)
var mu sync.Mutex var mu sync.Mutex
for ic, _ := range conns { for ic, _ := range conns {
for j := 0; j < rpcCount; j++ { for is := 0; is < rpcCount; is++ {
go func() { go func(ic, is int) {
defer wg.Done() defer wg.Done()
for { for {
done := make(chan bool) done := make(chan bool)
go func() { go func() {
start := time.Now() start := time.Now()
if err := doRPC(streams[ic], reqSize, respSize); err != nil { if err := doRPC(streams[ic*rpcCount+is], reqSize, respSize); err != nil {
done <- false done <- false
return return
} }
@ -264,7 +266,7 @@ func doCloseLoopStreamingBenchmark(h *stats.Histogram, conns []*grpc.ClientConn,
case <-done: case <-done:
} }
} }
}() }(ic, is)
} }
} }
grpclog.Printf("close loop done, count: %v", rpcCount) grpclog.Printf("close loop done, count: %v", rpcCount)