Skip to content

Commit

Permalink
Merge pull request #357 from cloudwego/release/v0.2.0
Browse files Browse the repository at this point in the history
chore: release v0.2.0
  • Loading branch information
joway authored Feb 24, 2022
2 parents c8c358f + 153dea8 commit 98e6407
Show file tree
Hide file tree
Showing 38 changed files with 1,329 additions and 179 deletions.
2 changes: 1 addition & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ func (kc *kClient) invokeHandleEndpoint() (endpoint.Endpoint, error) {
if err = cli.Send(ctx, ri, sendMsg); err != nil {
return
}
if resp == nil || m.OneWay() {
if m.OneWay() {
cli.Recv(ctx, ri, nil)
return nil
}
Expand Down
22 changes: 22 additions & 0 deletions client/genericclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,31 @@ func NewClientWithServiceInfo(destService string, g generic.Generic, svcInfo *se
}
runtime.SetFinalizer(cli, (*genericServiceClient).Close)

svcInfo.GenericMethod = func(name string) serviceinfo.MethodInfo {
m := svcInfo.Methods[serviceinfo.GenericMethod]
n, err := g.GetMethod(nil, name)
if err != nil {
return m
}
return &methodInfo{
MethodInfo: m,
oneway: n.Oneway,
}
}

return cli, nil
}

// methodInfo is a wrapper to update the oneway flag of a service.MethodInfo.
type methodInfo struct {
serviceinfo.MethodInfo
oneway bool
}

func (m *methodInfo) OneWay() bool {
return m.oneway
}

// Client generic client
type Client interface {
generic.Closer
Expand Down
53 changes: 53 additions & 0 deletions client/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/cloudwego/kitex/pkg/loadbalance/lbcache"
"github.com/cloudwego/kitex/pkg/remote"
"github.com/cloudwego/kitex/pkg/remote/trans/netpollmux"
"github.com/cloudwego/kitex/pkg/remote/trans/nphttp2/grpc"
"github.com/cloudwego/kitex/pkg/retry"
"github.com/cloudwego/kitex/pkg/rpcinfo"
"github.com/cloudwego/kitex/pkg/stats"
Expand Down Expand Up @@ -357,3 +358,55 @@ func WithCircuitBreaker(s *circuitbreak.CBSuite) Option {
o.CBSuite = s
}}
}

// WithGRPCConnPoolSize sets the value for the client connection pool size.
// In general, you should not adjust the size of the connection pool, otherwise it may cause performance degradation.
// You should adjust the size according to the actual situation.
func WithGRPCConnPoolSize(s uint32) Option {
return Option{F: func(o *client.Options, di *utils.Slice) {
di.Push(fmt.Sprintf("WithGRPCConnPoolSize(%d)", s))
o.GRPCConnPoolSize = s
}}
}

// WithGRPCInitialWindowSize sets the value for initial window size on a grpc stream.
// The lower bound for window size is 64K and any value smaller than that will be ignored.
// It corresponds to the WithInitialWindowSize DialOption of gRPC.
func WithGRPCInitialWindowSize(s uint32) Option {
return Option{F: func(o *client.Options, di *utils.Slice) {
di.Push(fmt.Sprintf("WithGRPCInitialWindowSize(%d)", s))
o.GRPCConnectOpts.InitialWindowSize = s
}}
}

// WithGRPCInitialConnWindowSize sets the value for initial window size on a connection of grpc.
// The lower bound for window size is 64K and any value smaller than that will be ignored.
// It corresponds to the WithInitialConnWindowSize DialOption of gRPC.
func WithGRPCInitialConnWindowSize(s uint32) Option {
return Option{F: func(o *client.Options, di *utils.Slice) {
di.Push(fmt.Sprintf("WithGRPCInitialConnWindowSize(%d)", s))
o.GRPCConnectOpts.InitialConnWindowSize = s
}}
}

// WithGRPCMaxHeaderListSize returns a DialOption that specifies the maximum
// (uncompressed) size of header list that the client is prepared to accept.
// It corresponds to the WithMaxHeaderListSize DialOption of gRPC.
func WithGRPCMaxHeaderListSize(s uint32) Option {
return Option{F: func(o *client.Options, di *utils.Slice) {
di.Push(fmt.Sprintf("WithGRPCMaxHeaderListSize(%d)", s))
o.GRPCConnectOpts.MaxHeaderListSize = &s
}}
}

