You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Joan Balaguero <jo...@grupoventus.com> on 2010/03/23 14:31:19 UTC

Sometimes response timeout seems to not work

Hello,

 

We're querying  a webservice using a 'ThreadSafeClientConnManager'. 

Platform: windows 2003 Server 64bit

httpClient 4.0

jre 6 update 13 on Tomcat 6.0.18

 

We're setting a global response timeout with:

HttpParams objHttpParams = new BasicHttpParams();

HttpProtocolParams.setVersion(objHttpParams, HttpVersion.HTTP_1_1);

HttpConnectionParams.setSoTimeout(objHttpParams, responseTimeout);

ClientConnectionManager cm = new ThreadSafeClientConnManager(objHttpParams,
HttpUtils.createDefaultSchemeRegistry());

this.objHttp                = new DefaultHttpClient(cm, objHttpParams);

 

For every webservice call, if the response timeout (at call level) is
greater than 0 then:

if (objCall.responseTimeout != 0)
objPost.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT,
objCall.responseTimeout); 

 

Then we send the request:

StringEntity entity = new StringEntity(request.createRequestParameters());

entity.setContentType(request.contentType);

objPost.setEntity(entity);

          

return (this.objHttp.execute(objPost));

 

And we read the response:

bis                          = new BufferedInputStream(entity.getContent());

ByteArrayOutputStream buffer = new ByteArrayOutputStream(httpOutBufferSize);

byte[] tmp                   = new byte[httpOutBufferSize];

int numBytesRead             = 0;

 

while ((numBytesRead = bis.read(tmp)) >= 0) buffer.write(tmp, 0,
numBytesRead);

bis.close();

bis = null;

 

 

Performing a thread dump, we can see many threads blocked waiting a response
several minutes (2,3,4 minutes) when the maximum response timeout is 60
seconds (at webservice and call level).

 

This is the dump of one of these threads:

Name: http-80-795

State: RUNNABLE

Total blocked: 3.603  Total waited: 3.127

 

Stack trace: 

java.net.SocketInputStream.socketRead0(Native Method)

java.net.SocketInputStream.read(Unknown Source)

org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessio
nInputBuffer.java:130)

org.apache.http.impl.io.SocketInputBuffer.fillBuffer(SocketInputBuffer.java:
127)

org.apache.http.impl.io.AbstractSessionInputBuffer.readLine(AbstractSessionI
nputBuffer.java:233)

org.apache.http.impl.conn.DefaultResponseParser.parseHead(DefaultResponsePar
ser.java:98)

org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.ja
va:210)

org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(Abst
ractHttpClientConnection.java:271)

org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(Defa
ultClientConnection.java:227)

org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(Ab
stractClientConnAdapter.java:229)

org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestEx
ecutor.java:292)

org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.jav
a:126)

org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDir
ector.java:447)

org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.ja
va:641)

org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.ja
va:576)

org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.ja
va:554)

com.vpfw.proxy.services.C.C.A(Unknown Source)

com.vpfw.proxy.services.C.C.A(Unknown Source)

com.vpfw.proxy.services.C.C.A(Unknown Source)

com.vpfw.proxy.servlet.E.A(Unknown Source)

com.vpfw.proxy.servlet.G.service(Unknown Source)

javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application
FilterChain.java:290)

org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh
ain.java:206)

org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.ja
va:233)

org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.ja
va:191)

org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128
)

org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102
)

org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java
:109)

org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)

org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)

org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http
11Protocol.java:583)

org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)

java.lang.Thread.run(Unknown Source)

 

 

The pool seems to work well, the connections are obtained and returned to
the pool correctly.

 

Could anybody help me to understand what's going on? If a http dump is
needed, I'll try to do it (it's a production environment with an average of
500 http  simultaneous requests to the webservices).

 

Thanks in advance,

 

Joan.


RE: Sometimes response timeout seems to not work

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Tue, 2010-03-23 at 14:53 +0100, Joan Balaguero wrote:
> Hello Oleg,
> 
> Your definition of http.socket.timeout is the maximum period of inactivity between two consecutive data packets.
> 

This is not my definition. I believe this is a fairly common / standard
definition of the socket timeout.

