From netstat -anp | grep I at two different times, I can see HttpClient is not re-using my connections. I connect to the same host every time with different urls such as
Why is HttpClient not just re-using the same connection to myhost.com every time?
I have the following code for intialization of the Pool that I pass to HttpClient...
PoolingClientConnectionManager mgr = new PoolingClientConnectionManager();
mgr.setDefaultMaxPerRoute(30);
mgr.setMaxTotal(30);
I see they are using an HttpRoute and have localAddress in the equals which seems odd as HttpRoute should be equal on just hostname and schema(https/http) and that is it, right? Does that have something to do with it? Is this a bug? Performance is very crappy having to re-establish https sockets every time!!!!!
If you are processing HTTP responses manually instead of using a response handler, you need to close all the http connections by yourself.
Connection pooling is specified by the SOCKETCLOSE attribute in a URIMAP resource, which defines if, and for how long, CICS keeps a socket open after the CICS application has finished using its client HTTP connection. Applications must specify the URIMAP resource when they open the connection.
You do not need to explicitly close the HttpClient, however, (you may be doing this already but worth noting) you should ensure that connections are released after method execution. Edit: The ClientConnectionManager within the HttpClient is going to be responsible for maintaining the state of connections.
HttpClient is fully thread-safe when used with a thread-safe connection manager such as MultiThreadedHttpConnectionManager.
private void stop() { // Clears HTTP/1.1 cache and close its connections connections. stop(); // Clears HTTP/2 cache and close its connections. client2. stop(); } ... }
I suspect rather strongly that SSL connections established by your applications are stateful. That is, the server requested the client to authenticate with a private certificate, making them security context specific. HttpClient detects that and prevents those connections from being leased to a caller with a different security context. Effectively HttpClient is playing safe by forcing a new connection for each request rather than risking leasing persistent SSL connection to the wrong user.
You can do two things here
For details see this section of the HttpClient tutorial
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With