Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

考虑支持 maxRequests、maxRequestsPerHost 的配置吗 #111

Closed
daliandazi opened this issue May 10, 2022 · 5 comments
Closed

考虑支持 maxRequests、maxRequestsPerHost 的配置吗 #111

daliandazi opened this issue May 10, 2022 · 5 comments

Comments

@daliandazi
Copy link

内部服务之间用OKHTTP调用,默认的maxRequests、maxRequestsPerHost太小限制了并发量,生产环境对这2个参数做了调整后效果还是比较明显;retrofit-spring-boot-starter 虽然可以用代码自定义注入OkHttpClient并做很多自定义配置,但是不够优雅便捷。

@chentianming11
Copy link
Collaborator

确实可以考虑扩充一些配置参数。

请问下maxRequests、maxRequestsPerHost 怎么设置到OkHttp的?我在Builder类上没找到

@daliandazi
Copy link
Author

在Dispatcher中设置,需要自定义初始化 Dispatcher,如下:

 int maxRequests = 100;
 ExecutorService dispatchExecutor = new ThreadPoolExecutor(5, maxRequests, 60, TimeUnit.SECONDS,
                new SynchronousQueue<>(), Util.threadFactory("OkHttp Dispatcher XXX", false), new ThreadPoolExecutor.DiscardPolicy());
        Dispatcher dispatcher = new Dispatcher(dispatchExecutor);
        dispatcher.setMaxRequests(maxRequests);
        dispatcher.setMaxRequestsPerHost(maxRequests);

Builder的dispatcher(dispatcher)方法传进去就行了。

@chentianming11
Copy link
Collaborator

https://github.com/LianjiaTech/retrofit-spring-boot-starter/releases/tag/2.3.3

2.3.3版本重构了自定义OkHttpClient属性。你这个需求可以自行注入支持了。具体看文档:
https://github.com/LianjiaTech/retrofit-spring-boot-starter#%E8%87%AA%E5%AE%9A%E4%B9%89OkHttpClient%E5%B1%9E%E6%80%A7

@daliandazi
Copy link
Author

@chentianming11 我目前是自己注入的OkHttpClient,想着如果可以通过配置文件实现,就更加优雅便捷。

@chentianming11
Copy link
Collaborator

chentianming11 commented May 24, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants