-
Notifications
You must be signed in to change notification settings - Fork 565
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhancement : Helidon Jersey Connector : Not reading the response fully causes connection to be discarded #8931
Comments
To test further we added additional line to read and discard the response. public int check(String url) {
int status;
WebTarget webTarget = client.target(url);
try(Response response = webTarget.request().accept(MediaType.APPLICATION_JSON).get()){
status = response.getStatus();
**String responseStr = response.readEntity(String.class);**
}
catch( .) {
}
return status;
} Now. We see that connections are re-used and. there is improvement in performance. Below is supporting data from our tests. We see 29% improvement in throughput while using 22.6% less CPU. |
The creation of new connections an be very expensive when it involves HTTPS end points, that involves SSL handshake. While we could say that it’s application coding issue that response is not read , it’s not uncommon for service developers to read only status or partially read the response and not read the full Response. When close() is called on the implementation of Response() , it’s clear that there won’t be further use of that Response by the app. At this point, the implementation of close() , For ex : For example Http1ClientResponseImpl.close(), method of the Response, fully read the response and re-use the connection instead of closing the physical connection . |
It looks like the HttpURLConenction in JDK code , does seem to read the remaining response, while doing a reset of the connection for reuse. |
@vasanth-bhat Seems less problematic to support this if responses are length-prefixed (include Content-Length). Is that true in your use case? |
@spericas Her is my thought , For cases where it's not feasible like, where Response is chunked ( Content-Length is not specified) , the connection is not re-used and WARNING Is logged about connection not being reused , so that app developers can see and take appropriate actions. |
We have have verified with the official fix, we no longer see the issue and the connection is reused with helidon connector even though we are not reading the response entity. |
Environment Details
Helidon connector does not reuse connection , when the Response is not Full Read , even when the client program explicitly closes the response. We again end up creating a new request each connection. Even when we are reusing the same Jersey client instance in the client code across requests.
Code Snippet is something like below where just the status is read from response and response is closed..
In the profile , we see that. the Http1ConenctionCache.keepAliveConenction() does not find the connection in the cache always ends up creating a new connection.
We debugged the issue further , and found that the connection was never getting added to the cache.
The adding to the cache happened only when connection.releaseResource() is invoked. This is invoked only when the response is fully read. ( entityFullyRead =true). rr in case where there is no response body. (Content-Length ‘0’). All other cases connection.closeResource() Is invoked which closes the connection.
The text was updated successfully, but these errors were encountered: