Discussion:
Migration from Async 4.1.3 to HttpClient 5
Joan Balagueró
2018-10-19 13:08:41 UTC
Permalink
Hello,



We are in the process of migrating to HttpClient5 from AsyncClient4.1.3, and
we have some quiestions:



1. this.rc = RequestConfig.custom().setAuthenticationEnabled(false).


setConnectionRequestTimeout(Timeout.ofMillis(this.poolTimeout)).


setConnectionRequestTimeout(this.poolTimeout, TimeUnit.MILLISECONDS).


setConnectionTimeout(Timeout.ofMillis(this.connectionTimeout)).


setConnectTimeout(this.connectionTimeout, TimeUnit.MILLISECONDS).



I wrote here the 4 possible methods ‘setConnectionxxxxx’.
The two first have the same name and different parameters, two ways to do
the same.

But the next two methods seem to be the same, but the method names are
different. Shouldn’t the fourth method be ‘setConnectionTimeout’ as well?





2. The
PoolingAsyncClientConnectionManagerBuilder.setConnectionTimeToLive() is the
keep alive to set to connections in this pool?

(similar to what we do in HttpAsyncClients.custom().setKeepAliveStrategy()?)



3. In previous AsyncClient, we set the setSocketTimeout at
RequestConfig level, so on each request I could copy this base ‘rc’ and
modify the response timeout.

But this method does no longer exist in RequestConfig. Where can I set the
response timeout now for each request?



4. I imagine the PoolConcurrencyPolicy cannot be modified after
creating the pool …



5. Before I had this method to set buffer sizes (and modify them on
the fly), getting the ConnectionConfig from the pool:



public void setBufferInInterface(int bufferInInterface) {


this.phccm.setDefaultConnectionConfig(ConnectionConfig.custom().setBufferSiz
e(bufferInInterface).setFragmentSizeHint(bufferInInterface).build());

}



How can I do this now?





Thanks,



Joan.
Oleg Kalnichevski
2018-10-19 15:21:19 UTC
Permalink
Post by Joan Balagueró
Hello,
We are in the process of migrating to HttpClient5 from
AsyncClient4.1.3, and
1. this.rc =
RequestConfig.custom().setAuthenticationEnabled(false).
setConnectionRequestTimeout(Timeout.ofMillis(this.poolTimeout)).
setConnectionRequestTimeout(this.poolTimeout, TimeUnit.MILLISECONDS).
setConnectionTimeout(Timeout.ofMillis(this.connectionTimeout)).
setConnectTimeout(this.connectionTimeout, TimeUnit.MILLISECONDS).
#setConnectTimeout was left out by mistake. It got removed after 5.0-
beta1

https://github.com/apache/httpcomponents-client/commit/60571ae8fa89918518fed57bc5a9785362f9a39a
Post by Joan Balagueró
2. The
PoolingAsyncClientConnectionManagerBuilder.setConnectionTimeToLive() is the
keep alive to set to connections in this pool?
(similar to what we do in
HttpAsyncClients.custom().setKeepAliveStrategy()?)
PoolingAsyncClientConnectionManagerBuilder#setConnectionTimeToLive sets
the _total_ time to live for any connection. No connection will be kept
alive past its TTL (time to live). Keep-alive time is always
incremental.
Post by Joan Balagueró
3. In previous AsyncClient, we set the setSocketTimeout at
RequestConfig level, so on each request I could copy this base ‘rc’
and
modify the response timeout.
But this method does no longer exist in RequestConfig. Where can I set the
response timeout now for each request?
With HTTP/2 a single request can no longer alter the socket timeout for
the connection shared with other message streams. One needs to set the
socket timeout while building HttpAsyncClient instances with
IOReactorConfig

