Preface
Today, when using the microservice call, the call between services timed out, and the error was reported as follows:
feign.RetryableException: Read timed out executing POST http://******
It is also possible that some people will report an error when the services are started successfully for the first time, but then resume normal access.
Solution:
First, the first call fails and then it is normal: To solve this problem, let the class that needs to be instantiated be created in advance instead of when it is first called.
Reason: The main reason is that the Client that Ribbon performs client-side load balancing is not initialized when the service starts, but the corresponding Client is created when the service is called, so the time consumed for the first call does not only include sending The time of the HTTP request also includes the time to create the RibbonClient. In this way, if the creation time is slow and the set timeout time is relatively short, it is easy to appear as described above.
Configuration:
#预加载配置,默认为懒加载
ribbon:
eager-load:
enabled: true
clients: zoo-plus-email
zoo-plus-email:
ribbon:
ReadTimeout: 3000
ConnectTimeout: 3000
Parameter Description:
ribbon.eager-load.enabled: Enable Ribbon's starvation loading mode
ribbon.eager-load.clients: Specify the service name that needs to be loaded
The following is the configuration connection read time for a single service.
Configure ribbon to configure all services:
ribbon:
ReadTimeout: 15000
ConnectTimeout: 60000