CyberSource / CyberSource/cybersource-rest-client-java

ApiClient throttles requests in async mode

Offen
#167 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
Java
Sterne
29
Forks
50
Ø Merge
28 Min.
Gemergte PRs (30 T.)
1

Beschreibung

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.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Das Issue identifiziert den ApiClient-Builder und die Konfiguration seines OkHttp-HTTP-Clients als die wichtigsten Einstiegspunkte. Untersuche zunächst, wie asynchrone Clients erstellt werden und wie Dispatcher-Einstellungen übergeben werden können, und kläre anschließend, welcher der vorgeschlagenen Konfigurationsansätze vorgesehen ist. Erledigt ist die Aufgabe, wenn asynchrone Anfragen nicht mehr durch OkHttp’s standardmäßige fünf gleichzeitige Anfragen pro Host begrenzt sind.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
java
Bereich
api
Issue-Typ
Bug
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.