Rename genericServer to byteBufServer
This commit is contained in:
@ -107,16 +107,16 @@ func StartServer(addr string, opts ...grpc.ServerOption) (string, func()) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type genericTestServer struct {
|
type byteBufServer struct {
|
||||||
reqSize int32
|
reqSize int32
|
||||||
respSize int32
|
respSize int32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *genericTestServer) UnaryCall(ctx context.Context, in *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
|
func (s *byteBufServer) UnaryCall(ctx context.Context, in *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
|
||||||
return &testpb.SimpleResponse{}, nil
|
return &testpb.SimpleResponse{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *genericTestServer) StreamingCall(stream testpb.BenchmarkService_StreamingCallServer) error {
|
func (s *byteBufServer) StreamingCall(stream testpb.BenchmarkService_StreamingCallServer) error {
|
||||||
for {
|
for {
|
||||||
m := make([]byte, s.reqSize)
|
m := make([]byte, s.reqSize)
|
||||||
err := stream.(grpc.ServerStream).RecvMsg(m)
|
err := stream.(grpc.ServerStream).RecvMsg(m)
|
||||||
@ -132,15 +132,15 @@ func (s *genericTestServer) StreamingCall(stream testpb.BenchmarkService_Streami
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// StartGenericServer starts a benchmark service server that supports custom codec.
|
// StartbyteBufServer starts a benchmark service server that supports custom codec.
|
||||||
// It returns its listen address and a function to stop the server.
|
// It returns its listen address and a function to stop the server.
|
||||||
func StartGenericServer(addr string, reqSize, respSize int32, opts ...grpc.ServerOption) (string, func()) {
|
func StartByteBufServer(addr string, reqSize, respSize int32, opts ...grpc.ServerOption) (string, func()) {
|
||||||
lis, err := net.Listen("tcp", addr)
|
lis, err := net.Listen("tcp", addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
grpclog.Fatalf("Failed to listen: %v", err)
|
grpclog.Fatalf("Failed to listen: %v", err)
|
||||||
}
|
}
|
||||||
s := grpc.NewServer(opts...)
|
s := grpc.NewServer(opts...)
|
||||||
testpb.RegisterBenchmarkServiceServer(s, &genericTestServer{reqSize: reqSize, respSize: respSize})
|
testpb.RegisterBenchmarkServiceServer(s, &byteBufServer{reqSize: reqSize, respSize: respSize})
|
||||||
go s.Serve(lis)
|
go s.Serve(lis)
|
||||||
return lis.Addr().String(), func() {
|
return lis.Addr().String(), func() {
|
||||||
s.Stop()
|
s.Stop()
|
||||||
@ -178,8 +178,8 @@ func DoStreamingRoundTrip(stream testpb.BenchmarkService_StreamingCallClient, re
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DoGenericStreamingRoundTrip performs a round trip for a single streaming rpc, using custom codec.
|
// DoByteBufStreamingRoundTrip performs a round trip for a single streaming rpc, using custom codec.
|
||||||
func DoGenericStreamingRoundTrip(stream testpb.BenchmarkService_StreamingCallClient, reqSize, respSize int) error {
|
func DoByteBufStreamingRoundTrip(stream testpb.BenchmarkService_StreamingCallClient, reqSize, respSize int) error {
|
||||||
if err := stream.(grpc.ClientStream).SendMsg(make([]byte, reqSize)); err != nil {
|
if err := stream.(grpc.ClientStream).SendMsg(make([]byte, reqSize)); err != nil {
|
||||||
return grpc.Errorf(grpc.Code(err), "StreamingCall(_).(ClientStream).SendMsg: %v", grpc.ErrorDesc(err))
|
return grpc.Errorf(grpc.Code(err), "StreamingCall(_).(ClientStream).SendMsg: %v", grpc.ErrorDesc(err))
|
||||||
}
|
}
|
||||||
|
@ -237,7 +237,7 @@ func (bc *benchmarkClient) doCloseLoopUnaryBenchmark(conns []*grpc.ClientConn, r
|
|||||||
func (bc *benchmarkClient) doCloseLoopStreamingBenchmark(conns []*grpc.ClientConn, rpcCountPerConn int, reqSize int, respSize int, payloadType string) {
|
func (bc *benchmarkClient) doCloseLoopStreamingBenchmark(conns []*grpc.ClientConn, rpcCountPerConn int, reqSize int, respSize int, payloadType string) {
|
||||||
var doRPC func(testpb.BenchmarkService_StreamingCallClient, int, int) error
|
var doRPC func(testpb.BenchmarkService_StreamingCallClient, int, int) error
|
||||||
if payloadType == "bytebuf" {
|
if payloadType == "bytebuf" {
|
||||||
doRPC = benchmark.DoGenericStreamingRoundTrip
|
doRPC = benchmark.DoByteBufStreamingRoundTrip
|
||||||
} else {
|
} else {
|
||||||
doRPC = benchmark.DoStreamingRoundTrip
|
doRPC = benchmark.DoStreamingRoundTrip
|
||||||
}
|
}
|
||||||
|
@ -114,7 +114,7 @@ func startBenchmarkServerWithSetup(setup *testpb.ServerConfig, serverPort int) (
|
|||||||
switch payload := setup.PayloadConfig.Payload.(type) {
|
switch payload := setup.PayloadConfig.Payload.(type) {
|
||||||
case *testpb.PayloadConfig_BytebufParams:
|
case *testpb.PayloadConfig_BytebufParams:
|
||||||
opts = append(opts, grpc.CustomCodec(byteBufCodec{}))
|
opts = append(opts, grpc.CustomCodec(byteBufCodec{}))
|
||||||
addr, close = benchmark.StartGenericServer(":"+strconv.Itoa(port), payload.BytebufParams.ReqSize, payload.BytebufParams.RespSize, opts...)
|
addr, close = benchmark.StartByteBufServer(":"+strconv.Itoa(port), payload.BytebufParams.ReqSize, payload.BytebufParams.RespSize, opts...)
|
||||||
case *testpb.PayloadConfig_SimpleParams:
|
case *testpb.PayloadConfig_SimpleParams:
|
||||||
addr, close = benchmark.StartServer(":"+strconv.Itoa(port), opts...)
|
addr, close = benchmark.StartServer(":"+strconv.Itoa(port), opts...)
|
||||||
case *testpb.PayloadConfig_ComplexParams:
|
case *testpb.PayloadConfig_ComplexParams:
|
||||||
|
Reference in New Issue
Block a user