Feign客户端的性能优化
Feign客户端的性能优化
feign的请求方式是默认采用urlConnection,urlConnection是没有使用连接池,载并发情况下请求性能不佳
但是feign还支持Apache的HTTPClient以及OKHTTP去发送请求,这两种是支持连接池
在配置了连接池后,性能提升大约15%左右
性能优化1:配置连接池
HTTPClient
<dependency> <groupId>io.github.openfeign</groupId> <artifactId>feign-httpclient</artifactId> <version>10.1.0</version> </dependency>
feign: httpclient: # 让feign使用Apache HTTPClient做请求,而不是默认的urlConnection enabled: true # feign最大连接数 max-connections: 200 # feign单个路径的最大连接数 max-connections-per-route: 50
okhttp
<dependency> <groupId>io.github.openfeign</groupId> <artifactId>feign-okhttp</artifactId> <version>10.1.0</version> </dependency>
feign: httpclient: # feign最大连接数 max-connections: 200 # feign单个路径的最大连接数 max-connections-per-route: 50 okhttp: # 让feign使用Apache okhttp做请求,而不是默认的urlConnection enabled: true
性能优化2:设置合理的日志级别
在生产环境,需要打印feign的日志,使用basic级别就ok了,强烈不建议使用full。打印日志太多,消耗feign的性能。