> Do you mean that, maybe, the response packets are received in long intervals (always less than 60 seconds), and then the exception is not thrown but the response time could take several minutes?
> 

Yes, I do.

Oleg

> Thanks,
> Joan.
> 
> -----Mensaje original-----
> De: Oleg Kalnichevski [mailto:olegk@apache.org] 
> Enviado el: martes, 23 de marzo de 2010 14:37
> Para: HttpClient User Discussion
> Asunto: Re: Sometimes response timeout seems to not work
> 
> On Tue, 2010-03-23 at 14:31 +0100, Joan Balaguero wrote:
> > Hello,
> > 
> >  
> > 
> > We're querying  a webservice using a 'ThreadSafeClientConnManager'. 
> > 
> > Platform: windows 2003 Server 64bit
> > 
> > httpClient 4.0
> > 
> > jre 6 update 13 on Tomcat 6.0.18
> > 
> >  
> > 
> > We're setting a global response timeout with:
> > 
> > HttpParams objHttpParams = new BasicHttpParams();
> > 
> > HttpProtocolParams.setVersion(objHttpParams, HttpVersion.HTTP_1_1);
> > 
> > HttpConnectionParams.setSoTimeout(objHttpParams, responseTimeout);
> > 
> > ClientConnectionManager cm = new ThreadSafeClientConnManager(objHttpParams,
> > HttpUtils.createDefaultSchemeRegistry());
> > 
> > this.objHttp                = new DefaultHttpClient(cm, objHttpParams);
> > 
> >  
> > 
> > For every webservice call, if the response timeout (at call level) is
> > greater than 0 then:
> > 
> > if (objCall.responseTimeout != 0)
> > objPost.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT,
> > objCall.responseTimeout); 
> > 
> >  
> > 
> > Then we send the request:
> > 
> > StringEntity entity = new StringEntity(request.createRequestParameters());
> > 
> > entity.setContentType(request.contentType);
> > 
> > objPost.setEntity(entity);
> > 
> >           
> > 
> > return (this.objHttp.execute(objPost));
> > 
> >  
> > 
> > And we read the response:
> > 
> > bis                          = new BufferedInputStream(entity.getContent());
> > 
> > ByteArrayOutputStream buffer = new ByteArrayOutputStream(httpOutBufferSize);
> > 
> > byte[] tmp                   = new byte[httpOutBufferSize];
> > 
> > int numBytesRead             = 0;
> > 
> >  
> > 
> > while ((numBytesRead = bis.read(tmp)) >= 0) buffer.write(tmp, 0,
> > numBytesRead);
> > 
> > bis.close();
> > 
> > bis = null;
> > 
> >  
> > 
> > 
> > 
> > Performing a thread dump, we can see many threads blocked waiting a response
> > several minutes (2,3,4 minutes) when the maximum response timeout is 60
> > seconds (at webservice and call level).
> > 
> 
> Please see definition of the socket timeout
> 
> Oleg
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 
> 
> No virus found in this incoming message.
> Checked by AVG - www.avg.com 
> Version: 9.0.791 / Virus Database: 271.1.1/2764 - Release Date: 03/22/10 20:44:00
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 



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


RE: Sometimes response timeout seems to not work

Posted by Joan Balaguero <jo...@grupoventus.com>.
Hello Oleg,

Your definition of http.socket.timeout is the maximum period of inactivity between two consecutive data packets.

Do you mean that, maybe, the response packets are received in long intervals (always less than 60 seconds), and then the exception is not thrown but the response time could take several minutes?

Thanks,
Joan.

-----Mensaje original-----
De: Oleg Kalnichevski [mailto:olegk@apache.org] 
Enviado el: martes, 23 de marzo de 2010 14:37
Para: HttpClient User Discussion
Asunto: Re: Sometimes response timeout seems to not work

