Synchronous API with Shared HttpClient vs AsyncClient with Executor Service: Which mitigates latency under concurrent 3DS requests?
0 reputation · 26 Apr 2020, 10:01 UTC
0 reputation · 26 Apr 2020, 10:01 UTC
The goal is to determine whether employing a single shared HttpClient instance with the synchronous threedsmax API or leveraging the documented AsyncClient interface with an executor service results in lower latency spikes when issuing concurrent 3DS authentication requests.
Constraints include the lack of an explicit thread‑safety guarantee for the shared HttpClient, potential contention on the same connection manager, and the risk of executor thread exhaustion when many requests are dispatched asynchronously.
Uncertainty remains about whether the library internally synchronizes access to the HttpClient during concurrent usage, and how the AsyncClient’s executor behaves under load.
34775 reputation · 26 Apr 2020, 21:33 UTC
threedsmax library does not add its own synchronization around a shared HttpClient. Thread safety and latency mitigation depend entirely on the underlying implementation (e.g., PoolingHttpClientConnectionManager). Using an AsyncClient backed by a fixed-size executor typically results in lower 95th-percentile latency and fewer spikes than a shared synchronous HttpClient because it offloads I/O to worker threads, preventing the calling application thread from blocking.
When issuing concurrent 3DS authentication requests, the primary bottleneck is often contention at the connection manager. If the shared HttpClient is used without a pooling mechanism, multiple threads will contend for the same socket, leading to significant latency spikes and potential connection exhaustion.
AsyncClient with a fixed thread pool provides more predictable performance. By decoupling the request dispatch from the execution, it avoids head-of-line blocking in the application logic.pool size = CPU cores × 2, paired with a bounded queue and a defined rejection policy.Executors.newFixedThreadPool(N). Record average and 99-percentile latency.AsyncClient documentation for the recommended pool-size formula and queue limits to prevent unbounded thread growth.What specific HTTP client implementation and version are you using (e.g., Apache HttpClient 4.5, 5.x, or another provider)? The internal behavior of the connection manager regarding locking varies significantly between these versions.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.