Feign 能干什么

Feign 是声明式的web service客户端,它让微服务之间的调用变得更简单了,类似controller调用service。Spring Cloud集成了Ribbon和Eureka,可在使用Feign时提供负载均衡的http客户端。


Feign 性能优化

feign 底层的客户端实现:

  • URLConnection:默认实现,不支持连接池
  • Apache HttpClient:支持连接池
  • OKHttp:支持连接池

因此优化Feign的性能主要包括:

  1. 使用连接池代替默认的实现(URLConnection)
  2. 日记级别最好用 bacsic 或 none(日志会消耗性能)
    1. bacsic:基础的日志
    2. none:不开启日志

Feign 底层使用 Apache HttpClient 作为客户端

  1. <dependency>
  2. <groupId>org.apache.httpcomponents</groupId>
  3. <artifactId>httpclient</artifactId>
  4. <version>被springboot管理</version>
  5. </dependency>
  1. feign:
  2. httpclient:
  3. enabled: true # 开启 feign 对 HttpClient 的支持
  4. max-connections: 200 # 最大连接数
  5. max-connections-per-route: 50 # 每个路径的最大连接数