pubsub: limit grpc conns to 4

Large values of WithGRPCConnectionPool have caused outages. This CL restricts it
to a reasonable default. Users can increase this default by supplying their
own WithGRPCConnectionPool option in the NewClient call.

Note: increasing connections does not necessarily mean increased throughput.
HTTP/2 takes care of concurrency for you already (unlike HTTP/1), so for the
majority of usecases this setting is not useful.

Change-Id: Ibbd929d20a637a13b7556f3f8060d19370a3e27c
Reviewed-on: https://code-review.googlesource.com/c/gocloud/+/48430
Reviewed-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alex Hong <hongalex@google.com>
Reviewed-by: Kamal Aboul-Hosn <aboulhosn@google.com>
Reviewed-by: Cody Oss <codyoss@google.com>
diff --git a/pubsub/pubsub.go b/pubsub/pubsub.go
index 9dead69..a14f669 100644
--- a/pubsub/pubsub.go
+++ b/pubsub/pubsub.go
@@ -62,9 +62,13 @@
 		}
 		o = []option.ClientOption{option.WithGRPCConn(conn)}
 	} else {
+		numConns := runtime.GOMAXPROCS(0)
+		if numConns > 4 {
+			numConns = 4
+		}
 		o = []option.ClientOption{
 			// Create multiple connections to increase throughput.
-			option.WithGRPCConnectionPool(runtime.GOMAXPROCS(0)),
+			option.WithGRPCConnectionPool(numConns),
 			option.WithGRPCDialOption(grpc.WithKeepaliveParams(keepalive.ClientParameters{
 				Time: 5 * time.Minute,
 			})),