Since distributed systems make different types of services, in one system 1, different services may be called, such as services A, B, C,
and the service and service will also call each other, such as service D, E will invoke service A;
When service a fails to be invoked, System 1, Service D, and service e fail, resulting in a service avalanche due to a service problem that causes multiple systems or services to be unavailable.
Therefore, a fuse is presented that quickly returns a failure value (not the return of the blocking wait service, or the exception that the service failed to throw out, causing the caller to fail)
The function of fuse can be realized by using Hystrix.
The fuse mode defines the logic for the fuse switch to be converted to each other:
Health status of the service = number of failed requests/total requests.
The switching of the fuse switch from off to on is determined by the current service health status and the set threshold comparison.
When the fuse switch is turned off, the request is allowed through the fuse. If the current health condition is higher than the set threshold, the switch continues to remain closed. If the current health condition is below the set threshold, the switch is switched on.
When the fuse switch is turned on, the request is forbidden.
When the fuse switch is open, after a period of time, the fuse will automatically enter the half-open state, when the fuse only allows one request to pass. When the request is successfully invoked, the fuse reverts to the off state. If the request fails, the fuse remains open and the subsequent request is disallowed.
The switch of the fuse can guarantee the service caller to return the result quickly when invoking the abnormal service, and avoid a large number of synchronous waits. And the fuse can continue to detect the request execution results after a period of time, providing the possibility of recovery service invocation.
Hystrix's internal processing logic
Constructs the command object for the Hystrix and invokes the execution method.
Hystrix Check if the fuse switch for the current service is on, and if it is on, perform the downgrade service Getfallback method.
If the fuse switch is off, Hystrix checks to see if the thread pool for the current service is able to receive new requests, and if the thread pool is more than full, perform the downgrade service Getfallback method.
If the thread pool accepts the request, Hystrix begins executing the service invocation of the concrete logical run method.
If the service execution fails, the Downgrade service Getfallback method is executed, and the execution results are escalated Metrics Update Service health status.
If the service execution times out, the downgrade service Getfallback method is executed and the execution result is escalated Metrics update service health.
If the service executes successfully, returns the normal result.
If the service demotion method Getfallback execution succeeds, the degraded result is returned.
If the service demotion method Getfallback execution fails, an exception is thrown.
Dubbo Integrated Hystrix as a fuse, can be based on the Dubbo filter to achieve the fuse function, the code has
https://github.com/jjavaboy/lam-nio/blob/master/lam-dubbo-consumer/src/main/java/lam/dubbo/consumer/filter/ Fallbackhystrixfilter.java
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.