Interview topic: What is Hystrix? Briefly describe the implementation mechanism

Important components of SpringCloud

Distributed fault tolerance framework

  • Prevent the chain reaction of failures and realize fusing
  • Fail fast and achieve graceful degradation
  • Provide real-time monitoring and alerting

Resource isolation: thread isolation, semaphore isolation

  • Thread isolation: Hystrix will allocate a separate thread pool to each Command, so that when a single service call is made, it can be performed in a separate thread pool without affecting other thread pools
  • Semaphore isolation: When the client initiates a request to a dependent service, it must first obtain a semaphore to actually initiate the call. Since the number of semaphores takes precedence, when the number of requests exceeds the number of semaphores, subsequent requests will be directly rejected and enter fallback process. Semaphore isolation is mainly used to control the amount of concurrent requests to prevent large-scale blockage of request threads, thereby achieving the purpose of current limiting and preventing avalanches.

Fuse and degradation: fail quickly after calling the service failed

  • Fuse: to prevent abnormal non-proliferation and ensure the stability of the system

  • Downgrade: Write the remedial logic for the call failure, and then stop the service directly, so that these interfaces cannot be called normally, but it will not directly report an error, but the service level is reduced

  • All external systems (or dependencies) are packaged through HystrixCommand or HystrixObservableCommand, and the entire packaged object runs in a single thread (this is a typical command mode).

  • The timeout request should exceed the threshold you defined

  • Maintain a small thread pool (or semaphore) for each dependency; if it becomes full, the dependency request will be rejected immediately instead of waiting in line

  • Statistics success, failure (exception thrown by the client), timeout and thread rejection

  • Opening the circuit breaker can stop all requests for characteristic services within a period of time. If the error percentage of the service passes the threshold, the circuit breaker can be closed manually or automatically.

  • When the request is rejected, the connection times out, or the circuit breaker is opened, the fallback logic is executed directly.

  • Monitor indicators and configuration changes in near real-time.

Guess you like

Origin blog.csdn.net/lxn1023143182/article/details/114974316