配置 HttpClient 或者 OKHttp
在默认情况下 spring cloud feign在进行各个子服务之间的调用时,http组件使用的是jdk的HttpURLConnection,没有使用线程池。有2种可选的线程池:HttpClient 和 OKHttp
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-httpclient</artifactId>
<version>11.0</version>
</dependency>
或者
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-okhttp</artifactId>
<version>11.0</version>
</dependency>
配置参数
feign:
httpclient:
enabled: true
# feign最大连接数
max-connections: 200
# feign单个路径的最大连接数
max-connections-per-route: 50
或者
feign:
okhttp:
enabled: true
# feign最大连接数
max-connections: 200
# feign单个路径的最大连接数
max-connections-per-route: 50
日志级别
在生产环境,需要打印feign的日志,使用basic级别就ok了,强烈不建议使用full。打印日志太多,消耗feign的性能。
feign:
client:
config:
default:
loggerLevel: basic
亲测日志级别从full改为basic,高并发时, 接口QPS提升30%+
版权声明:本文为weixin_40623736原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。