// WithGRPCKeepaliveParams returns a DialOption that specifies keepalive parameters for the client transport.
// It corresponds to the WithKeepaliveParams DialOption of gRPC.
func WithGRPCKeepaliveParams(kp grpc.ClientKeepalive) Option {
if kp.Time < grpc.KeepaliveMinPingTime {
kp.Time = grpc.KeepaliveMinPingTime
}
return Option{F: func(o *client.Options, di *utils.Slice) {
di.Push(fmt.Sprintf("WithGRPCKeepaliveParams(%+v)", kp))
o.GRPCConnectOpts.KeepaliveParams = kp
}}
}
2 changes: 1 addition & 1 deletion client/rpctimeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func rpcTimeoutMW(mwCtx context.Context) endpoint.Middleware {
e := panicToErr(ctx, panicInfo, ri)
done <- e
}
if !errors.Is(err, kerrors.ErrRPCFinish) {
if err == nil || !errors.Is(err, kerrors.ErrRPCFinish) {
// Don't regards ErrRPCFinish as normal error, it happens in retry scene,
// ErrRPCFinish means previous call returns first but is decoding.
close(done)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/bytedance/gopkg v0.0.0-20210910103821-e4efae9c17c3
github.com/cespare/xxhash v1.1.0
github.com/choleraehyq/pid v0.0.12
github.com/cloudwego/netpoll v0.1.2
github.com/cloudwego/netpoll v0.2.0
github.com/cloudwego/netpoll-http2 v0.0.6
github.com/cloudwego/thriftgo v0.1.2
github.com/json-iterator/go v1.1.11
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ github.com/choleraehyq/pid v0.0.12 h1:JLiTCsz2gStQZ3YWet+p9hktRnWzk7VJigpzvGV+I2
github.com/choleraehyq/pid v0.0.12/go.mod h1:uhzeFgxJZWQsZulelVQZwdASxQ9TIPZYL4TPkQMtL/U=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cloudwego/netpoll v0.1.0/go.mod h1:rZOiNI0FYjuvNybXKKhAPUja03loJi/cdv2F55AE6E8=
github.com/cloudwego/netpoll v0.1.2 h1:NSvqHfCmmR3g0ASshwAB0F2RJvXK8v7ToFmhWzh/ukY=
github.com/cloudwego/netpoll v0.1.2/go.mod h1:rZOiNI0FYjuvNybXKKhAPUja03loJi/cdv2F55AE6E8=
github.com/cloudwego/netpoll v0.2.0 h1:MmZX/jS6ozso86mnbVJ7fUO1hL4LOH/XngXN7Pn347A=
github.com/cloudwego/netpoll v0.2.0/go.mod h1:rZOiNI0FYjuvNybXKKhAPUja03loJi/cdv2F55AE6E8=
github.com/cloudwego/netpoll-http2 v0.0.6 h1:+jdkMKGj7ifRqWOdyT/hqzhXklmqh/H4lyOdrAVkI/U=
github.com/cloudwego/netpoll-http2 v0.0.6/go.mod h1:+bjPyu2Cd4GDzKa0IegPgp1hjMjpZ6/kXTsSjIsmUk8=
github.com/cloudwego/thriftgo v0.1.2 h1:AXpGJiWE3VggfiRHwA6raRJUIcjxliEIfJfGlvRiYUA=
Expand Down
9 changes: 8 additions & 1 deletion internal/client/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"github.com/cloudwego/kitex/pkg/remote/connpool"
"github.com/cloudwego/kitex/pkg/remote/trans/netpoll"
"github.com/cloudwego/kitex/pkg/remote/trans/nphttp2"
"github.com/cloudwego/kitex/pkg/remote/trans/nphttp2/grpc"
"github.com/cloudwego/kitex/pkg/retry"
"github.com/cloudwego/kitex/pkg/rpcinfo"
"github.com/cloudwego/kitex/pkg/serviceinfo"
Expand Down Expand Up @@ -98,6 +99,10 @@ type Options struct {
RetryContainer *retry.Container

CloseCallbacks []func() error

// GRPC
GRPCConnPoolSize uint32
GRPCConnectOpts *grpc.ConnectOptions
}

// Apply applies all options.
Expand Down Expand Up @@ -128,6 +133,8 @@ func NewOptions(opts []Option) *Options {
Events: event.NewQueue(event.MaxEventNum),

TracerCtl: &internal_stats.Controller{},

GRPCConnectOpts: new(grpc.ConnectOptions),
}
o.Apply(opts)
o.MetaHandlers = append(o.MetaHandlers, transmeta.MetainfoClientHandler)
Expand All @@ -150,7 +157,7 @@ func NewOptions(opts []Option) *Options {

func (o *Options) initRemoteOpt() {
if o.Configs.TransportProtocol()&transport.GRPC == transport.GRPC {
o.RemoteOpt.ConnPool = nphttp2.NewConnPool(o.Svr.ServiceName)
o.RemoteOpt.ConnPool = nphttp2.NewConnPool(o.Svr.ServiceName, o.GRPCConnPoolSize, *o.GRPCConnectOpts)
o.RemoteOpt.CliHandlerFactory = nphttp2.NewCliTransHandlerFactory()
}
if o.RemoteOpt.ConnPool == nil {
Expand Down
2 changes: 2 additions & 0 deletions internal/server/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/cloudwego/kitex/pkg/remote/codec/thrift"
"github.com/cloudwego/kitex/pkg/remote/trans/detection"
"github.com/cloudwego/kitex/pkg/remote/trans/netpoll"
"github.com/cloudwego/kitex/pkg/remote/trans/nphttp2/grpc"
"github.com/cloudwego/kitex/pkg/rpcinfo"
"github.com/cloudwego/kitex/pkg/serviceinfo"
"github.com/cloudwego/kitex/pkg/stats"
Expand Down Expand Up @@ -130,6 +131,7 @@ func newServerOption() *remote.ServerOption {
ExitWaitTime: defaultExitWaitTime,
MaxConnectionIdleTime: defaultConnectionIdleTime,
AcceptFailedDelayTime: defaultAcceptFailedDelayTime,
GRPCCfg: new(grpc.ServerConfig),
}
}

Expand Down
20 changes: 20 additions & 0 deletions licenses/LICENSE-gjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The MIT License (MIT)

Copyright (c) 2016 Josh Baker

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Loading

0 comments on commit 98e6407

Please sign in to comment.