Skip to content

Commit

Permalink
Ftr: add grpc max size support
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurenceLiZhixin committed Dec 6, 2021
1 parent 4ad68a0 commit 54460fb
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
30 changes: 30 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ type Option struct {
HeaderGroup string
HeaderAppVersion string

// grpc opts
GRPCMaxCallSendMsgSize int
GRPCMaxServerSendMsgSize int
GRPCMaxCallRecvMsgSize int
GRPCMaxServerRecvMsgSize int

// tracing
JaegerAddress string
JaegerServiceName string
Expand Down Expand Up @@ -166,6 +172,30 @@ func WithNumWorker(numWorkers uint32) OptionFunction {
}
}

func WithGRPCMaxCallSendMessageSize(maxCallSendMsgSize int) OptionFunction {
return func(o *Option) {
o.GRPCMaxCallSendMsgSize = maxCallSendMsgSize
}
}

func WithGRPCMaxCallRecvMessageSize(maxCallRecvMsgSize int) OptionFunction {
return func(o *Option) {
o.GRPCMaxCallRecvMsgSize = maxCallRecvMsgSize
}
}

func WithGRPCMaxServerSendMessageSize(maxServerSendMsgSize int) OptionFunction {
return func(o *Option) {
o.GRPCMaxServerSendMsgSize = maxServerSendMsgSize
}
}

func WithGRPCMaxServerRecvMessageSize(maxServerRecvMsgSize int) OptionFunction {
return func(o *Option) {
o.GRPCMaxServerRecvMsgSize = maxServerRecvMsgSize
}
}

func WithJaegerConfig(address, serviceName string, useAgent bool) OptionFunction {
return func(o *Option) {
o.JaegerAddress = address
Expand Down
9 changes: 9 additions & 0 deletions pkg/triple/dubbo3_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ func NewTripleClient(impl interface{}, opt *config.Option) (*TripleClient, error
)
}

defaultCallOpts := make([]grpc.CallOption, 0)
if opt.GRPCMaxCallSendMsgSize != 0 {
defaultCallOpts = append(defaultCallOpts, grpc.MaxCallSendMsgSize(opt.GRPCMaxCallSendMsgSize))
}
if opt.GRPCMaxCallRecvMsgSize != 0 {
defaultCallOpts = append(defaultCallOpts, grpc.MaxCallRecvMsgSize(opt.GRPCMaxCallRecvMsgSize))
}
dialOpts = append(dialOpts, grpc.WithDefaultCallOptions(defaultCallOpts...))

if opt.CodecType == constant.PBCodecName {
// put dubbo3 network logic to tripleConn, creat pb stub invoker
tripleClient.stubInvoker = reflect.ValueOf(getInvoker(impl, newTripleConn(opt.Location, dialOpts...)))
Expand Down
8 changes: 8 additions & 0 deletions pkg/triple/dubbo3_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/dubbogo/grpc-go/encoding/msgpack"
"github.com/dubbogo/grpc-go/encoding/proto_wrapper_api"
"github.com/dubbogo/grpc-go/encoding/raw_proto"

perrors "github.com/pkg/errors"
)

Expand Down Expand Up @@ -204,6 +205,13 @@ func newGrpcServerWithCodec(opt *config.Option) *grpc.Server {
)
}

if opt.GRPCMaxServerRecvMsgSize != 0 {
serverOpts = append(serverOpts, grpc.MaxRecvMsgSize(opt.GRPCMaxServerSendMsgSize))
}
if opt.GRPCMaxCallSendMsgSize != 0 {
serverOpts = append(serverOpts, grpc.MaxSendMsgSize(opt.GRPCMaxServerRecvMsgSize))
}

var err error
switch opt.CodecType {
case constant.PBCodecName:
Expand Down

0 comments on commit 54460fb

Please sign in to comment.