On Tue, 2010-03-23 at 14:31 +0100, Joan Balaguero wrote:
> Hello,
> 
>  
> 
> We're querying  a webservice using a 'ThreadSafeClientConnManager'. 
> 
> Platform: windows 2003 Server 64bit
> 
> httpClient 4.0
> 
> jre 6 update 13 on Tomcat 6.0.18
> 
>  
> 
> We're setting a global response timeout with:
> 
> HttpParams objHttpParams = new BasicHttpParams();
> 
> HttpProtocolParams.setVersion(objHttpParams, HttpVersion.HTTP_1_1);
> 
> HttpConnectionParams.setSoTimeout(objHttpParams, responseTimeout);
> 
> ClientConnectionManager cm = new ThreadSafeClientConnManager(objHttpParams,
> HttpUtils.createDefaultSchemeRegistry());
> 
> this.objHttp                = new DefaultHttpClient(cm, objHttpParams);
> 
>  
> 
> For every webservice call, if the response timeout (at call level) is
> greater than 0 then:
> 
> if (objCall.responseTimeout != 0)
> objPost.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT,
> objCall.responseTimeout); 
> 
>  
> 
> Then we send the request:
> 
> StringEntity entity = new StringEntity(request.createRequestParameters());
> 
> entity.setContentType(request.contentType);
> 
> objPost.setEntity(entity);
> 
>           
> 
> return (this.objHttp.execute(objPost));
> 
>  
> 
> And we read the response:
> 
> bis                          = new BufferedInputStream(entity.getContent());
> 
> ByteArrayOutputStream buffer = new ByteArrayOutputStream(httpOutBufferSize);
> 
> byte[] tmp                   = new byte[httpOutBufferSize];
> 
> int numBytesRead             = 0;
> 
>  
> 
> while ((numBytesRead = bis.read(tmp)) >= 0) buffer.write(tmp, 0,
> numBytesRead);
> 
> bis.close();
> 
> bis = null;
> 
>  
> 
> 
> 
> Performing a thread dump, we can see many threads blocked waiting a response
> several minutes (2,3,4 minutes) when the maximum response timeout is 60
> seconds (at webservice and call level).
> 

Please see definition of the socket timeout

Oleg



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


No virus found in this incoming message.
Checked by AVG - www.avg.com 
Version: 9.0.791 / Virus Database: 271.1.1/2764 - Release Date: 03/22/10 20:44:00


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


Re: Sometimes response timeout seems to not work

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Tue, 2010-03-23 at 14:31 +0100, Joan Balaguero wrote:
> Hello,
> 
>  
> 
> We're querying  a webservice using a 'ThreadSafeClientConnManager'. 
> 
> Platform: windows 2003 Server 64bit
> 
> httpClient 4.0
> 
> jre 6 update 13 on Tomcat 6.0.18
> 
>  
> 
> We're setting a global response timeout with:
> 
> HttpParams objHttpParams = new BasicHttpParams();
> 
> HttpProtocolParams.setVersion(objHttpParams, HttpVersion.HTTP_1_1);
> 
> HttpConnectionParams.setSoTimeout(objHttpParams, responseTimeout);
> 
> ClientConnectionManager cm = new ThreadSafeClientConnManager(objHttpParams,
> HttpUtils.createDefaultSchemeRegistry());
> 
> this.objHttp                = new DefaultHttpClient(cm, objHttpParams);
> 
>  
> 
> For every webservice call, if the response timeout (at call level) is
> greater than 0 then:
> 
> if (objCall.responseTimeout != 0)
> objPost.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT,
> objCall.responseTimeout); 
> 
>  
> 
> Then we send the request:
> 
> StringEntity entity = new StringEntity(request.createRequestParameters());
> 
> entity.setContentType(request.contentType);
> 
> objPost.setEntity(entity);
> 
>           
> 
> return (this.objHttp.execute(objPost));
> 
>  
> 
> And we read the response:
> 
> bis                          = new BufferedInputStream(entity.getContent());
> 
> ByteArrayOutputStream buffer = new ByteArrayOutputStream(httpOutBufferSize);
> 
> byte[] tmp                   = new byte[httpOutBufferSize];
> 
> int numBytesRead             = 0;
> 
>  
> 
> while ((numBytesRead = bis.read(tmp)) >= 0) buffer.write(tmp, 0,
> numBytesRead);
> 
> bis.close();
> 
> bis = null;
> 
>  
> 
> 
> 
> Performing a thread dump, we can see many threads blocked waiting a response
> several minutes (2,3,4 minutes) when the maximum response timeout is 60
> seconds (at webservice and call level).
> 

Please see definition of the socket timeout

Oleg



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