-
Notifications
You must be signed in to change notification settings - Fork 967
Open
Description
Summary
The current implementation resolves (it may hit cache, though) DNS for every request before checking the connection pool, which can introduce unnecessary DNS queries even when pooled connections are available.
Expected behavior
Ideally, the client should:
- Check the connection pool for an existing connection, ie using the hostname
- Only resolve DNS if no pooled connection exists
This would minimize DNS queries, and in other words, only resolving DNS when needing to create new connections.
Actual behavior
Currently in HttpClientDelegate.execute():
- DNS resolution happens first (if
endpoint.hasIpAddr()returns false) - Then connection pool lookup occurs with the resolved IP
See:
armeria/core/src/main/java/com/linecorp/armeria/client/HttpClientDelegate.java
Lines 125 to 139 in a74b849
| if (endpointWithPort.hasIpAddr() || | |
| proxyConfig.proxyType().isForwardProxy()) { | |
| // There is no need to resolve the IP address either because it is already known, | |
| // or it isn't needed for forward proxies. | |
| acquireConnectionAndExecute(ctx, endpointWithPort, req, res, timingsBuilder, proxyConfig); | |
| } else { | |
| resolveAddress(endpointWithPort, ctx, (resolved, cause) -> { | |
| timingsBuilder.dnsResolutionEnd(); | |
| if (cause == null) { | |
| assert resolved != null; | |
| acquireConnectionAndExecute(ctx, resolved, req, res, timingsBuilder, proxyConfig); | |
| } else { | |
| earlyCancelRequest(cause, ctx, timingsBuilder); | |
| } | |
| }); |
Why this is a problem
This means:
- Every request must resolve DNS
- It may create high load to the DNS server, even with DNS cache or refresh
sh-cho
Metadata
Metadata
Assignees
Labels
No labels