One: What is Hystrix? 1. 1: Basic explanation Hystrix was first opened by Netflix (everyone who has seen American TV shows knows that it is a giant company that makes American TV shows), and then SpringCloudHystrix realized a series of service protection functions such as circuit breakers and thread isolation based on this framework. The goal of this framework is to provide more powerful fault tolerance for delays and failures by controlling nodes accessing remote systems, services and third-party libraries.
Hystrix has powerful functions such as service degradation, service convergence, thread and signal isolation, request caching, request merging and service monitoring.
It plays a protective mechanism of micro-service, preventing one unit from failing, leading to the spread of dependency, and finally leading to the paralysis of the whole system.
1.2: The concept of circuit breaker is a switching device itself, which is used to protect the circuit from overload when there is a short circuit in the circuit.
"Circuit breaker" can cut off the fault in time and prevent serious consequences such as overload, fever and even fire.
In distributed architecture, circuit breaker mode plays a similar role.
When a service fails, it returns an error response to the caller through the fault monitoring of the circuit breaker, instead of hanging the thread for a long time and waiting indefinitely.
In this way, the thread will not be occupied for a long time because of the faulty service, and the spread of faults in the distributed system will be avoided.
Two: Hystrix solves the timeout problem. 2. 1: The problem assumes that our front-end provides users with the function of querying orders. First, the request is mapped to the OrderController, and the controller obtains the order information by calling the service orderService. The front end passes two parameters: one is the order id and the other is the user id. Order service needs to call the user service through the user id, get the relevant information of the user, and return the assembly information to OrderService. Suppose it is through/suggest. After the command sends a request, it passes through a series of judgments, the order is whether the cache hits, whether the circuit breaker is open, and whether the thread pool is full. Then it will start the service dependency processing of the code that actually requests us to write. That is, the Hystrix.run method, if any of these nodes has an error or throws an exception, it will return to the fallback method for service degradation. When the downgrade is completed, it will return the result to the international caller for a series of processing.