Netflix创建了一个名为Hystrix的库,它实现了断路器模式。在微服务体系结构中,有多个服务调用层是很常见的。

HystrixGraph

图1所示。Microservice图

服务级别较低的服务失败可能导致级联故障一直到客户端浏览器。当对某个特定服务的调用达到某个阈值时(5秒内的20次故障是在Hystrix上的默认值),断路器就会打开,调用也不会被调用。在出现错误和开放断路的情况下,开发人员可以提供备用方案。

HystrixFallback

图2。Hystrix的fallback避免了级联故障

拥有一个开放的断路器可以阻止连锁的失败,并允许被淹没或失败的服务时间来治愈。fallback可以是另一个受保护的断路器调用、静态数据或一个正常的空值。fallback可能是一个链式调用,所以第一个fallback会产生一些其他的业务调用,而这些调用反过来又会返回到静态数据。

英文原文:
13. Circuit Breaker: Hystrix Clients
Netflix has created a library called Hystrix that implements the circuit breaker pattern. In a microservice architecture it is common to have multiple layers of service calls.

Figure 13.1. Microservice Graph

HystrixGraph

A service failure in the lower level of services can cause cascading failure all the way up to the user. When calls to a particular service is greater than circuitBreaker.requestVolumeThreshold (default: 20 requests) and failue percentage is greater than circuitBreaker.errorThresholdPercentage (default: >50%) in a rolling window defined by metrics.rollingStats.timeInMilliseconds (default: 10 seconds), the circuit opens and the call is not made. In cases of error and an open circuit a fallback can be provided by the developer.

Figure 13.2. Hystrix fallback prevents cascading failures

HystrixFallback

Having an open circuit stops cascading failures and allows overwhelmed or failing services time to heal. The fallback can be another Hystrix protected call, static data or a sane empty value. Fallbacks may be chained so the first fallback makes some other business call which in turn falls back to static data.

分享到: 更多