Skip to content

Commit

Permalink
make backoff shorter
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <rleungx@gmail.com>
  • Loading branch information
rleungx committed Feb 18, 2024
1 parent e264a61 commit bcedbda
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
11 changes: 10 additions & 1 deletion client/grpcutil/grpcutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/tikv/pd/client/errs"
"go.uber.org/zap"
"google.golang.org/grpc"
"google.golang.org/grpc/backoff"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/metadata"
)
Expand Down Expand Up @@ -62,7 +63,15 @@ func GetClientConn(ctx context.Context, addr string, tlsCfg *tls.Config, do ...g
if err != nil {
return nil, errs.ErrURLParse.Wrap(err).GenWithStackByCause()
}
cc, err := grpc.DialContext(ctx, u.Host, append(do, opt)...)
backoffOpts := grpc.WithConnectParams(grpc.ConnectParams{
Backoff: backoff.Config{
BaseDelay: 1.0 * time.Second,
Multiplier: 1.6,
Jitter: 0.2,
MaxDelay: 60 * time.Second,
},
})
cc, err := grpc.DialContext(ctx, u.Host, append(do, opt, backoffOpts)...)
if err != nil {
return nil, errs.ErrGRPCDial.Wrap(err).GenWithStackByCause()
}
Expand Down
11 changes: 10 additions & 1 deletion pkg/utils/grpcutil/grpcutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"go.etcd.io/etcd/pkg/transport"
"go.uber.org/zap"
"google.golang.org/grpc"
"google.golang.org/grpc/backoff"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/metadata"
Expand Down Expand Up @@ -147,7 +148,15 @@ func GetClientConn(ctx context.Context, addr string, tlsCfg *tls.Config, do ...g
if err != nil {
return nil, errs.ErrURLParse.Wrap(err).GenWithStackByCause()
}
cc, err := grpc.DialContext(ctx, u.Host, append(do, opt)...)
backoffOpts := grpc.WithConnectParams(grpc.ConnectParams{
Backoff: backoff.Config{
BaseDelay: 1.0 * time.Second,
Multiplier: 1.6,
Jitter: 0.2,
MaxDelay: 60 * time.Second,
},
})
cc, err := grpc.DialContext(ctx, u.Host, append(do, opt, backoffOpts)...)
if err != nil {
return nil, errs.ErrGRPCDial.Wrap(err).GenWithStackByCause()
}
Expand Down

0 comments on commit bcedbda

Please sign in to comment.