Feign性能优化

发布时间 2023-06-21 15:41:52作者: 佛系粥米

一、Feign底层的客户端实现:

1、URLConnection:默认实现,不支持连接池

2、Apache HttpClient :支持连接池

3、OKHttp:支持连接池 因此优化

 

二、Feign的性能主要包括:

1、使用连接池代替默认的URLConnection

2、日志级别,最好用basic或none

 

三、Feign添加HttpClient的支持

1、引入依赖:

 <!--httpClient的依赖 -->
        <dependency>
            <groupId>io.github.openfeign</groupId>
            <artifactId>feign-httpclient</artifactId>
        </dependency>

2、配置连接池

feign:
  httpclient:
    enabled: true #支持httpClient开关
    max-connections: 200 # 最大连接数
    max-connections-per-route: 50 #单个请求路径的最大连接数