The caching mechanism used by. HttpClientRequest.discoverHttpImplementation() is not working. We end up paying significant cost , when the “HelidonProperties.PROTOCOL_ID” is not explicitly set in Client Config, as it ends up making a new connection on a per request basis to discover the supported HTTP version. This connection is closed ( connection.closeResource() -> socket.close() ) after retrieving the protocol details and this happens on every request .
This is a huge overhead, especially when HTTPS endpoints are involved. This will result in SSL handshake for each such connections.
public class HttpClientRequest extends ClientRequestBase<HttpClientRequest, HttpClientResponse> {
……..
private final LruCache<EndpointKey, HttpClientSpi> clientSpiCache = LruCache.create();
private final WebClient webClient;
The clientSpiCache ideally should be static member so that cached content persists across requests. We did try out tests with this change where made this as static member so that cache is reused across requests. , This. significantly improves the performance.
Based on our tests with the sample, we. see about 47% improvement in throughput, changing the clientSpiCache to static member.
Environment Details
Docker version (if applicable):
The caching mechanism used by. HttpClientRequest.discoverHttpImplementation() is not working. We end up paying significant cost , when the “HelidonProperties.PROTOCOL_ID” is not explicitly set in Client Config, as it ends up making a new connection on a per request basis to discover the supported HTTP version. This connection is closed ( connection.closeResource() -> socket.close() ) after retrieving the protocol details and this happens on every request .
This is a huge overhead, especially when HTTPS endpoints are involved. This will result in SSL handshake for each such connections.
It looks like the issue is because the LRU cache “clientSpiCache”. used to cache the protocol version for the endpoints is an instance member and not a static member so we end up creating new empty cache for every HTTP request. https://github.com/helidon-io/helidon/blob/main/webclient/api/src/main/java/io/helidon/webclient/api/HttpClientRequest.java#L35
public class HttpClientRequest extends ClientRequestBase<HttpClientRequest, HttpClientResponse> { …….. private final LruCache<EndpointKey, HttpClientSpi> clientSpiCache = LruCache.create(); private final WebClient webClient;
The clientSpiCache ideally should be static member so that cached content persists across requests. We did try out tests with this change where made this as static member so that cache is reused across requests. , This. significantly improves the performance.
Based on our tests with the sample, we. see about 47% improvement in throughput, changing the clientSpiCache to static member.