MCPcopy
hub / github.com/grpc/grpc-go / createConns

Function createConns

benchmark/worker/benchmark_client.go:117–168  ·  view source on GitHub ↗

createConns creates connections according to given config. It returns the connections and corresponding function to close them. It returns non-nil error if there is anything wrong.

(config *testpb.ClientConfig)

Source from the content-addressed store, hash-verified

115// It returns the connections and corresponding function to close them.
116// It returns non-nil error if there is anything wrong.
117func createConns(config *testpb.ClientConfig) ([]*grpc.ClientConn, func(), error) {
118 opts := []grpc.DialOption{
119 grpc.WithWriteBufferSize(128 * 1024),
120 grpc.WithReadBufferSize(128 * 1024),
121 }
122
123 // Sanity check for client type.
124 switch config.ClientType {
125 case testpb.ClientType_SYNC_CLIENT:
126 case testpb.ClientType_ASYNC_CLIENT:
127 default:
128 return nil, nil, status.Errorf(codes.InvalidArgument, "unknown client type: %v", config.ClientType)
129 }
130
131 // Check and set security options.
132 if config.SecurityParams != nil {
133 if *caFile == "" {
134 *caFile = testdata.Path("ca.pem")
135 }
136 creds, err := credentials.NewClientTLSFromFile(*caFile, config.SecurityParams.ServerHostOverride)
137 if err != nil {
138 return nil, nil, status.Errorf(codes.InvalidArgument, "failed to create TLS credentials: %v", err)
139 }
140 opts = append(opts, grpc.WithTransportCredentials(creds))
141 } else {
142 opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
143 }
144
145 // Use byteBufCodec if it is required.
146 if config.PayloadConfig != nil {
147 switch config.PayloadConfig.Payload.(type) {
148 case *testpb.PayloadConfig_BytebufParams:
149 opts = append(opts, grpc.WithDefaultCallOptions(grpc.CallCustomCodec(byteBufCodec{})))
150 case *testpb.PayloadConfig_SimpleParams:
151 default:
152 return nil, nil, status.Errorf(codes.InvalidArgument, "unknown payload config: %v", config.PayloadConfig)
153 }
154 }
155
156 // Create connections.
157 connCount := int(config.ClientChannels)
158 conns := make([]*grpc.ClientConn, connCount)
159 for connIndex := 0; connIndex < connCount; connIndex++ {
160 conns[connIndex] = benchmark.NewClientConn(config.ServerTargets[connIndex%len(config.ServerTargets)], opts...)
161 }
162
163 return conns, func() {
164 for _, conn := range conns {
165 conn.Close()
166 }
167 }, nil
168}
169
170func performRPCs(ctx context.Context, config *testpb.ClientConfig, conns []*grpc.ClientConn, bc *benchmarkClient) error {
171 // Read payload size and type from config.

Callers 1

startBenchmarkClientFunction · 0.85

Calls 11

WithWriteBufferSizeFunction · 0.92
WithReadBufferSizeFunction · 0.92
ErrorfFunction · 0.92
PathFunction · 0.92
NewClientTLSFromFileFunction · 0.92
WithTransportCredentialsFunction · 0.92
NewCredentialsFunction · 0.92
WithDefaultCallOptionsFunction · 0.92
CallCustomCodecFunction · 0.92
NewClientConnFunction · 0.92
CloseMethod · 0.65

Tested by

no test coverage detected