Skip to content

Commit 98e6407

Browse files
authored
Merge pull request #357 from cloudwego/release/v0.2.0
chore: release v0.2.0
2 parents c8c358f + 153dea8 commit 98e6407

38 files changed

+1329
-179
lines changed

client/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ func (kc *kClient) invokeHandleEndpoint() (endpoint.Endpoint, error) {
353353
if err = cli.Send(ctx, ri, sendMsg); err != nil {
354354
return
355355
}
356-
if resp == nil || m.OneWay() {
356+
if m.OneWay() {
357357
cli.Recv(ctx, ri, nil)
358358
return nil
359359
}

client/genericclient/client.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,31 @@ func NewClientWithServiceInfo(destService string, g generic.Generic, svcInfo *se
5252
}
5353
runtime.SetFinalizer(cli, (*genericServiceClient).Close)
5454

55+
svcInfo.GenericMethod = func(name string) serviceinfo.MethodInfo {
56+
m := svcInfo.Methods[serviceinfo.GenericMethod]
57+
n, err := g.GetMethod(nil, name)
58+
if err != nil {
59+
return m
60+
}
61+
return &methodInfo{
62+
MethodInfo: m,
63+
oneway: n.Oneway,
64+
}
65+
}
66+
5567
return cli, nil
5668
}
5769

70+
// methodInfo is a wrapper to update the oneway flag of a service.MethodInfo.
71+
type methodInfo struct {
72+
serviceinfo.MethodInfo
73+
oneway bool
74+
}
75+
76+
func (m *methodInfo) OneWay() bool {
77+
return m.oneway
78+
}
79+
5880
// Client generic client
5981
type Client interface {
6082
generic.Closer

client/option.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"github.com/cloudwego/kitex/pkg/loadbalance/lbcache"
3636
"github.com/cloudwego/kitex/pkg/remote"
3737
"github.com/cloudwego/kitex/pkg/remote/trans/netpollmux"
38+
"github.com/cloudwego/kitex/pkg/remote/trans/nphttp2/grpc"
3839
"github.com/cloudwego/kitex/pkg/retry"
3940
"github.com/cloudwego/kitex/pkg/rpcinfo"
4041
"github.com/cloudwego/kitex/pkg/stats"
@@ -357,3 +358,55 @@ func WithCircuitBreaker(s *circuitbreak.CBSuite) Option {
357358
o.CBSuite = s
358359
}}
359360
}
361+
362+
// WithGRPCConnPoolSize sets the value for the client connection pool size.
363+
// In general, you should not adjust the size of the connection pool, otherwise it may cause performance degradation.
364+
// You should adjust the size according to the actual situation.
365+
func WithGRPCConnPoolSize(s uint32) Option {
366+
return Option{F: func(o *client.Options, di *utils.Slice) {
367+
di.Push(fmt.Sprintf("WithGRPCConnPoolSize(%d)", s))
368+
o.GRPCConnPoolSize = s
369+
}}
370+
}
371+
372+
// WithGRPCInitialWindowSize sets the value for initial window size on a grpc stream.
373+
// The lower bound for window size is 64K and any value smaller than that will be ignored.
374+
// It corresponds to the WithInitialWindowSize DialOption of gRPC.
375+
func WithGRPCInitialWindowSize(s uint32) Option {
376+
return Option{F: func(o *client.Options, di *utils.Slice) {
377+
di.Push(fmt.Sprintf("WithGRPCInitialWindowSize(%d)", s))
378+
o.GRPCConnectOpts.InitialWindowSize = s
379+
}}
380+
}
381+
382+
// WithGRPCInitialConnWindowSize sets the value for initial window size on a connection of grpc.
383+
// The lower bound for window size is 64K and any value smaller than that will be ignored.
384+
// It corresponds to the WithInitialConnWindowSize DialOption of gRPC.
385+
func WithGRPCInitialConnWindowSize(s uint32) Option {
386+
return Option{F: func(o *client.Options, di *utils.Slice) {
387+
di.Push(fmt.Sprintf("WithGRPCInitialConnWindowSize(%d)", s))
388+
o.GRPCConnectOpts.InitialConnWindowSize = s
389+
}}
390+
}
391+
392+
// WithGRPCMaxHeaderListSize returns a DialOption that specifies the maximum
393+
// (uncompressed) size of header list that the client is prepared to accept.
394+
// It corresponds to the WithMaxHeaderListSize DialOption of gRPC.
395+
func WithGRPCMaxHeaderListSize(s uint32) Option {
396+
return Option{F: func(o *client.Options, di *utils.Slice) {
397+
di.Push(fmt.Sprintf("WithGRPCMaxHeaderListSize(%d)", s))
398+
o.GRPCConnectOpts.MaxHeaderListSize = &s
399+
}}
400+
}
401+
402+
// WithGRPCKeepaliveParams returns a DialOption that specifies keepalive parameters for the client transport.
403+
// It corresponds to the WithKeepaliveParams DialOption of gRPC.
404+
func WithGRPCKeepaliveParams(kp grpc.ClientKeepalive) Option {
405+
if kp.Time < grpc.KeepaliveMinPingTime {
406+
kp.Time = grpc.KeepaliveMinPingTime
407+
}
408+
return Option{F: func(o *client.Options, di *utils.Slice) {
409+
di.Push(fmt.Sprintf("WithGRPCKeepaliveParams(%+v)", kp))
410+
o.GRPCConnectOpts.KeepaliveParams = kp
411+
}}
412+
}

