Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ftr: Add grpc max message size config #824

Merged
merged 3 commits into from
Nov 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions common/constant/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const (
GROUP_KEY = "group"
VERSION_KEY = "version"
INTERFACE_KEY = "interface"
MESSAGE_SIZE_KEY = "message_size"
PATH_KEY = "path"
SERVICE_KEY = "service"
METHODS_KEY = "methods"
Expand Down
2 changes: 2 additions & 0 deletions config/service_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type ServiceConfig struct {
Auth string `yaml:"auth" json:"auth,omitempty" property:"auth"`
ParamSign string `yaml:"param.sign" json:"param.sign,omitempty" property:"param.sign"`
Tag string `yaml:"tag" json:"tag,omitempty" property:"tag"`
GrpcMaxMessageSize int `default:"4" yaml:"max_message_size" json:"max_message_size,omitempty"`

Protocols map[string]*ProtocolConfig
unexported *atomic.Bool
Expand Down Expand Up @@ -271,6 +272,7 @@ func (c *ServiceConfig) getUrlMap() url.Values {
urlMap.Set(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER))
urlMap.Set(constant.RELEASE_KEY, "dubbo-golang-"+constant.Version)
urlMap.Set(constant.SIDE_KEY, (common.RoleType(common.PROVIDER)).Role())
urlMap.Set(constant.MESSAGE_SIZE_KEY, strconv.Itoa(c.GrpcMaxMessageSize))
// todo: move
urlMap.Set(constant.SERIALIZATION_KEY, c.Serialization)
// application info
Expand Down
7 changes: 6 additions & 1 deletion protocol/grpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package grpc

import (
"reflect"
"strconv"
)

import (
Expand Down Expand Up @@ -93,9 +94,13 @@ func NewClient(url common.URL) *Client {
// if global trace instance was set , it means trace function enabled. If not , will return Nooptracer
tracer := opentracing.GlobalTracer()
dailOpts := make([]grpc.DialOption, 0, 4)
maxMessageSize, _ := strconv.Atoi(url.GetParam(constant.MESSAGE_SIZE_KEY, "4"))
dailOpts = append(dailOpts, grpc.WithInsecure(), grpc.WithBlock(), grpc.WithUnaryInterceptor(
otgrpc.OpenTracingClientInterceptor(tracer, otgrpc.LogPayloads())),
grpc.WithDefaultCallOptions(grpc.CallContentSubtype(clientConf.ContentSubType)))
grpc.WithDefaultCallOptions(
grpc.CallContentSubtype(clientConf.ContentSubType),
grpc.MaxCallRecvMsgSize(1024*1024*maxMessageSize),
grpc.MaxCallSendMsgSize(1024*1024*maxMessageSize)))
conn, err := grpc.Dial(url.Location, dailOpts...)
if err != nil {
panic(err)
Expand Down
4 changes: 4 additions & 0 deletions protocol/grpc/grpc_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
package grpc

import (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

split it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

"strconv"
"sync"
)

import (
"github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/common/extension"
"github.com/apache/dubbo-go/common/logger"
"github.com/apache/dubbo-go/protocol"
Expand Down Expand Up @@ -76,7 +78,9 @@ func (gp *GrpcProtocol) openServer(url common.URL) {
gp.serverLock.Lock()
_, ok = gp.serverMap[url.Location]
if !ok {
grpcMessageSize, _ := strconv.Atoi(url.GetParam(constant.MESSAGE_SIZE_KEY, "4"))
srv := NewServer()
srv.SetBufferSize(grpcMessageSize)
gp.serverMap[url.Location] = srv
srv.Start(url)
}
Expand Down
9 changes: 8 additions & 1 deletion protocol/grpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
// Server is a gRPC server
type Server struct {
grpcServer *grpc.Server
bufferSize int
}

// NewServer creates a new server
Expand All @@ -57,6 +58,10 @@ type DubboGrpcService interface {
ServiceDesc() *grpc.ServiceDesc
}

func (s *Server) SetBufferSize(n int) {
s.bufferSize = n
}

// Start gRPC server with @url
func (s *Server) Start(url common.URL) {
var (
Expand All @@ -72,7 +77,9 @@ func (s *Server) Start(url common.URL) {
// if global trace instance was set, then server tracer instance can be get. If not , will return Nooptracer
tracer := opentracing.GlobalTracer()
server := grpc.NewServer(
grpc.UnaryInterceptor(otgrpc.OpenTracingServerInterceptor(tracer)))
grpc.UnaryInterceptor(otgrpc.OpenTracingServerInterceptor(tracer)),
grpc.MaxRecvMsgSize(1024*1024*s.bufferSize),
grpc.MaxSendMsgSize(1024*1024*s.bufferSize))

key := url.GetParam(constant.BEAN_NAME_KEY, "")
service := config.GetProviderService(key)
Expand Down