Feign 能干什么
Feign 是声明式的web service客户端,它让微服务之间的调用变得更简单了,类似controller调用service。Spring Cloud集成了Ribbon和Eureka,可在使用Feign时提供负载均衡的http客户端。
Feign 性能优化
feign 底层的客户端实现:
- URLConnection:默认实现,不支持连接池
- Apache HttpClient:支持连接池
- OKHttp:支持连接池
因此优化Feign的性能主要包括:
- 使用连接池代替默认的实现(URLConnection)
- 日记级别最好用 bacsic 或 none(日志会消耗性能)
- bacsic:基础的日志
- none:不开启日志
Feign 底层使用 Apache HttpClient 作为客户端
<dependency><groupId>org.apache.httpcomponents</groupId><artifactId>httpclient</artifactId><version>被springboot管理</version></dependency>
feign:httpclient:enabled: true # 开启 feign 对 HttpClient 的支持max-connections: 200 # 最大连接数max-connections-per-route: 50 # 每个路径的最大连接数
