Series catalog
Hystrix, Ribbon, Feign source analysis (a) primer
Hystrix, Ribbon, Feign source code analysis (ii) the principle of generalization
Hystrix, Ribbon, Feign source code analysis (c) Detailed source
Hystrix, Ribbon, Feign source code analysis (iv) review for improvement
First, the primer
Call failed a few days ago appeared online services, architecture is a spring cloud Greenwich.SR4 version, use feign call log line after the investigation found that:. Feign Client calls microService one second to automatically time-out failure. Internet search, he said hystrix default is 1 second timeout configuration, add the following configuration to solve the problem:
#Feign
# Use apahce httpclient connection pool
feign:
httpclient:
enabled: true
hystrix:
enabled: true
# Timeout handling
hystrix:
command:
default:
execution:
isolation:
strategy: SEMAPHORE
thread:
timeoutInMilliseconds: 30000
# Timeout global configuration ribbion
ribbon:
ConnectTimeout: 10000
ReadTimeout: 10000
As shown in FIG:
1. Feign. Hystrix . Enabled = to true representative of open fuse
2. Hystrix. Command . Default . Execution . Isolation . Thread . TimeoutInMilliseconds = 30000 fuse timeout milliseconds, 30 seconds (default 1000)
Formula is as follows:
Hystrix的超时时间=Ribbon的重试次数(包含首次) * (ribbon.ReadTimeout + ribbon.ConnectTimeout)
This time out, there is nothing official corroboration of it?
Queries spring cloud 's official website after, find the following paragraph:
Translation is as follows:
hystrix timeout> Timeout ribbon (comprising potentially retry time), for example, one second connection timeout ribbon, three retries, so Hystrix timeout must be> 3 seconds
Second, the solution step
To expose my problem-solving steps, we can bring hope to the idea that to solve the problem.
We employ three steps: identify problems, analyze and solve problems .
2.1 identify problems
Here is nothing more than two points:
- Use spring cloud family bucket, hystrix, ribbon, clear principles feign call it?
- yml configuration What? The default configuration used to know it?
2.2 Analysis of the problem
- Principle by the official documentation + source code (the code is open source). I did not understand? Too lazy to look? Source-level blog now fewer and fewer people are impetuous and even copied the blog ...
- How to know which specific configuration? No clue! ! !
has it ended?
After reading official documents, found Spring boot all the jar package, automatic code completion configuration : the Spring-metadata.json the Configuration-oradditional-spring-configuration-metadata.json
. The former is automatically generated at compile time, which is manually customized. The latter over the former. ( But this is only part of the configuration details of a large number !!! !!! configuration chat in the source code than nothing right !!! )
IDEA in properties, yml file which may have prompted the drop-down configuration. As shown below:
Look at the specific additional-spring-configuration-metadata.json
contents are as follows:
As Figure:
feign.hysgtrix.enabled If true, open hystrix fuse. The default is false, do not open.
feign.httpclient.enabled open use apache http client connection pooling, enabled by default.
The question is, did not find the first configuration.
Honestly after reading the source code:
In hysyrix-core-1.5.18.jar (in spring-cloud-starter-netflix- hystrix: 2.1.4.RELEASE in) has finally found a configuration class HystrixCommandProperties
Sure enough, the default is 1 second, and finally a real hammer.
2.3 to solve the problem
This series of articles is a practical solution to the problem. + Source code by reading official documents, Cloud H thoroughly to find out the Spring ystrix + Ribbon + Feign old Dier. Subsequent chapters, is our step by step problem solving process.
Again, the technology does not allow lazy ! ! !