6

背景

我使用Spring雲Brixton.RC2,Zuul和Eureka。Zuul/Ribbon/Hystrix不在不同的實例上重試

我有一個網關服務@EnableZuulProxybook-servicestatus方法。通過配置,我可以通過睡眠定義的時間模擬status方法的工作。

的Zuul路線簡單

zuul.routes.foos.path=/foos/** 
zuul.routes.foos.serviceId=reservation-service 

我運行book-service的兩個實例。當我將睡眠時間設置在Hystrix超時閾值(1000毫秒)以下時,我可以看到請求轉到兩個圖書服務的實例。這很好。

問題

我明白,如果蝟命令失敗,它應該是可能的絲帶到不同的服務器上試該命令。這應該會讓客戶失敗。

我讀功能區的配置,並增加在Zuul以下配置:

zuul.routes.reservation-service.retryable=true //not sure which one to try 
zuul.routes.foos.retryable=true //not sure which one to try 

ribbon.MaxAutoRetries=0 // I don't want to retry on the same host, I also tried with 1 it doesn't work either 
ribbon.MaxAutoRetriesNextServer=2 
ribbon.OkToRetryOnAllOperations=true 

現在這樣只有一個服務睡覺時間超過1s,這意味着我有一個健康的服務,我更新配置,並一個壞的。

當我打電話網關的電話獲得發送到這兩種情況下,一半的呼​​叫返回一個500。我看到了豪豬超時網關:

com.netflix.zuul.exception.ZuulException: Forwarding error 
    [...] 
Caused by: com.netflix.hystrix.exception.HystrixRuntimeException: reservation-service timed-out and no fallback available. 
    [...] 
Caused by: java.util.concurrent.TimeoutException: null 

爲什麼不絲帶重試調用另一個實例?

我在這裏想念什麼?


參考

回答

3

默認情況下Zuul使用s SEMAPHORE隔離策略不允許設置超時。我無法在這種策略中使用負載平衡。什麼工作對我來說是(按照你的例子):

1)改變Zuul的隔離主題:

hystrix: 
    command: 
    reservation-service: 
     execution: 
     isolation: 
      strategy: THREAD 
      thread: 
      timeoutInMilliseconds: 100000 

重要:timeoutInMilliseconds = 100000好像是說沒有HystrixTimeout。爲什麼?因爲如果蝟超時,不會有任何負載平衡(我只是測試它與timeoutInMilliseconds播放)

然後,配置絲帶的ReadTimeout爲需要的值:單觸售後服務

reservation-service: 
    ribbon: 
    ReadTimeout: 800 
    ConnectTimeout: 250 
    OkToRetryOnAllOperations: true 
    MaxAutoRetriesNextServer: 2 
    MaxAutoRetries: 0 

在這種情況下,

o.s.web.servlet.DispatcherServlet  : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/api/stories] 
o.s.web.servlet.DispatcherServlet  : Last-Modified value for [/api/stories] is: -1 
c.n.zuul.http.HttpServletRequestWrapper : Path = null 
c.n.zuul.http.HttpServletRequestWrapper : Transfer-Encoding = null 
c.n.zuul.http.HttpServletRequestWrapper : Content-Encoding = null 
c.n.zuul.http.HttpServletRequestWrapper : Content-Length header = -1 
c.n.loadbalancer.ZoneAwareLoadBalancer : Zone aware logic disabled or there is only one zone 
c.n.loadbalancer.LoadBalancerContext  : storyteller-api using LB returned Server: localhost:7799 for request /api/stories 

---> ATTEMPTING THE SLOW SERVICE 

com.netflix.niws.client.http.RestClient : RestClient sending new Request(GET:) http://localhost:7799/api/stories 
c.n.http4.MonitoredConnectionManager  : Get connection: {}->http://localhost:7799, timeout = 250 
com.netflix.http4.NamedConnectionPool : [{}->http://localhost:7799] total kept alive: 1, total issued: 0, total allocated: 1 out of 200 
com.netflix.http4.NamedConnectionPool : No free connections [{}->http://localhost:7799][null] 
com.netflix.http4.NamedConnectionPool : Available capacity: 50 out of 50 [{}->http://localhost:7799][null] 
com.netflix.http4.NamedConnectionPool : Creating new connection [{}->http://localhost:7799] 
com.netflix.http4.NFHttpClient   : Attempt 1 to execute request 
com.netflix.http4.NFHttpClient   : Closing the connection. 
c.n.http4.MonitoredConnectionManager  : Released connection is not reusable. 
com.netflix.http4.NamedConnectionPool : Releasing connection [{}->http://localhost:7799][null] 
com.netflix.http4.NamedConnectionPool : Notifying no-one, there are no waiting threads 

--- HERE'S RIBBON'S TIMEOUT 

c.n.l.reactive.LoadBalancerCommand  : Got error com.sun.jersey.api.client.ClientHandlerException: java.net.SocketTimeoutException: Read timed out when executed on server localhost:7799 
c.n.loadbalancer.ZoneAwareLoadBalancer : Zone aware logic disabled or there is only one zone 
c.n.loadbalancer.LoadBalancerContext  : storyteller-api using LB returned Server: localhost:9977 for request /api/stories 

---> HERE IT RETRIES 

com.netflix.niws.client.http.RestClient : RestClient sending new Request(GET:) http://localhost:9977/api/stories 
c.n.http4.MonitoredConnectionManager  : Get connection: {}->http://localhost:9977, timeout = 250 
com.netflix.http4.NamedConnectionPool : [{}->http://localhost:9977] total kept alive: 1, total issued: 0, total allocated: 1 out of 200 
com.netflix.http4.NamedConnectionPool : Getting free connection [{}->http://localhost:9977][null] 
com.netflix.http4.NFHttpClient   : Stale connection check 
com.netflix.http4.NFHttpClient   : Attempt 1 to execute request 
com.netflix.http4.NFHttpClient   : Connection can be kept alive indefinitely 
c.n.http4.MonitoredConnectionManager  : Released connection is reusable. 
com.netflix.http4.NamedConnectionPool : Releasing connection [{}->http://localhost:9977][null] 
com.netflix.http4.NamedConnectionPool : Pooling connection [{}->http://localhost:9977][null]; keep alive indefinitely 
com.netflix.http4.NamedConnectionPool : Notifying no-one, there are no waiting threads 
o.s.web.servlet.DispatcherServlet  : Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling 
o.s.web.servlet.DispatcherServlet  : Successfully completed request 
o.s.web.servlet.DispatcherServlet  : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/favicon.ico] 
o.s.w.s.handler.SimpleUrlHandlerMapping : Matching patterns for request [/favicon.ico] are [/**/favicon.ico] 
o.s.w.s.handler.SimpleUrlHandlerMapping : URI Template variables for request [/favicon.ico] are {} 
o.s.w.s.handler.SimpleUrlHandlerMapping : Mapping [/favicon.ico] to HandlerExecutionChain with handler [ResourceHttpRequestHandler [locations=[ServletContext resource [/], class path resource [META-INF/resources/], class path resource [resources/], class path resource [static/], class path resource [public/], class path resource []], resolvers=[[email protected]d875d]]] and 1 interceptor 
o.s.web.servlet.DispatcherServlet  : Last-Modified value for [/favicon.ico] is: -1 
o.s.web.servlet.DispatcherServlet  : Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling 
o.s.web.servlet.DispatcherServlet  : Successfully completed request 
+0

我已經加入 '重:超時的絲帶,它會與500ms的服務

下面你有我在zuul情況下得到了數重試servation-service.ribbon.ConnectTimeout = 250 預約service.ribbon.OkToRetryOnAllOperations =真 預約service.ribbon.MaxAutoRetriesNextServer = 2 預約service.ribbon.MaxAutoRetries = 0' 到我的配置,但我怕沒有解決問題。 – phoenix7360

+0

太棒了!我還沒有意識到,絲帶重試發生在同一個Hystrix命令內。我認爲每次重試都會有他們自己的Hystrix命令。這樣做更有意義。 – phoenix7360

相關問題