Hystrix and principle introduction

Hystrix, meaning porcupine in Chinese, has thorns on its back, and thus has the ability to protect itself. The Hystrix mentioned in this article is a fault-tolerant framework open sourced by Netflix and also has self-protection capabilities.

Hystrix is ​​a delay and fault tolerance library open sourced by Netflix, used to isolate access to remote systems, services or third-party libraries to prevent cascading failures, thereby improving system availability, fault tolerance and local application flexibility And circuit breaker tool library.

1. The design principle of Hystrix

  • Prevent any individual dependency from exhausting resources (threads), overload is immediately cut off and quickly fails, preventing queueing.
  • Provide rollback as much as possible to protect users from malfunctions.
  • Use isolation techniques (such as bulkheads, swim lanes, and circuit breaker modes) to limit the effects of any one dependency.
  • Through near real-time indicators, monitoring and alarms, ensure that faults are discovered in a timely manner.
  • By dynamically modifying the configuration properties, to ensure timely recovery of faults.
  • Prevent entire client-dependent execution failures, not just network communication.

Second, the working principle of Hystrix

  • Use command mode to wrap all calls to external services (or dependencies) in HystrixCommand or HystrixObservableCommand objects, and place the object in a separate thread for execution.
  • Each dependency maintains a thread pool (or semaphore), and the thread pool is exhausted and rejects the request (instead of queuing the request).
  • Record request success, failure, timeout and thread rejection.
  • The service error percentage exceeds the threshold, the fuse switch is automatically turned on, and all requests for the service are stopped for a period of time.
  • The request failed, rejected, and the downgrade logic was executed when it timed out or blown.
  • Monitor indicators and configuration changes in near real time.

When Hystrix is ​​used to encapsulate each basic dependency, each dependency is isolated from each other, limited by the resources that are saturated during the delay, and contains fallback logic, which determines when any type of failure occurs in the dependency What response.

 

Guess you like

Origin www.cnblogs.com/myitnews/p/12730276.html