fix(contrib): fix eureka server load too high (#2546)

Co-authored-by: fangyong <fangyong@haodf.com>
pull/2676/head
weetime 2 years ago committed by GitHub
parent d0b1d84850
commit bab67facad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      contrib/registry/eureka/client.go
  2. 3
      contrib/registry/eureka/eureka.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{}),
}

@ -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
}

Loading…
Cancel
Save