client/rpctimeout.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func rpcTimeoutMW(mwCtx context.Context) endpoint.Middleware {
109109
e := panicToErr(ctx, panicInfo, ri)
110110
done <- e
111111
}
112-
if !errors.Is(err, kerrors.ErrRPCFinish) {
112+
if err == nil || !errors.Is(err, kerrors.ErrRPCFinish) {
113113
// Don't regards ErrRPCFinish as normal error, it happens in retry scene,
114114
// ErrRPCFinish means previous call returns first but is decoding.
115115
close(done)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/bytedance/gopkg v0.0.0-20210910103821-e4efae9c17c3
88
github.com/cespare/xxhash v1.1.0
99
github.com/choleraehyq/pid v0.0.12
10-
github.com/cloudwego/netpoll v0.1.2
10+
github.com/cloudwego/netpoll v0.2.0
1111
github.com/cloudwego/netpoll-http2 v0.0.6
1212
github.com/cloudwego/thriftgo v0.1.2
1313
github.com/json-iterator/go v1.1.11

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ github.com/choleraehyq/pid v0.0.12 h1:JLiTCsz2gStQZ3YWet+p9hktRnWzk7VJigpzvGV+I2
1414
github.com/choleraehyq/pid v0.0.12/go.mod h1:uhzeFgxJZWQsZulelVQZwdASxQ9TIPZYL4TPkQMtL/U=
1515
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
1616
github.com/cloudwego/netpoll v0.1.0/go.mod h1:rZOiNI0FYjuvNybXKKhAPUja03loJi/cdv2F55AE6E8=
17-
github.com/cloudwego/netpoll v0.1.2 h1:NSvqHfCmmR3g0ASshwAB0F2RJvXK8v7ToFmhWzh/ukY=
18-
github.com/cloudwego/netpoll v0.1.2/go.mod h1:rZOiNI0FYjuvNybXKKhAPUja03loJi/cdv2F55AE6E8=
17+
github.com/cloudwego/netpoll v0.2.0 h1:MmZX/jS6ozso86mnbVJ7fUO1hL4LOH/XngXN7Pn347A=
18+
github.com/cloudwego/netpoll v0.2.0/go.mod h1:rZOiNI0FYjuvNybXKKhAPUja03loJi/cdv2F55AE6E8=
1919
github.com/cloudwego/netpoll-http2 v0.0.6 h1:+jdkMKGj7ifRqWOdyT/hqzhXklmqh/H4lyOdrAVkI/U=
2020
github.com/cloudwego/netpoll-http2 v0.0.6/go.mod h1:+bjPyu2Cd4GDzKa0IegPgp1hjMjpZ6/kXTsSjIsmUk8=
2121
github.com/cloudwego/thriftgo v0.1.2 h1:AXpGJiWE3VggfiRHwA6raRJUIcjxliEIfJfGlvRiYUA=

internal/client/option.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import (
4040
"github.com/cloudwego/kitex/pkg/remote/connpool"
4141
"github.com/cloudwego/kitex/pkg/remote/trans/netpoll"
4242
"github.com/cloudwego/kitex/pkg/remote/trans/nphttp2"
43+
"github.com/cloudwego/kitex/pkg/remote/trans/nphttp2/grpc"
4344
"github.com/cloudwego/kitex/pkg/retry"
4445
"github.com/cloudwego/kitex/pkg/rpcinfo"
4546
"github.com/cloudwego/kitex/pkg/serviceinfo"
@@ -98,6 +99,10 @@ type Options struct {
9899
RetryContainer *retry.Container
99100

100101
CloseCallbacks []func() error
102+
103+
// GRPC
104+
GRPCConnPoolSize uint32
105+
GRPCConnectOpts *grpc.ConnectOptions
101106
}
102107

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

130135
TracerCtl: &internal_stats.Controller{},
136+
137+
GRPCConnectOpts: new(grpc.ConnectOptions),
131138
}
132139
o.Apply(opts)
133140
o.MetaHandlers = append(o.MetaHandlers, transmeta.MetainfoClientHandler)
@@ -150,7 +157,7 @@ func NewOptions(opts []Option) *Options {
150157

151158
func (o *Options) initRemoteOpt() {
152159
if o.Configs.TransportProtocol()&transport.GRPC == transport.GRPC {
153-
o.RemoteOpt.ConnPool = nphttp2.NewConnPool(o.Svr.ServiceName)
160+
o.RemoteOpt.ConnPool = nphttp2.NewConnPool(o.Svr.ServiceName, o.GRPCConnPoolSize, *o.GRPCConnectOpts)
154161
o.RemoteOpt.CliHandlerFactory = nphttp2.NewCliTransHandlerFactory()
155162
}
156163
if o.RemoteOpt.ConnPool == nil {

internal/server/option.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
"github.com/cloudwego/kitex/pkg/remote/codec/thrift"
3939
"github.com/cloudwego/kitex/pkg/remote/trans/detection"
4040
"github.com/cloudwego/kitex/pkg/remote/trans/netpoll"
41+
"github.com/cloudwego/kitex/pkg/remote/trans/nphttp2/grpc"
4142
"github.com/cloudwego/kitex/pkg/rpcinfo"
4243
"github.com/cloudwego/kitex/pkg/serviceinfo"
4344
"github.com/cloudwego/kitex/pkg/stats"
@@ -130,6 +131,7 @@ func newServerOption() *remote.ServerOption {
130131
ExitWaitTime: defaultExitWaitTime,
131132
MaxConnectionIdleTime: defaultConnectionIdleTime,
132133
AcceptFailedDelayTime: defaultAcceptFailedDelayTime,
134+
GRPCCfg: new(grpc.ServerConfig),
133135
}
134136
}
135137

licenses/LICENSE-gjson

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 Josh Baker
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

0 commit comments

Comments
 (0)