https://github.com/apache/httpcomponents-client/blob/master/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientBuilder.java#L317
Post by Joan Balagueró
4. I imagine the PoolConcurrencyPolicy cannot be modified after
creating the pool …
No, it cannot.
Post by Joan Balagueró
5. Before I had this method to set buffer sizes (and modify them on
public void setBufferInInterface(int bufferInInterface) {
this.phccm.setDefaultConnectionConfig(ConnectionConfig.custom().setBu
fferSiz
e(bufferInInterface).setFragmentSizeHint(bufferInInterface).build());
}
How can I do this now?
Why would you want to modify those settings at runetime?

Oleg


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org
Joan Balagueró
2018-10-19 16:01:12 UTC
Permalink
Hi Oleg,

Thanks a lot for all your answers. I'll work on this a bit more.

There is just one problematic thing for us. Our app is an api gateway, and one important piece is the response timeouts between our app and the client application servers. If fact, it's common the user changes these response timeouts from the admin console.

If now they cannot change them on the fly, that means stopping the http pool, recreating the ioreactor with the new timeout and starting the pool again, even if this takes just several seconds is something I cannot do with installations that are processing more than 15.000 requests per second.

The main purpose to move to HttpClient5 is the http pool with Lax Max connections (PoolConcurrencyPolicy.LAX), because we were detecting contention on the current pool due to the global lock. We don't need HTTP/2 so, from my ignorance, is there any way to use a Lax Pool with http1.1 in order to get this socket timeout at request level?

Thanks,

Joan.

-----Mensaje original-----
De: Oleg Kalnichevski [mailto:***@apache.org]
Enviado el: viernes, 19 de octubre de 2018 17:21
Para: HttpClient User Discussion
Asunto: Re: Migration from Async 4.1.3 to HttpClient 5
Post by Joan Balagueró
Hello,
We are in the process of migrating to HttpClient5 from
1. this.rc =
RequestConfig.custom().setAuthenticationEnabled(false).
setConnectionRequestTimeout(Timeout.ofMillis(this.poolTimeout)).
setConnectionRequestTimeout(this.poolTimeout, TimeUnit.MILLISECONDS).
setConnectionTimeout(Timeout.ofMillis(this.connectionTimeout)).
setConnectTimeout(this.connectionTimeout, TimeUnit.MILLISECONDS).
#setConnectTimeout was left out by mistake. It got removed after 5.0-
beta1

https://github.com/apache/httpcomponents-client/commit/60571ae8fa89918518fed57bc5a9785362f9a39a
Post by Joan Balagueró
2. The
PoolingAsyncClientConnectionManagerBuilder.setConnectionTimeToLive() is the
keep alive to set to connections in this pool?
(similar to what we do in
HttpAsyncClients.custom().setKeepAliveStrategy()?)
PoolingAsyncClientConnectionManagerBuilder#setConnectionTimeToLive sets the _total_ time to live for any connection. No connection will be kept alive past its TTL (time to live). Keep-alive time is always incremental.
Post by Joan Balagueró
3. In previous AsyncClient, we set the setSocketTimeout at
RequestConfig level, so on each request I could copy this base ‘rc’
and
modify the response timeout.
But this method does no longer exist in RequestConfig. Where can I set
the response timeout now for each request?
With HTTP/2 a single request can no longer alter the socket timeout for
the connection shared with other message streams. One needs to set the
socket timeout while building HttpAsyncClient instances with
IOReactorConfig

https://github.com/apache/httpcomponents-client/blob/master/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientBuilder.java#L317
Post by Joan Balagueró
4. I imagine the PoolConcurrencyPolicy cannot be modified after
creating the pool …
No, it cannot.
Post by Joan Balagueró
5. Before I had this method to set buffer sizes (and modify them on
public void setBufferInInterface(int bufferInInterface) {
this.phccm.setDefaultConnectionConfig(ConnectionConfig.custom().setBu
fferSiz
e(bufferInInterface).setFragmentSizeHint(bufferInInterface).build());
}
How can I do this now?
Why would you want to modify those settings at runetime?

Oleg


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org
Oleg Kalnichevski
2018-10-19 16:21:45 UTC
Permalink
Post by Joan Balagueró
Hi Oleg,
Thanks a lot for all your answers. I'll work on this a bit more.
There is just one problematic thing for us. Our app is an api
gateway, and one important piece is the response timeouts between our
app and the client application servers. If fact, it's common the user
changes these response timeouts from the admin console.
If now they cannot change them on the fly, that means stopping the
http pool, recreating the ioreactor with the new timeout and starting
the pool again, even if this takes just several seconds is something
I cannot do with installations that are processing more than 15.000
requests per second.
The main purpose to move to HttpClient5 is the http pool with Lax Max
connections (PoolConcurrencyPolicy.LAX), because we were detecting
contention on the current pool due to the global lock. We don't need
HTTP/2 so, from my ignorance, is there any way to use a Lax Pool
with http1.1 in order to get this socket timeout at request level?
No, there is not. There will be no request level socket timeout
override in HC 5.0 because even with HTTP/1.1 it makes no sense when
messages are being pipelined.

HC 5.0 could however provide APIs to enumerate all open connection and
let their socket timeout get re-set. Feel free to raise a change
request for this feature or better yet contribute it.

Oleg



---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org
Joan Balagueró
2018-10-19 19:07:44 UTC
Permalink
Hello Oleg,

I think it's a bit more complicated ... Let me explain it:

- we have a pool with a response timeout of 15s
- this pool is shared by 2 webservices, ws1 and ws2. Ws1 uses the pool's response timeout, but ws2 uses its own response timeout of 10s.
- the webservice ws2 has 2 methods, m1 and m2, m1 uses the ws2 timeout but m2 uses its own response timeout of 12s.
- and finally the method m2 is used by 2 clients, c1 and c2. c1 is a very good client so his response timeout is 20s, and c2 is very bad so he only has a 3s response timeout.

When we set the response timeout at request level, we do this:

/**
* This method sets the 'responseTimeout' to this http method.
*
* @param RequestBuilder the 'RequestBuilder' object
* @param responseTimeout the response timeout to apply
* @return none
*/
private void setTimeout(RequestBuilder rb)
{
// 1. If the client has a timeout (clientResponseTimeout != -1), then set this value
// 2. If the client has no timeout but the method has, then set this value.
// 3. If the method has no timeout but the api has, then set this value.
// 4. Otherwise set the pool's response timeout.
int clientResponseTimeout = this.objClient.getResponseTimeout(this.objCall.getId());
int responseTimeout = (clientResponseTimeout != -1 ? clientResponseTimeout : (this.objCall.getResponseTimeout() != -1 ? this.objCall.getResponseTimeout() : (this.objInterface.getResponseTimeout() != -1 ? this.objInterface.getResponseTimeout() : this.objHttp.getResponseTimeout())) );
rb.setConfig(RequestConfig.copy(this.objHttp.getRequestConfig()).setSocketTimeout(responseTimeout).build());
}

And that's my problem now. Do you think this can be solved in any way using http5?

Thanks,

Joan.



-----Mensaje original-----
De: Oleg Kalnichevski [mailto:***@apache.org]
Enviado el: viernes, 19 de octubre de 2018 18:22
Para: HttpClient User Discussion
Asunto: Re: Migration from Async 4.1.3 to HttpClient 5
Post by Joan Balagueró
Hi Oleg,
Thanks a lot for all your answers. I'll work on this a bit more.
There is just one problematic thing for us. Our app is an api gateway,
and one important piece is the response timeouts between our app and
the client application servers. If fact, it's common the user changes
these response timeouts from the admin console.
If now they cannot change them on the fly, that means stopping the
http pool, recreating the ioreactor with the new timeout and starting
the pool again, even if this takes just several seconds is something I
cannot do with installations that are processing more than 15.000
requests per second.
The main purpose to move to HttpClient5 is the http pool with Lax Max
connections (PoolConcurrencyPolicy.LAX), because we were detecting
contention on the current pool due to the global lock. We don't need
HTTP/2 so, from my ignorance, is there any way to use a Lax Pool with
http1.1 in order to get this socket timeout at request level?
No, there is not. There will be no request level socket timeout override in HC 5.0 because even with HTTP/1.1 it makes no sense when messages are being pipelined.

HC 5.0 could however provide APIs to enumerate all open connection and let their socket timeout get re-set. Feel free to raise a change request for this feature or better yet contribute it.

Oleg



---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org
Oleg Kalnichevski
2018-10-20 16:17:07 UTC
Permalink
Post by Joan Balagueró
Hello Oleg,
- we have a pool with a response timeout of 15s
- this pool is shared by 2 webservices, ws1 and ws2. Ws1 uses the
pool's response timeout, but ws2 uses its own response timeout of
10s.
- the webservice ws2 has 2 methods, m1 and m2, m1 uses the ws2
timeout but m2 uses its own response timeout of 12s.
- and finally the method m2 is used by 2 clients, c1 and c2. c1 is a
very good client so his response timeout is 20s, and c2 is very bad
so he only has a 3s response timeout.
/**
* This method sets the 'responseTimeout' to this http method.
*
object
to apply
*/
private void setTimeout(RequestBuilder rb)
{
// 1. If the client has a timeout (clientResponseTimeout != -1), then set this value
// 2. If the client has no timeout but the method has, then set this value.
// 3. If the method has no timeout but the api has, then set this value.
// 4. Otherwise set the pool's response timeout.
int clientResponseTimeout =
this.objClient.getResponseTimeout(this.objCall.getId());
int responseTimeout = (clientResponseTimeout != -1 ?
clientResponseTimeout : (this.objCall.getResponseTimeout() != -1 ?
(this.objInterface.getResponseTimeout() != -1 ?
this.objHttp.getResponseTimeout())) );
rb.setConfig(RequestConfig.copy(this.objHttp.getRequestConfig()).setS
ocketTimeout(responseTimeout).build());
}
And that's my problem now. Do you think this can be solved in any way using http5?
I must admit I do not understand the reason for doing all that in the
first place. I also do not understand what exactly you mean by response
timeout. Max waiting time until a response head is received?

Oleg


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org
Joan Balagueró
2018-10-20 17:57:23 UTC
Permalink
Hi Oleg,

I must admit I do not understand the reason for doing all that in the first place.
--> It doesn't matter, it's important for B2B integrations in tourism sector, but that's another story.

I also do not understand what exactly you mean by response timeout. Max waiting time until a response head is received?
--> Yes, if we have a response timeout of 15s this is the maximum time our app will wait for getting a response from the application servers once the request has been sent. And yes, this is when response headers start to arrive (and read on 'responseReceived' method).

Thanks,

Joan.


-----Mensaje original-----
De: Oleg Kalnichevski [mailto:***@apache.org]
Enviado el: sábado, 20 de octubre de 2018 18:17
Para: HttpClient User Discussion
Asunto: Re: Migration from Async 4.1.3 to HttpClient 5
Post by Joan Balagueró
Hello Oleg,
- we have a pool with a response timeout of 15s
- this pool is shared by 2 webservices, ws1 and ws2. Ws1 uses the
pool's response timeout, but ws2 uses its own response timeout of 10s.
- the webservice ws2 has 2 methods, m1 and m2, m1 uses the ws2 timeout
but m2 uses its own response timeout of 12s.
- and finally the method m2 is used by 2 clients, c1 and c2. c1 is a
very good client so his response timeout is 20s, and c2 is very bad so
he only has a 3s response timeout.
/**
* This method sets the 'responseTimeout' to this http method.
*
object
to apply
*/
private void setTimeout(RequestBuilder rb) {
// 1. If the client has a timeout (clientResponseTimeout != -1), then set this value
// 2. If the client has no timeout but the method has, then set this value.
// 3. If the method has no timeout but the api has, then set this value.
// 4. Otherwise set the pool's response timeout.
int clientResponseTimeout =
this.objClient.getResponseTimeout(this.objCall.getId());
int responseTimeout = (clientResponseTimeout != -1 ?
clientResponseTimeout : (this.objCall.getResponseTimeout() != -1 ?
(this.objInterface.getResponseTimeout() != -1 ?
this.objHttp.getResponseTimeout())) );
rb.setConfig(RequestConfig.copy(this.objHttp.getRequestConfig()).setS
ocketTimeout(responseTimeout).build());
}
And that's my problem now. Do you think this can be solved in any way using http5?
Oleg


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org
Joan Balagueró
2018-10-20 18:23:06 UTC
Permalink
Ok, I understand whtat you mean. Since this is a non-blocking model when we send the request the thread is released, so I simply have to count the time passed from I send the response until the 'responseReceived' method is invoked, and if this time has been exceeded just throw an exception (and avoid read the response body content).

Thanks,
Joan.

-----Mensaje original-----
De: Oleg Kalnichevski [mailto:***@apache.org]
Enviado el: sábado, 20 de octubre de 2018 18:17
Para: HttpClient User Discussion
Asunto: Re: Migration from Async 4.1.3 to HttpClient 5
Post by Joan Balagueró
Hello Oleg,
- we have a pool with a response timeout of 15s
- this pool is shared by 2 webservices, ws1 and ws2. Ws1 uses the
pool's response timeout, but ws2 uses its own response timeout of 10s.
- the webservice ws2 has 2 methods, m1 and m2, m1 uses the ws2 timeout
but m2 uses its own response timeout of 12s.
- and finally the method m2 is used by 2 clients, c1 and c2. c1 is a
very good client so his response timeout is 20s, and c2 is very bad so
he only has a 3s response timeout.
/**
* This method sets the 'responseTimeout' to this http method.
*
object
to apply
*/
private void setTimeout(RequestBuilder rb) {
// 1. If the client has a timeout (clientResponseTimeout != -1), then set this value
// 2. If the client has no timeout but the method has, then set this value.
// 3. If the method has no timeout but the api has, then set this value.
// 4. Otherwise set the pool's response timeout.
int clientResponseTimeout =
this.objClient.getResponseTimeout(this.objCall.getId());
int responseTimeout = (clientResponseTimeout != -1 ?
clientResponseTimeout : (this.objCall.getResponseTimeout() != -1 ?
(this.objInterface.getResponseTimeout() != -1 ?
this.objHttp.getResponseTimeout())) );
rb.setConfig(RequestConfig.copy(this.objHttp.getRequestConfig()).setS
ocketTimeout(responseTimeout).build());
}
And that's my problem now. Do you think this can be solved in any way using http5?
I must admit I do not understand the reason for doing all that in the first place. I also do not understand what exactly you mean by response timeout. Max waiting time until a response head is received?

Oleg


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org
Oleg Kalnichevski
2018-10-21 11:11:06 UTC
Permalink
Post by Joan Balagueró
Ok, I understand whtat you mean. Since this is a non-blocking model
when we send the request the thread is released, so I simply have to
count the time passed from I send the response until the
'responseReceived' method is invoked, and if this time has been
exceeded just throw an exception (and avoid read the response body
content).
Thanks,
Joan.
Hi Joan

That will likely require an observer thread and creating a thread per
request can be expensive.

I will see if there is a way provide a socket timeout per request
setting for HTTP/1.1 transport only without exposing the same setting
to HTTP/2 transport.

Oleg

-----Mensaje original-----
Post by Joan Balagueró
Enviado el: sábado, 20 de octubre de 2018 18:17
Para: HttpClient User Discussion
Asunto: Re: Migration from Async 4.1.3 to HttpClient 5
Post by Joan Balagueró
Hello Oleg,
- we have a pool with a response timeout of 15s
- this pool is shared by 2 webservices, ws1 and ws2. Ws1 uses the
pool's response timeout, but ws2 uses its own response timeout of 10s.
- the webservice ws2 has 2 methods, m1 and m2, m1 uses the ws2 timeout
but m2 uses its own response timeout of 12s.
- and finally the method m2 is used by 2 clients, c1 and c2. c1 is a
very good client so his response timeout is 20s, and c2 is very bad so
he only has a 3s response timeout.
/**
* This method sets the 'responseTimeout' to this http method.
*
'RequestBuilder'
object
timeout
to apply
*/
private void setTimeout(RequestBuilder rb) {
// 1. If the client has a timeout (clientResponseTimeout != -1), then set this value
// 2. If the client has no timeout but the method has, then set
this
value.
// 3. If the method has no timeout but the api has, then set
this
value.
// 4. Otherwise set the pool's response timeout.
int clientResponseTimeout =
this.objClient.getResponseTimeout(this.objCall.getId());
int responseTimeout = (clientResponseTimeout != -1 ?
clientResponseTimeout : (this.objCall.getResponseTimeout() != -1 ?
(this.objInterface.getResponseTimeout() != -1 ?
this.objHttp.getResponseTimeout())) );
rb.setConfig(RequestConfig.copy(this.objHttp.getRequestConfig()).se
tS
ocketTimeout(responseTimeout).build());
}
And that's my problem now. Do you think this can be solved in any
way
using http5?
I must admit I do not understand the reason for doing all that in the
first place. I also do not understand what exactly you mean by
response timeout. Max waiting time until a response head is
received?
Oleg
---------------------------------------------------------------------
---------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org
Joan Balagueró
2018-10-22 18:40:14 UTC
Permalink
That would be great.
Thanks Oleg.

-----Mensaje original-----
De: Oleg Kalnichevski [mailto:***@apache.org]
Enviado el: domingo, 21 de octubre de 2018 13:11
Para: HttpClient User Discussion
Asunto: Re: Migration from Async 4.1.3 to HttpClient 5
Post by Joan Balagueró
Ok, I understand whtat you mean. Since this is a non-blocking model
when we send the request the thread is released, so I simply have to
count the time passed from I send the response until the
'responseReceived' method is invoked, and if this time has been
exceeded just throw an exception (and avoid read the response body
content).
Thanks,
Joan.
Hi Joan

That will likely require an observer thread and creating a thread per request can be expensive.

I will see if there is a way provide a socket timeout per request setting for HTTP/1.1 transport only without exposing the same setting to HTTP/2 transport.

Oleg

-----Mensaje original-----
Post by Joan Balagueró
de octubre de 2018 18:17
Para: HttpClient User Discussion
Asunto: Re: Migration from Async 4.1.3 to HttpClient 5
Post by Joan Balagueró
Hello Oleg,
- we have a pool with a response timeout of 15s
- this pool is shared by 2 webservices, ws1 and ws2. Ws1 uses the
pool's response timeout, but ws2 uses its own response timeout of 10s.
- the webservice ws2 has 2 methods, m1 and m2, m1 uses the ws2
timeout but m2 uses its own response timeout of 12s.
- and finally the method m2 is used by 2 clients, c1 and c2. c1 is a
very good client so his response timeout is 20s, and c2 is very bad
so he only has a 3s response timeout.
/**
* This method sets the 'responseTimeout' to this http method.
*
'RequestBuilder'
object
timeout
to apply
*/
private void setTimeout(RequestBuilder rb) {
// 1. If the client has a timeout (clientResponseTimeout != -1), then set this value
// 2. If the client has no timeout but the method has, then set this value.
// 3. If the method has no timeout but the api has, then set this value.
// 4. Otherwise set the pool's response timeout.
int clientResponseTimeout =
this.objClient.getResponseTimeout(this.objCall.getId());
int responseTimeout = (clientResponseTimeout != -1 ?
clientResponseTimeout : (this.objCall.getResponseTimeout() != -1 ?
(this.objInterface.getResponseTimeout() != -1 ?
this.objHttp.getResponseTimeout())) );
rb.setConfig(RequestConfig.copy(this.objHttp.getRequestConfig()).se
tS
ocketTimeout(responseTimeout).build());
}
And that's my problem now. Do you think this can be solved in any way using http5?
I must admit I do not understand the reason for doing all that in the
first place. I also do not understand what exactly you mean by
response timeout. Max waiting time until a response head is received?
Oleg
---------------------------------------------------------------------
---------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org
Oleg Kalnichevski
2018-10-23 07:27:59 UTC
Permalink
Post by Joan Balagueró
That would be great.
Thanks Oleg.
Hi Joan

I added #responseTimeout to RequestConfig that will work the same way
as socket timeout in 4.1 for HTTP/1.1 transport

https://github.com/apache/httpcomponents-client/commit/75ca519314b783ba0d314e84f3a7e3488a7c968c

Oleg
Post by Joan Balagueró
-----Mensaje original-----
Enviado el: domingo, 21 de octubre de 2018 13:11
Para: HttpClient User Discussion
Asunto: Re: Migration from Async 4.1.3 to HttpClient 5
Post by Joan Balagueró
Ok, I understand whtat you mean. Since this is a non-blocking model
when we send the request the thread is released, so I simply have to
count the time passed from I send the response until the
'responseReceived' method is invoked, and if this time has been
exceeded just throw an exception (and avoid read the response body
content).
Thanks,
Joan.
Hi Joan
That will likely require an observer thread and creating a thread per
request can be expensive.
I will see if there is a way provide a socket timeout per request
setting for HTTP/1.1 transport only without exposing the same setting
to HTTP/2 transport.
Oleg
-----Mensaje original-----
Post by Joan Balagueró
de octubre de 2018 18:17
Para: HttpClient User Discussion
Asunto: Re: Migration from Async 4.1.3 to HttpClient 5
Post by Joan Balagueró
Hello Oleg,
- we have a pool with a response timeout of 15s
- this pool is shared by 2 webservices, ws1 and ws2. Ws1 uses the
pool's response timeout, but ws2 uses its own response timeout of
10s.
- the webservice ws2 has 2 methods, m1 and m2, m1 uses the ws2
timeout but m2 uses its own response timeout of 12s.
- and finally the method m2 is used by 2 clients, c1 and c2. c1 is a
very good client so his response timeout is 20s, and c2 is very bad
so he only has a 3s response timeout.
/**
* This method sets the 'responseTimeout' to this http method.
*
'RequestBuilder'
object
response
timeout
to apply
*/
private void setTimeout(RequestBuilder rb) {
// 1. If the client has a timeout (clientResponseTimeout !=
-1),
then set this value
// 2. If the client has no timeout but the method has, then set
this value.
// 3. If the method has no timeout but the api has, then set
this
value.
// 4. Otherwise set the pool's response timeout.
int clientResponseTimeout =
this.objClient.getResponseTimeout(this.objCall.getId());
int responseTimeout = (clientResponseTimeout != -1 ?
clientResponseTimeout : (this.objCall.getResponseTimeout() != -1 ?
(this.objInterface.getResponseTimeout() != -1 ?
this.objHttp.getResponseTimeout())) );
rb.setConfig(RequestConfig.copy(this.objHttp.getRequestConfig()).
se
tS
ocketTimeout(responseTimeout).build());
}
And that's my problem now. Do you think this can be solved in any
way using http5?
I must admit I do not understand the reason for doing all that in the
first place. I also do not understand what exactly you mean by
response timeout. Max waiting time until a response head is
received?
Oleg
-----------------------------------------------------------------
----
-----------------------------------------------------------------
----
---------------------------------------------------------------------
---------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org
Joan Balagueró
2018-10-23 17:02:45 UTC
Permalink
Hi Oleg,

Thanks! I'll try it asap

Joan.

-----Mensaje original-----
De: Oleg Kalnichevski [mailto:***@apache.org]
Enviado el: martes, 23 de octubre de 2018 9:28
Para: HttpClient User Discussion
Asunto: Re: Migration from Async 4.1.3 to HttpClient 5
Post by Joan Balagueró
That would be great.
Thanks Oleg.
Hi Joan

I added #responseTimeout to RequestConfig that will work the same way as socket timeout in 4.1 for HTTP/1.1 transport

https://github.com/apache/httpcomponents-client/commit/75ca519314b783ba0d314e84f3a7e3488a7c968c

Oleg
Post by Joan Balagueró
-----Mensaje original-----
21 de octubre de 2018 13:11
Para: HttpClient User Discussion
Asunto: Re: Migration from Async 4.1.3 to HttpClient 5
Post by Joan Balagueró
Ok, I understand whtat you mean. Since this is a non-blocking model
when we send the request the thread is released, so I simply have to
count the time passed from I send the response until the
'responseReceived' method is invoked, and if this time has been
exceeded just throw an exception (and avoid read the response body
content).
Thanks,
Joan.
Hi Joan
That will likely require an observer thread and creating a thread per
request can be expensive.
I will see if there is a way provide a socket timeout per request
setting for HTTP/1.1 transport only without exposing the same setting
to HTTP/2 transport.
Oleg
-----Mensaje original-----
Post by Joan Balagueró
de octubre de 2018 18:17
Para: HttpClient User Discussion
Asunto: Re: Migration from Async 4.1.3 to HttpClient 5
Post by Joan Balagueró
Hello Oleg,
- we have a pool with a response timeout of 15s
- this pool is shared by 2 webservices, ws1 and ws2. Ws1 uses the
pool's response timeout, but ws2 uses its own response timeout of 10s.
- the webservice ws2 has 2 methods, m1 and m2, m1 uses the ws2
timeout but m2 uses its own response timeout of 12s.
- and finally the method m2 is used by 2 clients, c1 and c2. c1 is
a very good client so his response timeout is 20s, and c2 is very
bad so he only has a 3s response timeout.
/**
* This method sets the 'responseTimeout' to this http method.
*
'RequestBuilder'
object
response
timeout
to apply
*/
private void setTimeout(RequestBuilder rb) {
// 1. If the client has a timeout (clientResponseTimeout != -1),
then set this value
// 2. If the client has no timeout but the method has, then set this value.
// 3. If the method has no timeout but the api has, then set this value.
// 4. Otherwise set the pool's response timeout.
int clientResponseTimeout =
this.objClient.getResponseTimeout(this.objCall.getId());
int responseTimeout = (clientResponseTimeout != -1 ?
clientResponseTimeout : (this.objCall.getResponseTimeout() != -1 ?
(this.objInterface.getResponseTimeout() != -1 ?
this.objHttp.getResponseTimeout())) );
rb.setConfig(RequestConfig.copy(this.objHttp.getRequestConfig()).
se
tS
ocketTimeout(responseTimeout).build());
}
And that's my problem now. Do you think this can be solved in any way using http5?
I must admit I do not understand the reason for doing all that in
the first place. I also do not understand what exactly you mean by
response timeout. Max waiting time until a response head is
received?
Oleg
-----------------------------------------------------------------
----
-----------------------------------------------------------------
----
---------------------------------------------------------------------
---------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org
Joan Balagueró
2018-11-07 18:30:07 UTC
Permalink
Hello Oleg,

We are finishing the migration and have the last questions:

1. If a connection is kept-alive for 30s at second 0, and after 10s is reused, this connection will die at second 30 or will survive until second 40?

2. Regarding the RetryHandler, below the method inherited from http 4.5 and modified to work with http5:

public boolean retryRequest(HttpRequest request, IOException exception, int executionCount, HttpContext context)
{
// Don't retry if max retries are reached.
if (executionCount > this.maxExecutionCount) return false;

// Don't retry if any of these exceptions occur.
if (exception instanceof InterruptedIOException || exception instanceof UnknownHostException || exception instanceof ConnectException || exception instanceof SSLException) return false;

// Retry of if this request is considered 'idempotent'.
return (!(request instanceof HttpEntityEnclosingRequest));
}

I understand the first two conditions are still ok (not sure if we have to add new exceptions on that list) but regarding the last condition,what would the equivalent condition be in Http5?


3. We have increased the response time of our backend (ip ended with '182') in order to exhaust the strict/lax pool. When this happens the pool starts to throw a DeadlineTimeoutException. At this moment the number of sockets in TIME_WAIT increases a lot until making the server unresponsive (probably exhausting the local ports):

[***@ns3103538 ~]# netstat -anp | grep TIME_WAIT | grep "179.182" | wc -l
99
[***@ns3103538 ~]# netstat -anp | grep TIME_WAIT | grep "179.182" | wc -l
101
[***@ns3103538 ~]# netstat -anp | grep TIME_WAIT | grep "179.182" | wc -l
98
[***@ns3103538 ~]# netstat -anp | grep TIME_WAIT | grep "179.182" | wc -l
25876
[***@ns3103538 ~]# netstat -anp | grep TIME_WAIT | grep "179.182" | wc -l
61507
[***@ns3103538 ~]# netstat -anp | grep TIME_WAIT | grep "179.182" | wc -l
97615

Is this the right behaviour? If Http5 cannot create new connections, so no new sockets are opened, why does the number of sockets in TIME_WAIT raise at those values?


Thanks,

Joan.


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org
Oleg Kalnichevski
2018-11-08 10:03:34 UTC
Permalink
Post by Joan Balagueró
Hello Oleg,
1. If a connection is kept-alive for 30s at second 0, and after 10s
is reused, this connection will die at second 30 or will survive
until second 40?
Keep-alive value is always relative to the last connection release. If
you want to limit the absolute connection life time please use set a
finite TTL (total time to live) value.
Post by Joan Balagueró
2. Regarding the RetryHandler, below the method inherited from http
I would recommend using DefaultHttpRequestRetryHandler shipped with the
library unless you have some application specific requirements.

https://github.com/apache/httpcomponents-client/blob/master/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultHttpRequestRetryHandler.java#L160
Post by Joan Balagueró
public boolean retryRequest(HttpRequest request, IOException
exception, int executionCount, HttpContext context)
{
// Don't retry if max retries are reached.
if (executionCount > this.maxExecutionCount) return false;
// Don't retry if any of these exceptions occur.
if (exception instanceof InterruptedIOException || exception
instanceof UnknownHostException || exception instanceof
ConnectException || exception instanceof SSLException) return false;
// Retry of if this request is considered 'idempotent'.
return (!(request instanceof HttpEntityEnclosingRequest));
}
I understand the first two conditions are still ok (not sure if we
have to add new exceptions on that list) but regarding the last
condition,what would the equivalent condition be in Http5?
I would suggest the following:

https://github.com/apache/httpcomponents-client/blob/master/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultHttpRequestRetryHandler.java#L160
Post by Joan Balagueró
3. We have increased the response time of our backend (ip ended with
'182') in order to exhaust the strict/lax pool. When this happens the
pool starts to throw a DeadlineTimeoutException. At this moment the
number of sockets in TIME_WAIT increases a lot until making the
99
101
98
25876
61507
97615
Is this the right behaviour? If Http5 cannot create new connections,
so no new sockets are opened, why does the number of sockets in
TIME_WAIT raise at those values?
I believe it is. There is pretty good explanation of what the TIME_WAIT
state represents in our old wiki:

https://wiki.apache.org/HttpComponents/FrequentlyAskedConnectionManagementQuestions

Oleg



---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org
Joan Balagueró
2018-11-09 12:39:20 UTC
Permalink
Thanks Oleg. One more thing about the max connections with lax/strict pool. Our code to modify the number of max connections is:

public void setMaxConnections(int maxConnections)
{
this.phccm.setMaxTotal(maxConnections);
this.phccm.setDefaultMaxPerRoute(maxConnections);
}

If I modify (on the fly) the max connections in a strict pool it works. For example I set a very low value and I start to receive DeadlineTimeoutException, when I set a higher value the error disappears. If I print the pool.getMaxTotal() I get the right value.

But this does not work with a lax pool. I set up a lax pool with max connections = 1, and no DeadlineTimeoutException is thrown (with the same load). When I print the maxTotal and defaultMaxPerRoute I get 0 and 1 (instead of 1 and 1).

Is this a bug or am I missing something?

Thanks,

Joan.


-----Mensaje original-----
De: Oleg Kalnichevski [mailto:***@apache.org]
Enviado el: jueves, 8 de noviembre de 2018 11:04
Para: HttpClient User Discussion
Asunto: Re: RV: Migration from Async 4.1.3 to HttpClient 5
Post by Joan Balagueró
Hello Oleg,
1. If a connection is kept-alive for 30s at second 0, and after 10s is
reused, this connection will die at second 30 or will survive until
second 40?
Keep-alive value is always relative to the last connection release. If you want to limit the absolute connection life time please use set a finite TTL (total time to live) value.
Post by Joan Balagueró
2. Regarding the RetryHandler, below the method inherited from http
I would recommend using DefaultHttpRequestRetryHandler shipped with the library unless you have some application specific requirements.

https://github.com/apache/httpcomponents-client/blob/master/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultHttpRequestRetryHandler.java#L160
Post by Joan Balagueró
public boolean retryRequest(HttpRequest request, IOException
exception, int executionCount, HttpContext context) {
// Don't retry if max retries are reached.
if (executionCount > this.maxExecutionCount) return false;
// Don't retry if any of these exceptions occur.
if (exception instanceof InterruptedIOException || exception
instanceof UnknownHostException || exception instanceof
ConnectException || exception instanceof SSLException) return false;
// Retry of if this request is considered 'idempotent'.
return (!(request instanceof HttpEntityEnclosingRequest)); }
I understand the first two conditions are still ok (not sure if we
have to add new exceptions on that list) but regarding the last
condition,what would the equivalent condition be in Http5?
I would suggest the following:

https://github.com/apache/httpcomponents-client/blob/master/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultHttpRequestRetryHandler.java#L160
Post by Joan Balagueró
3. We have increased the response time of our backend (ip ended with
'182') in order to exhaust the strict/lax pool. When this happens the
pool starts to throw a DeadlineTimeoutException. At this moment the
number of sockets in TIME_WAIT increases a lot until making the server
99
101
98
25876
61507
97615
Is this the right behaviour? If Http5 cannot create new connections,
so no new sockets are opened, why does the number of sockets in
TIME_WAIT raise at those values?
I believe it is. There is pretty good explanation of what the TIME_WAIT state represents in our old wiki:

https://wiki.apache.org/HttpComponents/FrequentlyAskedConnectionManagementQuestions

Oleg



---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org
Oleg Kalnichevski
2018-11-09 14:01:29 UTC
Permalink
Post by Joan Balagueró
Thanks Oleg. One more thing about the max connections with lax/strict
public void setMaxConnections(int maxConnections)
{
this.phccm.setMaxTotal(maxConnections);
this.phccm.setDefaultMaxPerRoute(maxConnections);
}
If I modify (on the fly) the max connections in a strict pool it
works. For example I set a very low value and I start to receive
DeadlineTimeoutException, when I set a higher value the error
disappears. If I print the pool.getMaxTotal() I get the right value.
But this does not work with a lax pool. I set up a lax pool with max
connections = 1, and no DeadlineTimeoutException is thrown (with the
same load). When I print the maxTotal and defaultMaxPerRoute I get 0
and 1 (instead of 1 and 1).
Is this a bug or am I missing something?
Max total is not enforced by the lax pool, only max per route.

Oleg
Post by Joan Balagueró
Thanks,
Joan.
-----Mensaje original-----
Enviado el: jueves, 8 de noviembre de 2018 11:04
Para: HttpClient User Discussion
Asunto: Re: RV: Migration from Async 4.1.3 to HttpClient 5
Post by Joan Balagueró
Hello Oleg,
1. If a connection is kept-alive for 30s at second 0, and after 10s is
reused, this connection will die at second 30 or will survive until
second 40?
Keep-alive value is always relative to the last connection release.
If you want to limit the absolute connection life time please use set
a finite TTL (total time to live) value.
Post by Joan Balagueró
2. Regarding the RetryHandler, below the method inherited from http
I would recommend using DefaultHttpRequestRetryHandler shipped with
the library unless you have some application specific requirements.
https://github.com/apache/httpcomponents-client/blob/master/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultHttpRequestRetryHandler.java#L160
Post by Joan Balagueró
Post by Joan Balagueró
public boolean retryRequest(HttpRequest request, IOException
exception, int executionCount, HttpContext context) {
// Don't retry if max retries are reached.
if (executionCount > this.maxExecutionCount) return false;
// Don't retry if any of these exceptions occur.
if (exception instanceof InterruptedIOException || exception
instanceof UnknownHostException || exception instanceof
ConnectException || exception instanceof SSLException) return false;
// Retry of if this request is considered 'idempotent'.
return (!(request instanceof HttpEntityEnclosingRequest)); }
I understand the first two conditions are still ok (not sure if we
have to add new exceptions on that list) but regarding the last
condition,what would the equivalent condition be in Http5?
https://github.com/apache/httpcomponents-client/blob/master/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultHttpRequestRetryHandler.java#L160
Post by Joan Balagueró
Post by Joan Balagueró
3. We have increased the response time of our backend (ip ended with
'182') in order to exhaust the strict/lax pool. When this happens the
pool starts to throw a DeadlineTimeoutException. At this moment the
number of sockets in TIME_WAIT increases a lot until making the server
|
wc -l
99
|
wc -l
101
|
wc -l
98
|
wc -l
25876
|
wc -l
61507
|
wc -l
97615
Is this the right behaviour? If Http5 cannot create new
connections,
so no new sockets are opened, why does the number of sockets in
TIME_WAIT raise at those values?
I believe it is. There is pretty good explanation of what the
https://wiki.apache.org/HttpComponents/FrequentlyAskedConnectionManagementQuestions
Post by Joan Balagueró
Oleg
---------------------------------------------------------------------
---------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org
Joan Balagueró
2018-11-09 14:19:25 UTC
Permalink
Ok, so if I have a defaultMaxPerRoute = 1, and all requests I'm sending are using plain http to the same ip (without proxy) and only using 4 different ports (8080, 8081, 8082, 8083), than this means I have 1 max connection for ip:8080, 1 for ip:8081, 1 for ip:80802 and 1 for ip:80803?
Joan.

-----Mensaje original-----
De: Oleg Kalnichevski [mailto:***@apache.org]
Enviado el: viernes, 9 de noviembre de 2018 15:01
Para: HttpClient User Discussion
Asunto: Re: RV: Migration from Async 4.1.3 to HttpClient 5
Post by Joan Balagueró
Thanks Oleg. One more thing about the max connections with lax/strict
public void setMaxConnections(int maxConnections) {
this.phccm.setMaxTotal(maxConnections);
this.phccm.setDefaultMaxPerRoute(maxConnections);
}
If I modify (on the fly) the max connections in a strict pool it
works. For example I set a very low value and I start to receive
DeadlineTimeoutException, when I set a higher value the error
disappears. If I print the pool.getMaxTotal() I get the right value.
But this does not work with a lax pool. I set up a lax pool with max
connections = 1, and no DeadlineTimeoutException is thrown (with the
same load). When I print the maxTotal and defaultMaxPerRoute I get 0
and 1 (instead of 1 and 1).
Is this a bug or am I missing something?
Max total is not enforced by the lax pool, only max per route.

Oleg
Post by Joan Balagueró
Thanks,
Joan.
-----Mensaje original-----
de noviembre de 2018 11:04
Para: HttpClient User Discussion
Asunto: Re: RV: Migration from Async 4.1.3 to HttpClient 5
Post by Joan Balagueró
Hello Oleg,
1. If a connection is kept-alive for 30s at second 0, and after 10s
is reused, this connection will die at second 30 or will survive
until second 40?
Keep-alive value is always relative to the last connection release.
If you want to limit the absolute connection life time please use set
a finite TTL (total time to live) value.
Post by Joan Balagueró
2. Regarding the RetryHandler, below the method inherited from http
I would recommend using DefaultHttpRequestRetryHandler shipped with
the library unless you have some application specific requirements.
https://github.com/apache/httpcomponents-client/blob/master/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultHttpRequestRetryHandler.java#L160
Post by Joan Balagueró
Post by Joan Balagueró
public boolean retryRequest(HttpRequest request, IOException
exception, int executionCount, HttpContext context) {
// Don't retry if max retries are reached.
if (executionCount > this.maxExecutionCount) return false;
// Don't retry if any of these exceptions occur.
if (exception instanceof InterruptedIOException || exception
instanceof UnknownHostException || exception instanceof
ConnectException || exception instanceof SSLException) return false;
// Retry of if this request is considered 'idempotent'.
return (!(request instanceof HttpEntityEnclosingRequest)); }
I understand the first two conditions are still ok (not sure if we
have to add new exceptions on that list) but regarding the last
condition,what would the equivalent condition be in Http5?
https://github.com/apache/httpcomponents-client/blob/master/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultHttpRequestRetryHandler.java#L160
Post by Joan Balagueró
Post by Joan Balagueró
3. We have increased the response time of our backend (ip ended with
'182') in order to exhaust the strict/lax pool. When this happens
the pool starts to throw a DeadlineTimeoutException. At this moment
the number of sockets in TIME_WAIT increases a lot until making the
|
wc -l
99
|
wc -l
101
|
wc -l
98
|
wc -l
25876
|
wc -l
61507
|
wc -l
97615
Is this the right behaviour? If Http5 cannot create new connections,
so no new sockets are opened, why does the number of sockets in
TIME_WAIT raise at those values?
I believe it is. There is pretty good explanation of what the
https://wiki.apache.org/HttpComponents/FrequentlyAskedConnectionManagementQuestions
Post by Joan Balagueró
Oleg
---------------------------------------------------------------------
---------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org
Oleg Kalnichevski
2018-11-09 14:30:47 UTC
Permalink
Post by Joan Balagueró
Ok, so if I have a defaultMaxPerRoute = 1, and all requests I'm
sending are using plain http to the same ip (without proxy) and only
using 4 different ports (8080, 8081, 8082, 8083), than this means I
have 1 max connection for ip:8080, 1 for ip:8081, 1 for ip:80802 and
1 for ip:80803?
Joan.
Correct.

Oleg
Post by Joan Balagueró
-----Mensaje original-----
Enviado el: viernes, 9 de noviembre de 2018 15:01
Para: HttpClient User Discussion
Asunto: Re: RV: Migration from Async 4.1.3 to HttpClient 5
Post by Joan Balagueró
Thanks Oleg. One more thing about the max connections with
lax/strict
public void setMaxConnections(int maxConnections) {
this.phccm.setMaxTotal(maxConnections);
this.phccm.setDefaultMaxPerRoute(maxConnections);
}
If I modify (on the fly) the max connections in a strict pool it
works. For example I set a very low value and I start to receive
DeadlineTimeoutException, when I set a higher value the error
disappears. If I print the pool.getMaxTotal() I get the right value.
But this does not work with a lax pool. I set up a lax pool with max
connections = 1, and no DeadlineTimeoutException is thrown (with the
same load). When I print the maxTotal and defaultMaxPerRoute I get 0
and 1 (instead of 1 and 1).
Is this a bug or am I missing something?
Max total is not enforced by the lax pool, only max per route.
Oleg
Post by Joan Balagueró
Thanks,
Joan.
-----Mensaje original-----
de noviembre de 2018 11:04
Para: HttpClient User Discussion
Asunto: Re: RV: Migration from Async 4.1.3 to HttpClient 5
Post by Joan Balagueró
Hello Oleg,
1. If a connection is kept-alive for 30s at second 0, and after 10s
is reused, this connection will die at second 30 or will survive
until second 40?
Keep-alive value is always relative to the last connection release.
If you want to limit the absolute connection life time please use set
a finite TTL (total time to live) value.
Post by Joan Balagueró
2. Regarding the RetryHandler, below the method inherited from http
I would recommend using DefaultHttpRequestRetryHandler shipped with
the library unless you have some application specific requirements.
https://github.com/apache/httpcomponents-client/blob/master/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultHttpRequestRetryHandler.java#L160
Post by Joan Balagueró
Post by Joan Balagueró
Post by Joan Balagueró
public boolean retryRequest(HttpRequest request, IOException
exception, int executionCount, HttpContext context) {
// Don't retry if max retries are reached.
if (executionCount > this.maxExecutionCount) return false;
// Don't retry if any of these exceptions occur.
if (exception instanceof InterruptedIOException || exception
instanceof UnknownHostException || exception instanceof
ConnectException || exception instanceof SSLException) return false;
// Retry of if this request is considered 'idempotent'.
return (!(request instanceof HttpEntityEnclosingRequest)); }
I understand the first two conditions are still ok (not sure if we
have to add new exceptions on that list) but regarding the last
condition,what would the equivalent condition be in Http5?
https://github.com/apache/httpcomponents-client/blob/master/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultHttpRequestRetryHandler.java#L160
Post by Joan Balagueró
Post by Joan Balagueró
Post by Joan Balagueró
3. We have increased the response time of our backend (ip ended with
'182') in order to exhaust the strict/lax pool. When this
happens
the pool starts to throw a DeadlineTimeoutException. At this moment
the number of sockets in TIME_WAIT increases a lot until making the
"179.182"
wc -l
99
"179.182"
wc -l
101
"179.182"
wc -l
98
"179.182"
wc -l
25876
"179.182"
wc -l
61507
"179.182"
wc -l
97615
Is this the right behaviour? If Http5 cannot create new
connections,
so no new sockets are opened, why does the number of sockets in
TIME_WAIT raise at those values?
I believe it is. There is pretty good explanation of what the
https://wiki.apache.org/HttpComponents/FrequentlyAskedConnectionManagementQuestions
Post by Joan Balagueró
Post by Joan Balagueró
Oleg
-----------------------------------------------------------------
----
-----------------------------------------------------------------
----
---------------------------------------------------------------------
---------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org
Gary Gregory
2018-11-09 15:10:31 UTC
Permalink
Post by Oleg Kalnichevski
Post by Joan Balagueró
Thanks Oleg. One more thing about the max connections with lax/strict
public void setMaxConnections(int maxConnections)
{
this.phccm.setMaxTotal(maxConnections);
this.phccm.setDefaultMaxPerRoute(maxConnections);
}
If I modify (on the fly) the max connections in a strict pool it
works. For example I set a very low value and I start to receive
DeadlineTimeoutException, when I set a higher value the error
disappears. If I print the pool.getMaxTotal() I get the right value.
But this does not work with a lax pool. I set up a lax pool with max
connections = 1, and no DeadlineTimeoutException is thrown (with the
same load). When I print the maxTotal and defaultMaxPerRoute I get 0
and 1 (instead of 1 and 1).
Is this a bug or am I missing something?
Max total is not enforced by the lax pool, only max per route.
Hi,

Can you make sure this is Javadoc'd in the right places if it is not
already?

Gary
Post by Oleg Kalnichevski
Oleg
Post by Joan Balagueró
Thanks,
Joan.
-----Mensaje original-----
Enviado el: jueves, 8 de noviembre de 2018 11:04
Para: HttpClient User Discussion
Asunto: Re: RV: Migration from Async 4.1.3 to HttpClient 5
Post by Joan Balagueró
Hello Oleg,
1. If a connection is kept-alive for 30s at second 0, and after 10s is
reused, this connection will die at second 30 or will survive until
second 40?
Keep-alive value is always relative to the last connection release.
If you want to limit the absolute connection life time please use set
a finite TTL (total time to live) value.
Post by Joan Balagueró
2. Regarding the RetryHandler, below the method inherited from http
I would recommend using DefaultHttpRequestRetryHandler shipped with
the library unless you have some application specific requirements.
https://github.com/apache/httpcomponents-client/blob/master/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultHttpRequestRetryHandler.java#L160
Post by Joan Balagueró
Post by Joan Balagueró
public boolean retryRequest(HttpRequest request, IOException
exception, int executionCount, HttpContext context) {
// Don't retry if max retries are reached.
if (executionCount > this.maxExecutionCount) return false;
// Don't retry if any of these exceptions occur.
if (exception instanceof InterruptedIOException || exception
instanceof UnknownHostException || exception instanceof
ConnectException || exception instanceof SSLException) return false;
// Retry of if this request is considered 'idempotent'.
return (!(request instanceof HttpEntityEnclosingRequest)); }
I understand the first two conditions are still ok (not sure if we
have to add new exceptions on that list) but regarding the last
condition,what would the equivalent condition be in Http5?
https://github.com/apache/httpcomponents-client/blob/master/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultHttpRequestRetryHandler.java#L160
Post by Joan Balagueró
Post by Joan Balagueró
3. We have increased the response time of our backend (ip ended with
'182') in order to exhaust the strict/lax pool. When this happens the
pool starts to throw a DeadlineTimeoutException. At this moment the
number of sockets in TIME_WAIT increases a lot until making the server
|
wc -l
99
|
wc -l
101
|
wc -l
98
|
wc -l
25876
|
wc -l
61507
|
wc -l
97615
Is this the right behaviour? If Http5 cannot create new
connections,
so no new sockets are opened, why does the number of sockets in
TIME_WAIT raise at those values?
I believe it is. There is pretty good explanation of what the
https://wiki.apache.org/HttpComponents/FrequentlyAskedConnectionManagementQuestions
Post by Joan Balagueró
Oleg
---------------------------------------------------------------------
---------------------------------------------------------------------
---------------------------------------------------------------------
Joan Balagueró - ventusproxy
2018-11-10 17:02:32 UTC
Permalink
Hello Oleg,

Sorry, but I think I'm going to need a bit more help to finish understand this ... This was my test:

a. A load of around 2000 req/s
b. Just 1 route = http://54.38.179.182:8080
c. Every time we change the max_connections value this method is executed:
public void setMaxConnections(int maxConnections) {
this.phccm.setMaxTotal(maxConnections);
this.phccm.setDefaultMaxPerRoute(maxConnections);
}
d. Printing stats every 1s:
public void printStats() {
System.out.println("Stats total: " + this.phccm.getTotalStats().getLeased() + " / " + this.phccm.getTotalStats().getMax());
System.out.println("Stats route: " + this.phccm.getStats(new HttpRoute(new HttpHost("54.38.179.182", 8080, "http"))).getLeased() + " / " + this.phccm.getStats(new HttpRoute(new HttpHost("54.38.179.182", 8080, "http"))).getMax());
}


TEST 1. Strict pool, max connections = 1, keep-alive = 1s, pool timeout = 1m
- almost all requests end up with max connections error
- Stats total = Stats route = 1 / 1
--> So test ok.

TEST 2. Strict pool, max connections = 5000 (value changed without restarting pool), keep-alive = 1s, pool timeout = 1m
- all requests processed ok
- Stats total = Stats route ~ 1030 / 5000
--> So test ok.

TEST 3. Strict pool, max connections = 1 (value changed without restarting pool), keep-alive = 1s, pool timeout = 1m
- some requests processed ok, some returning max connections error
- Stats total = Stats route ~ n / 1, with 'n' lowering slowly from 1.030 to ....
--> It seems that even with a maxConn = 1 the pool is reusing pooled connections.

TEST 4: Lax pool, max connections = 1, POOL RESTARTED before sending traffic, keep-alive = 1s, pool timeout = 1m
- almost all requests end up with max connections error
- Stats total = Stats route = 1 / 1 (sometimes 2 / 1, ok because it's lax).
--> So test ok.

TEST 5. Lax pool, max connections = 5000 (value changed without restarting pool), keep-alive = 1s, pool timeout = 1m
- almost all requests end up with max connections error
- Stats total = Stats route = 1 / 1 (sometimes 2 / 1).


So my doubts are:

1. Is TEST 3 ok? Even having pooled connections to reuse, shouldn't the max_conn value have preference?

2. Is TEST 5 ok? It seems the 'DefaultMaxPerRoute' cannot be applied on the fly in a lax pool. It should have a value of 5000 but it's preserving the previous value of 1 (test 4).



Thanks ,

Joan.



-----Mensaje original-----
De: Oleg Kalnichevski [mailto:***@apache.org]
Enviado el: viernes, 9 de noviembre de 2018 15:31
Para: HttpClient User Discussion
Asunto: Re: RV: Migration from Async 4.1.3 to HttpClient 5
Post by Joan Balagueró
Ok, so if I have a defaultMaxPerRoute = 1, and all requests I'm
sending are using plain http to the same ip (without proxy) and only
using 4 different ports (8080, 8081, 8082, 8083), than this means I
have 1 max connection for ip:8080, 1 for ip:8081, 1 for ip:80802 and
1 for ip:80803?
Joan.
Correct.

Oleg
Post by Joan Balagueró
-----Mensaje original-----
de noviembre de 2018 15:01
Para: HttpClient User Discussion
Asunto: Re: RV: Migration from Async 4.1.3 to HttpClient 5
Post by Joan Balagueró
Thanks Oleg. One more thing about the max connections with
lax/strict pool. Our code to modify the number of max connections
public void setMaxConnections(int maxConnections) {
this.phccm.setMaxTotal(maxConnections);
this.phccm.setDefaultMaxPerRoute(maxConnections);
}
If I modify (on the fly) the max connections in a strict pool it
works. For example I set a very low value and I start to receive
DeadlineTimeoutException, when I set a higher value the error
disappears. If I print the pool.getMaxTotal() I get the right value.
But this does not work with a lax pool. I set up a lax pool with max
connections = 1, and no DeadlineTimeoutException is thrown (with the
same load). When I print the maxTotal and defaultMaxPerRoute I get
0
and 1 (instead of 1 and 1).
Is this a bug or am I missing something?
Max total is not enforced by the lax pool, only max per route.
Oleg
Post by Joan Balagueró
Thanks,
Joan.
-----Mensaje original-----
8
de noviembre de 2018 11:04
Para: HttpClient User Discussion
Asunto: Re: RV: Migration from Async 4.1.3 to HttpClient 5
Post by Joan Balagueró
Hello Oleg,
1. If a connection is kept-alive for 30s at second 0, and after
10s is reused, this connection will die at second 30 or will
survive until second 40?
Keep-alive value is always relative to the last connection release.
If you want to limit the absolute connection life time please use
set a finite TTL (total time to live) value.
Post by Joan Balagueró
2. Regarding the RetryHandler, below the method inherited from
http
I would recommend using DefaultHttpRequestRetryHandler shipped with
the library unless you have some application specific requirements.
https://github.com/apache/httpcomponents-client/blob/master/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultHttpRequestRetryHandler.java#L160
Post by Joan Balagueró
Post by Joan Balagueró
Post by Joan Balagueró
public boolean retryRequest(HttpRequest request, IOException
exception, int executionCount, HttpContext context) {
// Don't retry if max retries are reached.
if (executionCount > this.maxExecutionCount) return false;
// Don't retry if any of these exceptions occur.
if (exception instanceof InterruptedIOException || exception
instanceof UnknownHostException || exception instanceof
ConnectException || exception instanceof SSLException) return
false;
// Retry of if this request is considered 'idempotent'.
return (!(request instanceof HttpEntityEnclosingRequest)); }
I understand the first two conditions are still ok (not sure if we
have to add new exceptions on that list) but regarding the last
condition,what would the equivalent condition be in Http5?
https://github.com/apache/httpcomponents-client/blob/master/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultHttpRequestRetryHandler.java#L160
Post by Joan Balagueró
Post by Joan Balagueró
Post by Joan Balagueró
3. We have increased the response time of our backend (ip ended
with
'182') in order to exhaust the strict/lax pool. When this happens
the pool starts to throw a DeadlineTimeoutException. At this
moment the number of sockets in TIME_WAIT increases a lot until
making the server unresponsive (probably exhausting the local
"179.182"
wc -l
99
wc -l
101
wc -l
98
wc -l
25876
wc -l
61507
wc -l
97615
Is this the right behaviour? If Http5 cannot create new
connections, so no new sockets are opened, why does the number of
sockets in TIME_WAIT raise at those values?
I believe it is. There is pretty good explanation of what the
https://wiki.apache.org/HttpComponents/FrequentlyAskedConnectionManagementQuestions
Post by Joan Balagueró
Post by Joan Balagueró
Oleg
-----------------------------------------------------------------
----
-----------------------------------------------------------------
----
---------------------------------------------------------------------
---------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org






---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org
Oleg Kalnichevski
2018-11-10 18:30:23 UTC
Permalink
Post by Joan Balagueró
Hello Oleg,
Sorry, but I think I'm going to need a bit more help to finish
a. A load of around 2000 req/s
b. Just 1 route = http://54.38.179.182:8080
public void setMaxConnections(int maxConnections) {
this.phccm.setMaxTotal(maxConnections);
this.phccm.setDefaultMaxPerRoute(maxConnections);
}
You might want to add this.phccm.setMaxPerRoute(new HttpRoute(new HttpHost("54.38.179.182", 8080)), maxConnections);


this.phccm.setDefaultMaxPerRoute(maxConnections)
Post by Joan Balagueró
public void printStats() {
System.out.println("Stats total: " +
this.phccm.getTotalStats().getLeased() + " / " +
this.phccm.getTotalStats().getMax());
System.out.println("Stats route: " +
this.phccm.getStats(new HttpRoute(new HttpHost("54.38.179.182", 8080,
"http"))).getLeased() + " / " + this.phccm.getStats(new HttpRoute(new
HttpHost("54.38.179.182", 8080, "http"))).getMax());
}
TEST 1. Strict pool, max connections = 1, keep-alive = 1s, pool timeout = 1m
- almost all requests end up with max connections error
- Stats total = Stats route = 1 / 1
--> So test ok.
TEST 2. Strict pool, max connections = 5000 (value changed
without restarting pool), keep-alive = 1s, pool timeout = 1m
- all requests processed ok
- Stats total = Stats route ~ 1030 / 5000
--> So test ok.
TEST 3. Strict pool, max connections = 1 (value changed without
restarting pool), keep-alive = 1s, pool timeout = 1m
- some requests processed ok, some returning max connections
error
- Stats total = Stats route ~ n / 1, with 'n' lowering slowly
from 1.030 to ....
--> It seems that even with a maxConn = 1 the pool is reusing
pooled connections.
TEST 4: Lax pool, max connections = 1, POOL RESTARTED before
sending traffic, keep-alive = 1s, pool timeout = 1m
- almost all requests end up with max connections error
- Stats total = Stats route = 1 / 1 (sometimes 2 / 1, ok
because it's lax).
--> So test ok.
TEST 5. Lax pool, max connections = 5000 (value changed without
restarting pool), keep-alive = 1s, pool timeout = 1m
- almost all requests end up with max connections error
- Stats total = Stats route = 1 / 1 (sometimes 2 / 1).
1. Is TEST 3 ok? Even having pooled connections to reuse, shouldn't
the max_conn value have preference?
2. Is TEST 5 ok? It seems the 'DefaultMaxPerRoute' cannot be applied
on the fly in a lax pool. It should have a value of 5000 but it's
preserving the previous value of 1 (test 4).
Thanks ,
Joan.
-----Mensaje original-----
Enviado el: viernes, 9 de noviembre de 2018 15:31
Para: HttpClient User Discussion
Asunto: Re: RV: Migration from Async 4.1.3 to HttpClient 5
Post by Joan Balagueró
Ok, so if I have a defaultMaxPerRoute = 1, and all requests I'm
sending are using plain http to the same ip (without proxy) and only
using 4 different ports (8080, 8081, 8082, 8083), than this means I
have 1 max connection for ip:8080, 1 for ip:8081, 1 for ip:80802 and
1 for ip:80803?
Joan.
defaultMaxPerRoute applies only once when the per route pool is
created. I guess this is what skews the results of TEST 3 and TEST 5.

Oleg
Post by Joan Balagueró
Correct.
Oleg
Post by Joan Balagueró
-----Mensaje original-----
viernes, 9
de noviembre de 2018 15:01
Para: HttpClient User Discussion
Asunto: Re: RV: Migration from Async 4.1.3 to HttpClient 5
Post by Joan Balagueró
Thanks Oleg. One more thing about the max connections with
lax/strict pool. Our code to modify the number of max
connections
public void setMaxConnections(int maxConnections) {
this.phccm.setMaxTotal(maxConnections);
this.phccm.setDefaultMaxPerRoute(maxConnections);
}
If I modify (on the fly) the max connections in a strict pool it
works. For example I set a very low value and I start to receive
DeadlineTimeoutException, when I set a higher value the error
disappears. If I print the pool.getMaxTotal() I get the right value.
But this does not work with a lax pool. I set up a lax pool with max
connections = 1, and no DeadlineTimeoutException is thrown (with the
same load). When I print the maxTotal and defaultMaxPerRoute I get
0
and 1 (instead of 1 and 1).
Is this a bug or am I missing something?
Max total is not enforced by the lax pool, only max per route.
Oleg
Post by Joan Balagueró
Thanks,
Joan.
-----Mensaje original-----
8
de noviembre de 2018 11:04
Para: HttpClient User Discussion
Asunto: Re: RV: Migration from Async 4.1.3 to HttpClient 5
Post by Joan Balagueró
Hello Oleg,
1. If a connection is kept-alive for 30s at second 0, and after
10s is reused, this connection will die at second 30 or will
survive until second 40?
Keep-alive value is always relative to the last connection
release.
If you want to limit the absolute connection life time please use
set a finite TTL (total time to live) value.
Post by Joan Balagueró
2. Regarding the RetryHandler, below the method inherited from
http
I would recommend using DefaultHttpRequestRetryHandler shipped with
the library unless you have some application specific
requirements.
https://github.com/apache/httpcomponents-client/blob/master/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultHttpRequestRetryHandler.java#L160
Post by Joan Balagueró
Post by Joan Balagueró
Post by Joan Balagueró
Post by Joan Balagueró
public boolean retryRequest(HttpRequest request, IOException
exception, int executionCount, HttpContext context) {
// Don't retry if max retries are reached.
if (executionCount > this.maxExecutionCount) return false;
// Don't retry if any of these exceptions occur.
if (exception instanceof InterruptedIOException || exception
instanceof UnknownHostException || exception instanceof
ConnectException || exception instanceof SSLException) return
false;
// Retry of if this request is considered 'idempotent'.
return (!(request instanceof HttpEntityEnclosingRequest)); }
I understand the first two conditions are still ok (not sure if we
have to add new exceptions on that list) but regarding the last
condition,what would the equivalent condition be in Http5?
https://github.com/apache/httpcomponents-client/blob/master/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultHttpRequestRetryHandler.java#L160
Post by Joan Balagueró
Post by Joan Balagueró
Post by Joan Balagueró
Post by Joan Balagueró
3. We have increased the response time of our backend (ip ended
with
'182') in order to exhaust the strict/lax pool. When this happens
the pool starts to throw a DeadlineTimeoutException. At this
moment the number of sockets in TIME_WAIT increases a lot until
making the server unresponsive (probably exhausting the local
wc -l
99
"179.182"
wc -l
101
"179.182"
wc -l
98
"179.182"
wc -l
25876
"179.182"
wc -l
61507
"179.182"
wc -l
97615
Is this the right behaviour? If Http5 cannot create new
connections, so no new sockets are opened, why does the number of
sockets in TIME_WAIT raise at those values?
I believe it is. There is pretty good explanation of what the
https://wiki.apache.org/HttpComponents/FrequentlyAskedConnectionManagementQuestions
Post by Joan Balagueró
Post by Joan Balagueró
Post by Joan Balagueró
Oleg
-----------------------------------------------------------------
----
-----------------------------------------------------------------
----
-----------------------------------------------------------------
----
-----------------------------------------------------------------
----
---------------------------------------------------------------------
---------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org
Joan Balagueró
2018-11-11 10:32:59 UTC
Permalink
Hi Oleg,

After applying the route in concrete now TEST5 works, but TEST3 still works in the same way as the previous test. I have tried TEST3 with the Async 4.1.3 and the result is the same, when you decrease the max connections value the pool still reuses connections and does not honor the maxconn parameter.

Adding routes is not feasible in our use case, so at the moment we will provoke a pool restart in case a user changes the max connections in a lax pool.

Thanks for your time,

Joan.


-----Mensaje original-----
De: Oleg Kalnichevski [mailto:***@apache.org]
Enviado el: sábado, 10 de noviembre de 2018 19:30
Para: HttpClient User Discussion
Asunto: Re: RV: Migration from Async 4.1.3 to HttpClient 5
Post by Joan Balagueró
Hello Oleg,
Sorry, but I think I'm going to need a bit more help to finish
a. A load of around 2000 req/s
b. Just 1 route = http://54.38.179.182:8080 c. Every time we change
the max_connections value this method is
public void setMaxConnections(int maxConnections) {
this.phccm.setMaxTotal(maxConnections);
this.phccm.setDefaultMaxPerRoute(maxConnections);
}
You might want to add this.phccm.setMaxPerRoute(new HttpRoute(new HttpHost("54.38.179.182", 8080)), maxConnections);


this.phccm.setDefaultMaxPerRoute(maxConnections)
Post by Joan Balagueró
public void printStats() {
System.out.println("Stats total: " +
this.phccm.getTotalStats().getLeased() + " / " +
this.phccm.getTotalStats().getMax());
System.out.println("Stats route: " + this.phccm.getStats(new
HttpRoute(new HttpHost("54.38.179.182", 8080,
"http"))).getLeased() + " / " + this.phccm.getStats(new HttpRoute(new
HttpHost("54.38.179.182", 8080, "http"))).getMax());
}
TEST 1. Strict pool, max connections = 1, keep-alive = 1s, pool timeout = 1m
- almost all requests end up with max connections error
- Stats total = Stats route = 1 / 1
--> So test ok.
TEST 2. Strict pool, max connections = 5000 (value changed
without restarting pool), keep-alive = 1s, pool timeout = 1m
- all requests processed ok
- Stats total = Stats route ~ 1030 / 5000
--> So test ok.
TEST 3. Strict pool, max connections = 1 (value changed without
restarting pool), keep-alive = 1s, pool timeout = 1m
- some requests processed ok, some returning max connections error
- Stats total = Stats route ~ n / 1, with 'n' lowering slowly from 1.030 to ....
--> It seems that even with a maxConn = 1 the pool is reusing pooled connections.
TEST 4: Lax pool, max connections = 1, POOL RESTARTED before
sending traffic, keep-alive = 1s, pool timeout = 1m
- almost all requests end up with max connections error
- Stats total = Stats route = 1 / 1 (sometimes 2 / 1, ok because it's lax).
--> So test ok.
TEST 5. Lax pool, max connections = 5000 (value changed without
restarting pool), keep-alive = 1s, pool timeout = 1m
- almost all requests end up with max connections error
- Stats total = Stats route = 1 / 1 (sometimes 2 / 1).
1. Is TEST 3 ok? Even having pooled connections to reuse, shouldn't
the max_conn value have preference?
2. Is TEST 5 ok? It seems the 'DefaultMaxPerRoute' cannot be applied
on the fly in a lax pool. It should have a value of 5000 but it's
preserving the previous value of 1 (test 4).
Thanks ,
Joan.
-----Mensaje original-----
de noviembre de 2018 15:31
Para: HttpClient User Discussion
Asunto: Re: RV: Migration from Async 4.1.3 to HttpClient 5
Post by Joan Balagueró
Ok, so if I have a defaultMaxPerRoute = 1, and all requests I'm
sending are using plain http to the same ip (without proxy) and only
using 4 different ports (8080, 8081, 8082, 8083), than this means I
have 1 max connection for ip:8080, 1 for ip:8081, 1 for ip:80802 and
1 for ip:80803?
Joan.
defaultMaxPerRoute applies only once when the per route pool is created. I guess this is what skews the results of TEST 3 and TEST 5.

Oleg
Post by Joan Balagueró
Correct.
Oleg
Post by Joan Balagueró
-----Mensaje original-----
viernes, 9
de noviembre de 2018 15:01
Para: HttpClient User Discussion
Asunto: Re: RV: Migration from Async 4.1.3 to HttpClient 5
Post by Joan Balagueró
Thanks Oleg. One more thing about the max connections with
lax/strict pool. Our code to modify the number of max connections
public void setMaxConnections(int maxConnections) {
this.phccm.setMaxTotal(maxConnections);
this.phccm.setDefaultMaxPerRoute(maxConnections);
}
If I modify (on the fly) the max connections in a strict pool it
works. For example I set a very low value and I start to receive
DeadlineTimeoutException, when I set a higher value the error
disappears. If I print the pool.getMaxTotal() I get the right value.
But this does not work with a lax pool. I set up a lax pool with
max connections = 1, and no DeadlineTimeoutException is thrown
(with the same load). When I print the maxTotal and
defaultMaxPerRoute I get
0
and 1 (instead of 1 and 1).
Is this a bug or am I missing something?
Max total is not enforced by the lax pool, only max per route.
Oleg
Post by Joan Balagueró
Thanks,
Joan.
-----Mensaje original-----
8
de noviembre de 2018 11:04
Para: HttpClient User Discussion
Asunto: Re: RV: Migration from Async 4.1.3 to HttpClient 5
Post by Joan Balagueró
Hello Oleg,
1. If a connection is kept-alive for 30s at second 0, and after
10s is reused, this connection will die at second 30 or will
survive until second 40?
Keep-alive value is always relative to the last connection
release.
If you want to limit the absolute connection life time please use
set a finite TTL (total time to live) value.
Post by Joan Balagueró
2. Regarding the RetryHandler, below the method inherited from
http
I would recommend using DefaultHttpRequestRetryHandler shipped
with the library unless you have some application specific
requirements.
https://github.com/apache/httpcomponents-client/blob/master/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultHttpRequestRetryHandler.java#L160
Post by Joan Balagueró
Post by Joan Balagueró
Post by Joan Balagueró
Post by Joan Balagueró
public boolean retryRequest(HttpRequest request, IOException
exception, int executionCount, HttpContext context) {
// Don't retry if max retries are reached.
if (executionCount > this.maxExecutionCount) return false;
// Don't retry if any of these exceptions occur.
if (exception instanceof InterruptedIOException || exception
instanceof UnknownHostException || exception instanceof
ConnectException || exception instanceof SSLException) return
false;
// Retry of if this request is considered 'idempotent'.
return (!(request instanceof HttpEntityEnclosingRequest)); }
I understand the first two conditions are still ok (not sure if
we have to add new exceptions on that list) but regarding the
last condition,what would the equivalent condition be in Http5?
https://github.com/apache/httpcomponents-client/blob/master/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultHttpRequestRetryHandler.java#L160
Post by Joan Balagueró
Post by Joan Balagueró
Post by Joan Balagueró
Post by Joan Balagueró
3. We have increased the response time of our backend (ip ended
with
'182') in order to exhaust the strict/lax pool. When this
happens the pool starts to throw a DeadlineTimeoutException. At
this moment the number of sockets in TIME_WAIT increases a lot
until making the server unresponsive (probably exhausting the
local
wc -l
99
"179.182"
wc -l
101
"179.182"
wc -l
98
"179.182"
wc -l
25876
"179.182"
wc -l
61507
"179.182"
wc -l
97615
Is this the right behaviour? If Http5 cannot create new
connections, so no new sockets are opened, why does the number
of sockets in TIME_WAIT raise at those values?
I believe it is. There is pretty good explanation of what the
https://wiki.apache.org/HttpComponents/FrequentlyAskedConnectionManagementQuestions
Post by Joan Balagueró
Post by Joan Balagueró
Post by Joan Balagueró
Oleg
-----------------------------------------------------------------
----
-----------------------------------------------------------------
----
-----------------------------------------------------------------
----
-----------------------------------------------------------------
----
---------------------------------------------------------------------
---------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org
Loading...