In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail what is Hystrix, the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
Hystrix coordinates the framework of high availability of various services in distributed systems, and is an important member of SpringCloud architecture. Hystrix mainly solves the problems of service avalanche, service monitoring and so on.
Hystrix function introduces the function of resource isolation and current restriction.
The main purpose is to prevent the collapse of the dependent service from affecting the consumption of its own service resources, and to use isolation to limit the maximum thread resources that can be used to invoke the dependent service. If a service crashes and does not control resource isolation, it will trigger a service avalanche and many upstream services will collapse collectively.
In addition, in the case of large concurrency, it can also reduce the traffic of dependent service requests and avoid excessive load of dependent services.
Principle
Hystrix encapsulates calls to external services and a series of processing into a Commond object, which is divided into HystrixCommand (direct invocation command) and HystrixObservableCommand (observer subscription command), which can register callback events. Both can be called asynchronously or synchronously (Future is returned asynchronously, and get blocking can be called later to get the result).
Commond objects isolate resources in two ways, one is to use thread pools (commonly used), and the second is to use semaphores. Both of them limit the number of concurrent threads called by Commond. The difference is that semaphores are only a thread that allows concurrent calls to command and cannot record timeout information and so on.
Configuration item
Select Commond resource isolation strategy, thread pool (commonly used) or semaphore
Specify the command name, group. The name defaults to the class name (a command usually corresponds to a service-dependent interface call), and all command under group share a thread pool or are isolated by a semaphore by default (group usually corresponds to a dependent service).
Specify the command thread pool, and the key for HystrixThreadPool defaults to the group name, or you can specify the HystrixThreadPool to use manually.
Specifies the number of core threads in the thread pool, which defaults to 10.
Specifies the thread pool queue length, which defaults to-1 unbounded queue. If the value is exceeded, the request is rejected.
Specifies the thread pool reject threshold, which defaults to 5, and rejects the request if it exceeds it.
The maximum number of concurrent visits can be set under semaphore isolation. The default is 10.
Principle of requestCache- request caching
In a web call main thread, the cache is established for the command of the main thread calling the service, so that if the call depends on the same parameters of the service, the result can be obtained directly from memory. Since I think it is not very useful, I will not introduce it much, mainly initializing the HytrixRequestContext in the interceptor (this cache data should be visually in the thread local variable), and then implementing the getCacheKey method in Command to return the key of cache. When the key is the same, directly try to get the result of the same key returned after the previous call.
Principle of fallback- service degradation
The getFallBack method (HystrixCommand) or the resumeWithFallback method (HystrixObservableCommand) is implemented through Command, and the degraded logic is implemented, and the degraded result is returned locally.
Conditions for demotion
Thread pool or semaphore reject
Call timeout
Execute error report
The circuit breaker is turned on
The usual logic of demotion
Fetch older data from the local cache
Returns the default value
Note: downgrade logic can set parameters to limit the number of concurrent threads (based on semaphores) circuit breaker- circuit breaker principle open condition
The call timeout reaches a certain percentage.
The execution of error reports reaches a certain proportion.
Thread pool or semaphore reject to a certain proportion
Half-open state
After a certain period of time, it will switch to the half-open state and let 1 request pass to see if it can be returned normally.
Open state
If the request allowed to pass in the half-open state is successful, turn off the circuit breaker
Related configurable item
Whether to turn on the circuit breaker (on by default)
Minimum number of requests in the circuit breaker time rolling window (default 20)
How many anomalies (including timeouts, errors, rejections) (default 50%) turn on the circuit breaker
How long does it take to enter the half-open state (default is 5000 milliseconds)
Whether to force the circuit breaker to open
Whether to forcibly close the circuit breaker
Timeout configuration (default 1000 milliseconds)
Whether to turn on the timeout mechanism (on by default)
On what is Hystrix to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.