From bab67facad0d3582fb1f5a49b95621f4611a502f Mon Sep 17 00:00:00 2001 From: weetime <351075478@qq.com> Date: Wed, 22 Feb 2023 15:50:22 +0800 Subject: [PATCH] fix(contrib): fix eureka server load too high (#2546) Co-authored-by: fangyong --- contrib/registry/eureka/client.go | 10 +++++----- contrib/registry/eureka/eureka.go | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/contrib/registry/eureka/client.go b/contrib/registry/eureka/client.go index ab9eb30d2..3b985c5b1 100644 --- a/contrib/registry/eureka/client.go +++ b/contrib/registry/eureka/client.go @@ -19,9 +19,9 @@ const ( statusOutOfService = "OUT_OF_SERVICE" heartbeatRetry = 3 maxIdleConns = 100 - heartbeatTime = 10 - httpTimeout = 3 - refreshTime = 30 + heartbeatTime = 10 * time.Second + httpTimeout = 3 * time.Second + refreshTime = 30 * time.Second ) type Endpoint struct { @@ -139,8 +139,8 @@ func NewClient(urls []string, opts ...ClientOption) *Client { urls: urls, eurekaPath: "eureka/v2", maxRetry: len(urls), - heartbeatInterval: time.Second * heartbeatTime, - client: &http.Client{Transport: tr, Timeout: time.Second * httpTimeout}, + heartbeatInterval: heartbeatTime, + client: &http.Client{Transport: tr, Timeout: httpTimeout}, keepalive: make(map[string]chan struct{}), } diff --git a/contrib/registry/eureka/eureka.go b/contrib/registry/eureka/eureka.go index a5c1201e7..a7759dee4 100644 --- a/contrib/registry/eureka/eureka.go +++ b/contrib/registry/eureka/eureka.go @@ -29,7 +29,7 @@ func NewAPI(ctx context.Context, client *Client, refreshInterval time.Duration) } // it is required to broadcast for the first time - e.broadcast() + go e.broadcast() go e.refresh(ctx) @@ -112,6 +112,7 @@ func (e *API) Subscribe(serverName string, fn func()) error { appID: appID, callBack: fn, } + go e.broadcast() return nil }