CyberSource / CyberSource/cybersource-rest-client-java

ApiClient throttles requests in async mode

Open
#167 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
29
Forks
50
Avg merge
28m
Merged PRs (30d)
1

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue identifies the ApiClient builder and its OkHttp HTTP client configuration as the main entry points. First inspect how async clients are constructed and how Dispatcher settings can be supplied, then resolve which of the proposed configuration approaches is intended. Done means async requests are no longer limited by OkHttp’s default five concurrent requests per host.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.