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

Function StartServer

benchmark/benchmark.go:259–277  ·  view source on GitHub ↗

StartServer starts a gRPC server serving a benchmark service according to info. It returns a function to stop the server.

(info ServerInfo, opts ...grpc.ServerOption)

Source from the content-addressed store, hash-verified

257// StartServer starts a gRPC server serving a benchmark service according to info.
258// It returns a function to stop the server.
259func StartServer(info ServerInfo, opts ...grpc.ServerOption) func() {
260 s := grpc.NewServer(opts...)
261 switch info.Type {
262 case "protobuf":
263 testgrpc.RegisterBenchmarkServiceServer(s, &testServer{})
264 case "bytebuf":
265 respSize, ok := info.Metadata.(int32)
266 if !ok {
267 logger.Fatalf("failed to StartServer, invalid metadata: %v, for Type: %v", info.Metadata, info.Type)
268 }
269 testgrpc.RegisterBenchmarkServiceServer(s, &byteBufServer{respSize: respSize})
270 default:
271 logger.Fatalf("failed to StartServer, unknown Type: %v", info.Type)
272 }
273 go s.Serve(info.Listener)
274 return func() {
275 s.Stop()
276 }
277}
278
279// DoUnaryCall performs a unary RPC with given stub and request and response sizes.
280func DoUnaryCall(tc testgrpc.BenchmarkServiceClient, reqSize, respSize int) error {

Callers 3

makeClientsFunction · 0.92
startBenchmarkServerFunction · 0.92
mainFunction · 0.92

Calls 4

ServeMethod · 0.95
StopMethod · 0.95
NewServerFunction · 0.92
FatalfMethod · 0.65

Tested by

no test coverage detected