Skip to content

Commit

Permalink
fix review + rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
lyuxuan committed May 21, 2018
2 parents d0a817d + 3b7feb1 commit 7814b52
Show file tree
Hide file tree
Showing 92 changed files with 8,692 additions and 5,635 deletions.
33 changes: 33 additions & 0 deletions Documentation/concurrency.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Concurrency

In general, gRPC-go provides a concurrency-friendly API. What follows are some
guidelines.

## Clients

A [ClientConn][client-conn] can safely be accessed concurrently. Using
[helloworld][helloworld] as an example, one could share the `ClientConn` across
multiple goroutines to create multiple `GreeterClient` types. In this case, RPCs
would be sent in parallel.

## Streams

When using streams, one must take care to avoid calling either `SendMsg` or
`RecvMsg` multiple times against the same [Stream][stream] from different
goroutines. In other words, it's safe to have a goroutine calling `SendMsg` and
another goroutine calling `RecvMsg` on the same stream at the same time. But it
is not safe to call `SendMsg` on the same stream in different goroutines, or to
call `RecvMsg` on the same stream in different goroutines.

## Servers

Each RPC handler attached to a registered server will be invoked in its own
goroutine. For example, [SayHello][say-hello] will be invoked in its own
goroutine. The same is true for service handlers for streaming RPCs, as seen
in the route guide example [here][route-guide-stream].

[helloworld]: https://github.com/grpc/grpc-go/blob/master/examples/helloworld/greeter_client/main.go#L43
[client-conn]: https://godoc.org/google.golang.org/grpc#ClientConn
[stream]: https://godoc.org/google.golang.org/grpc#Stream
[say-hello]: https://github.com/grpc/grpc-go/blob/master/examples/helloworld/greeter_server/main.go#L41
[route-guide-stream]: https://github.com/grpc/grpc-go/blob/master/examples/route_guide/server/server.go#L126
6 changes: 3 additions & 3 deletions benchmark/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func closeLoopUnary() {
close(ch)
wg.Wait()
conn.Close()
grpclog.Println(s.String())
grpclog.Infoln(s.String())

}

Expand Down Expand Up @@ -155,7 +155,7 @@ func closeLoopStream() {
close(ch)
wg.Wait()
conn.Close()
grpclog.Println(s.String())
grpclog.Infoln(s.String())
}

func main() {
Expand All @@ -166,7 +166,7 @@ func main() {
if err != nil {
grpclog.Fatalf("Failed to listen: %v", err)
}
grpclog.Println("Client profiling address: ", lis.Addr().String())
grpclog.Infoln("Client profiling address: ", lis.Addr().String())
if err := http.Serve(lis, nil); err != nil {
grpclog.Fatalf("Failed to serve: %v", err)
}
Expand Down
Loading

0 comments on commit 7814b52

Please sign in to comment.