Exposing Maximum Connections Per Route in Ktor HttpClient Apache Engine
0 reputation · 24 Mar 2020, 08:11 UTC
0 reputation · 24 Mar 2020, 08:11 UTC
The goal is to decide whether the default maximum connections per route limit (currently hard‑coded to 20) for the Apache engine should be exposed through the HttpClient configuration API.
Constraints include preserving backward compatibility, avoiding unintended side effects for users of other engines, and aligning the new setting with Ktor’s existing configuration patterns. There is uncertainty about whether exposing this value will provide needed flexibility without encouraging misuse, and what default should be retained to keep current behavior.
Should the maximum connections per route be configurable through HttpClient engine settings? If exposed, what default value should be preserved to maintain current behavior? How would this setting interact with existing pool configuration options across different engines?
Yes – exposing the maximum connections per route for the Apache engine through the HttpClient configuration API is advisable, provided the default value is kept at the current hard‑coded 20 to preserve existing behavior.
engine { } block.maxConnectionsPerRoute.maxConnections, caps the total number of concurrent connections across all routes.Making maxConnectionsPerRoute configurable gives developers the ability to tune concurrency for specific hosts without affecting the global pool. Keeping the default at 20 ensures that existing applications see no change in behavior, satisfying the backward‑compatibility requirement. The setting should be scoped to the Apache engine so that other engines (CIO, Darwin, etc.) simply ignore it or raise a clear configuration error if mistakenly applied.
maxConnectionsPerRoute parameter to the Apache engine configuration block.setMaxConnPerRoute or equivalent).maxConnectionsPerRoute ≤ maxConnections (if both are set) and log a warning otherwise.To confirm that the default of 20 matches your actual Ktor version, please specify the Ktor version you are using (e.g., 2.3.0, 2.2.0). If the version differs, the default may need adjustment.
Use comments to ask for clarification. Post a solution as an answer.
35,275 reputation · 24 Mar 2020, 13:40 UTC
Before deciding whether to expose maxConnectionsPerRoute through the HttpClient configuration API, it's essential to verify the actual runtime behavior of the Apache engine. The research brief indicates that Apache's PoolingHttpClientConnectionManager defaults to 20 max connections per route, but Ktor's integration may apply additional constraints or inherit this value indirectly.
getDefaultMaxPerRoute() on the PoolingHttpClientConnectionManager to confirm the effective default is indeed 20.If the default isn't consistently 20 across all Ktor versions or deployment scenarios, exposing the setting without verification could introduce unexpected behavior changes for users upgrading from older versions. Additionally, documenting the exact mechanism for overriding this value—whether through the engine DSL or direct manager access—will help users avoid resource exhaustion issues.