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

线程池管理问题 #102

Closed
caopengan opened this issue Sep 3, 2024 · 2 comments
Closed

线程池管理问题 #102

caopengan opened this issue Sep 3, 2024 · 2 comments

Comments

@caopengan
Copy link

caopengan commented Sep 3, 2024

ArkService中的线程池由OkHttpClient的Dispatcher管理,但未配置最大线程数、单主机最大请求数等参数。如果请求量增加并且线程池未正确关闭,则可能导致线程池无限增长,增加内存使用量,并可能导致 OutOfMemoryError。
建议:
创建OkHttpClient时,显式设置Dispatcher参数如setMaxRequests、setMaxRequestsPerHost来控制线程池的大小。

public static OkHttpClient defaultApiKeyClient(String apiKey, Duration timeout) {
        Dispatcher dispatcher = new Dispatcher();
        dispatcher.setMaxRequests("最大线程数");
        dispatcher.setMaxRequestsPerHost("单主机最大请求数");
        return new OkHttpClient.Builder()
                .addInterceptor(new AuthenticationInterceptor(apiKey))
                .addInterceptor(new RequestIdInterceptor())
                .connectionPool(new ConnectionPool(5, 1, TimeUnit.SECONDS))
                .readTimeout(timeout.toMillis(), TimeUnit.MILLISECONDS).dispatcher(dispatcher)
                .build();
    }
@volc-sdk-team
Copy link

目前已经调整示例中建议的方式,考虑到其他兼容性问题,默认的Client暂时未进行修改。
非常感谢你宝贵的建议。

@volc-sdk-team
Copy link

由于该 issue 已闲置较长时间,我们将24H后暂时关闭。如果您仍有相关问题:

  • 可以重新提交新的 issue
    我们会持续关注并及时响应您的需求。感谢您的理解!

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

3 participants