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

ApiClient throttles requests in async mode #167

Open
andrewshuttlewood-masabi opened this issue Oct 11, 2024 · 0 comments
Open

ApiClient throttles requests in async mode #167

andrewshuttlewood-masabi opened this issue Oct 11, 2024 · 0 comments

Comments

@andrewshuttlewood-masabi
Copy link

andrewshuttlewood-masabi commented Oct 11, 2024

OkHttp by default only permits 5 connections to a given host in async mode. This means that in a high traffic scenario, we are capped to just 5 concurrent requests unless we manage a pool of ApiClients or create one per request, or ignore the async methods.

The number can be changed by configuring a dispatcher on the ApiClient builder to have a greater number of maxRequests and maxRequestsPerHost. I think there are a number of possible fixes:

  • The max requests is set suitably high automatically (ideally unbounded for us)
  • The max requests/max requests per host is configurable inside the merchant config
  • The client can pass in an optional Function to configure the http client builder

We did a quick test with a local fork to set this higher and this helped it work for us, the change was just:

+            Dispatcher dispatcher = new Dispatcher();
+            dispatcher.setMaxRequests(500);
+            dispatcher.setMaxRequestsPerHost(500);
           try {
               httpClient = classHttpClient.newBuilder()
+                     .dispatcher(dispatcher)

It looks like there is no significant negative impact to just setting this to Integer.MAX_VALUE - so that might be a reasonable option.

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

No branches or pull requests

1 participant