Feign底層的客戶端實現:
- URLConnection:默認實現,不支持連接池
- Apache HttpClient :支持連接池
- OKHttp:支持連接池
因此優化Feign的性能主要包括:
- 使用連接池代替默認的URLConnection
- 日志級別,最好用basic或none
連接池配置
Feign添加HttpClient或OKHttp代替URLConnection
添加HttpClient依賴
<dependency> <groupId>io.github.openfeign</groupId> <artifactId>feign-httpclient</artifactId> </dependency>
配置連接池
feign: client: config: userservice: loggerLevel: BASIC httpclient: enabled: true # 開啟feign對HttpClient的支持 max-connections: 200 # 最大的連接數 max-connections-per-route: 50 # 每個路徑的最大連接數
