From 636160ed950b1b4b8a6aa5cc38b88d19540e0188 Mon Sep 17 00:00:00 2001 From: longXboy Date: Thu, 4 Jul 2019 16:14:27 +0800 Subject: [PATCH] add keepalive for client --- pkg/net/rpc/warden/CHANGELOG.md | 4 ++++ pkg/net/rpc/warden/client.go | 33 ++++++++++++++++++++++----------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/pkg/net/rpc/warden/CHANGELOG.md b/pkg/net/rpc/warden/CHANGELOG.md index 5c453bb02..8918b7f5f 100644 --- a/pkg/net/rpc/warden/CHANGELOG.md +++ b/pkg/net/rpc/warden/CHANGELOG.md @@ -1,5 +1,9 @@ ### net/rpc/warden +##### Version 1.1.19 +1. 升级grpc至1.22.0 +2. client增加keepAlive选项 + ##### Version 1.1.18 1. 修复resolver过滤导致的子集bug diff --git a/pkg/net/rpc/warden/client.go b/pkg/net/rpc/warden/client.go index e81fabb25..ec5ec4bca 100644 --- a/pkg/net/rpc/warden/client.go +++ b/pkg/net/rpc/warden/client.go @@ -34,9 +34,11 @@ var _grpcTarget flagvar.StringVars var ( _once sync.Once _defaultCliConf = &ClientConfig{ - Dial: xtime.Duration(time.Second * 10), - Timeout: xtime.Duration(time.Millisecond * 250), - Subset: 50, + Dial: xtime.Duration(time.Second * 10), + Timeout: xtime.Duration(time.Millisecond * 250), + Subset: 50, + KeepAliveInterval: xtime.Duration(time.Second * 60), + KeepAliveTimeout: xtime.Duration(time.Second * 20), } _defaultClient *Client ) @@ -51,14 +53,17 @@ func baseMetadata() metadata.MD { // ClientConfig is rpc client conf. type ClientConfig struct { - Dial xtime.Duration - Timeout xtime.Duration - Breaker *breaker.Config - Method map[string]*ClientConfig - Clusters []string - Zone string - Subset int - NonBlock bool + Dial xtime.Duration + Timeout xtime.Duration + Breaker *breaker.Config + Method map[string]*ClientConfig + Clusters []string + Zone string + Subset int + NonBlock bool + KeepAliveInterval xtime.Duration + KeepAliveTimeout xtime.Duration + KeepAliveWithoutStream bool } // Client is the framework's client side instance, it contains the ctx, opt and interceptors. @@ -186,6 +191,12 @@ func (c *Client) SetConfig(conf *ClientConfig) (err error) { if conf.Subset <= 0 { conf.Subset = 50 } + if conf.KeepAliveInterval <= 0 { + conf.KeepAliveInterval = xtime.Duration(time.Second * 60) + } + if conf.KeepAliveTimeout <= 0 { + conf.KeepAliveTimeout = xtime.Duration(time.Second * 20) + } // FIXME(maojian) check Method dial/timeout c.mutex.Lock()