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 Ma...@fiducia.de on 2007/07/26 08:16:42 UTC

WG: Connection timeout using httpclient


----- Weitergeleitet von Markus Gierich/KA/FAG/FIDUCIA/DE am 26.07.2007 08:12
-----
                               ------------------------------------------------ 
       FIDUCIA IT AG                                                            
                                                                                
                                                                                
                                                                                
 Von:  Markus Gierich          An:                                              
       Informationssysteme           users@kannel.org                           
       (SYTIS)                                                                  
                                                                                
                                                                                
 Vom:  26.07.2007 08:10                                                         
                                                                                
                                                                                





Thema:      Connection timeout using Kannel



Hi!

I'm using the kannel sms gateway  (www.kannel.org) and call it via the HTTP
Interface from a java application. To connect to the interface I use the jakarta
commons httpclient.
After sent a sms I close the connection via method.releaseConnection(). If I
don't send a sms for more than 2 hours and then the next sms I get a connection
timeout. But after that, the 2 second sms works again. Does releaseConnection
really close the connection ? The java application runs as a daemon 24 hours a
day an connect to the smsgateway whenever a sms has to be send.

java.net.SocketException: Connection timed out
        at java.net.SocketInputStream.socketRead0(Native Method)
        at java.net.SocketInputStream.read(Unknown Source)
        at java.io.BufferedInputStream.fill(Unknown Source)
        at java.io.BufferedInputStream.read(Unknown Source)
        at
org.apache.commons.httpclient.HttpParser.readRawLine(HttpParser.java:77)
        at
org.apache.commons.httpclient.HttpParser.readLine(HttpParser.java:105)
        at
org.apache.commons.httpclient.HttpConnection.readLine(HttpConnection.java:1115)
        at
org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.readLin
e(MultiThreadedHttpConnectionManager.java:1373)
        at
org.apache.commons.httpclient.HttpMethodBase.readStatusLine(HttpMethodBase.java:1832)
        at
org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodBase.java:1590)
        at
org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:995)
        at
org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:397)
        at
org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:170)
        at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:396)
        at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:324)


Any Ideas?

Markus



----------------------------------------------------------------------------------------------------------------------------------------------

FIDUCIA IT AG
Fiduciastraße 20
76227 Karlsruhe

Sitz der Gesellschaft: Karlsruhe
AG Mannheim HRB 100059

Vorsitzender des Aufsichtsrats: Erwin Kuhn
Vorsitzender des Vorstands: Michael Krings
Vorstand: Klaus-Peter Bruns, Hans-Peter Straberger, Eckhardt Werner

Umsatzsteuer-ID.Nr. DE143582320, http://www.fiducia.de
----------------------------------------------------------------------------------------------------------------------------------------------



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


Antwort: Re: WG: Connection timeout using httpclient [*]

Posted by Ma...@fiducia.de.
I think you are right. After I released the connection, I still see a connection
in the netstat overview.

Thank you

Markus


                               ------------------------------------------------ 
       de.ibm.com                                                               
                                                                                
                                                                                
                                                                                
 Von:  Roland Weber            An:                                              
       <RO...@de.ibm.com>         "HttpClient User Discussion"               
                                     <ht...@jakarta.apache.org>       
                                                                                
 Vom:  26.07.2007 08:25                                                         
       Bitte antworten an                                                       
       "HttpClient User                                                         
       Discussion"                                                              
                                                                                
                                                                                





Thema:      Re: WG: Connection timeout using httpclient [*]




Markus.Gierich@fiducia.de wrote on 26.07.2007 08:16:42:
> After sent a sms I close the connection via method.releaseConnection().
If I
> don't send a sms for more than 2 hours and then the next sms I get
aconnection
> timeout. But after that, the 2 second sms works again. Does
releaseConnection
> really close the connection ?

No, it doesn't. releaseConnection releases the connection back to
the connection pool, where it is kept open for re-use. You can
either disable connection re-use altogether, for example by sending
"Connection: close" headers with the requests, or you can call the
method closeIdleConnections(...) on the connection pool to close
only the connections that have been open and idle for a given
timespan. It depends on the requency of your requests whether
connection keep-alive is a performance improvement or not.

http://jakarta.apache.org/commons/httpclient/performance.html#Connection_persistence

http://jakarta.apache.org/commons/httpclient/apidocs/org/apache/commons/httpclient/HttpConnectionManager.html#closeIdleConnections(long)


cheers,
  Roland





----------------------------------------------------------------------------------------------------------------------------------------------

FIDUCIA IT AG
Fiduciastraße 20
76227 Karlsruhe

Sitz der Gesellschaft: Karlsruhe
AG Mannheim HRB 100059

Vorsitzender des Aufsichtsrats: Erwin Kuhn
Vorsitzender des Vorstands: Michael Krings
Vorstand: Klaus-Peter Bruns, Hans-Peter Straberger, Eckhardt Werner

Umsatzsteuer-ID.Nr. DE143582320, http://www.fiducia.de
----------------------------------------------------------------------------------------------------------------------------------------------



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


Re: WG: Connection timeout using httpclient [*]

Posted by Lars George <la...@worldlingo.com>.
Hi Guys,

I had the same issue - glad you brought this up, I always wondered why we had so many lingering 
connections to the Squid proxy we use. I had to add two headers actually:

   Connection: close
   Proxy-Connection: close

Obviously because of our proxy use internally. Now they get ramped down as expect. Smooth!

HTH,
Lars

Markus.Gierich@fiducia.de wrote:
> Hello Roland,
> 
> I want to use a connection pool. How can I remove closed connections from the
> pool ? As you wrote, the method.releaseConnection() only frees the connection
> for reuse. Do you see my point ?
> 
> Markus
> 
> 
>  MultiThreadedHttpConnectionManager connectionManager = new
> MultiThreadedHttpConnectionManager();
>                 HttpClient client = new HttpClient(connectionManager);
> 
>                 // Create a method instance.
>                 GetMethod method = new GetMethod(url);
>               method.releaseConnection();
> 
> 
>                                ------------------------------------------------ 
>        de.ibm.com                                                               
>                                                                                 
>                                                                                 
>                                                                                 
>  Von:  Roland Weber            An:                                              
>        <RO...@de.ibm.com>         "HttpClient User Discussion"               
>                                      <ht...@jakarta.apache.org>       
>                                                                                 
>  Vom:  26.07.2007 08:25                                                         
>        Bitte antworten an                                                       
>        "HttpClient User                                                         
>        Discussion"                                                              
>                                                                                 
>                                                                                 
> 
> 
> 
> 
> 
> Thema:      Re: WG: Connection timeout using httpclient [*]
> 
> 
> 
> 
> Markus.Gierich@fiducia.de wrote on 26.07.2007 08:16:42:
>> After sent a sms I close the connection via method.releaseConnection().
> If I
>> don't send a sms for more than 2 hours and then the next sms I get
> aconnection
>> timeout. But after that, the 2 second sms works again. Does
> releaseConnection
>> really close the connection ?
> 
> No, it doesn't. releaseConnection releases the connection back to
> the connection pool, where it is kept open for re-use. You can
> either disable connection re-use altogether, for example by sending
> "Connection: close" headers with the requests, or you can call the
> method closeIdleConnections(...) on the connection pool to close
> only the connections that have been open and idle for a given
> timespan. It depends on the requency of your requests whether
> connection keep-alive is a performance improvement or not.
> 
> http://jakarta.apache.org/commons/httpclient/performance.html#Connection_persistence
> 
> http://jakarta.apache.org/commons/httpclient/apidocs/org/apache/commons/httpclient/HttpConnectionManager.html#closeIdleConnections(long)
> 
> 
> cheers,
>   Roland
> 
> 
> 
> 
> 
> ----------------------------------------------------------------------------------------------------------------------------------------------
> 
> FIDUCIA IT AG
> Fiduciastraße 20
> 76227 Karlsruhe
> 
> Sitz der Gesellschaft: Karlsruhe
> AG Mannheim HRB 100059
> 
> Vorsitzender des Aufsichtsrats: Erwin Kuhn
> Vorsitzender des Vorstands: Michael Krings
> Vorstand: Klaus-Peter Bruns, Hans-Peter Straberger, Eckhardt Werner
> 
> Umsatzsteuer-ID.Nr. DE143582320, http://www.fiducia.de
> ----------------------------------------------------------------------------------------------------------------------------------------------
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
> 

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


Re: Connection timeout using httpclient [*]

Posted by Roland Weber <RO...@de.ibm.com>.
Hello Markus,

> I want to use a connection pool. How can I remove closed connections 
from the
> pool ? As you wrote, the method.releaseConnection() only frees the 
connection
> for reuse. Do you see my point ?

There are no closed connections in the pool. There are idle, open
connections. I've pointed out one way to remove idle connections in
my previous mail. Another way is mentioned in the documentation,
which I linked in my previous mail. This topic has also been
discussed before on several occasions and can therefore be found
in the mailing list archives.

cheers,
  Roland


Antwort: Re: WG: Connection timeout using httpclient [*]

Posted by Ma...@fiducia.de.
Hello Roland,

I want to use a connection pool. How can I remove closed connections from the
pool ? As you wrote, the method.releaseConnection() only frees the connection
for reuse. Do you see my point ?

Markus


 MultiThreadedHttpConnectionManager connectionManager = new
MultiThreadedHttpConnectionManager();
                HttpClient client = new HttpClient(connectionManager);

                // Create a method instance.
                GetMethod method = new GetMethod(url);
              method.releaseConnection();


                               ------------------------------------------------ 
       de.ibm.com                                                               
                                                                                
                                                                                
                                                                                
 Von:  Roland Weber            An:                                              
       <RO...@de.ibm.com>         "HttpClient User Discussion"               
                                     <ht...@jakarta.apache.org>       
                                                                                
 Vom:  26.07.2007 08:25                                                         
       Bitte antworten an                                                       
       "HttpClient User                                                         
       Discussion"                                                              
                                                                                
                                                                                





Thema:      Re: WG: Connection timeout using httpclient [*]




Markus.Gierich@fiducia.de wrote on 26.07.2007 08:16:42:
> After sent a sms I close the connection via method.releaseConnection().
If I
> don't send a sms for more than 2 hours and then the next sms I get
aconnection
> timeout. But after that, the 2 second sms works again. Does
releaseConnection
> really close the connection ?

No, it doesn't. releaseConnection releases the connection back to
the connection pool, where it is kept open for re-use. You can
either disable connection re-use altogether, for example by sending
"Connection: close" headers with the requests, or you can call the
method closeIdleConnections(...) on the connection pool to close
only the connections that have been open and idle for a given
timespan. It depends on the requency of your requests whether
connection keep-alive is a performance improvement or not.

http://jakarta.apache.org/commons/httpclient/performance.html#Connection_persistence

http://jakarta.apache.org/commons/httpclient/apidocs/org/apache/commons/httpclient/HttpConnectionManager.html#closeIdleConnections(long)


cheers,
  Roland





----------------------------------------------------------------------------------------------------------------------------------------------

FIDUCIA IT AG
Fiduciastraße 20
76227 Karlsruhe

Sitz der Gesellschaft: Karlsruhe
AG Mannheim HRB 100059

Vorsitzender des Aufsichtsrats: Erwin Kuhn
Vorsitzender des Vorstands: Michael Krings
Vorstand: Klaus-Peter Bruns, Hans-Peter Straberger, Eckhardt Werner

Umsatzsteuer-ID.Nr. DE143582320, http://www.fiducia.de
----------------------------------------------------------------------------------------------------------------------------------------------



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


Re: WG: Connection timeout using httpclient

Posted by Roland Weber <RO...@de.ibm.com>.
Markus.Gierich@fiducia.de wrote on 26.07.2007 08:16:42:
> After sent a sms I close the connection via method.releaseConnection(). 
If I
> don't send a sms for more than 2 hours and then the next sms I get 
aconnection
> timeout. But after that, the 2 second sms works again. Does 
releaseConnection
> really close the connection ?

No, it doesn't. releaseConnection releases the connection back to
the connection pool, where it is kept open for re-use. You can
either disable connection re-use altogether, for example by sending
"Connection: close" headers with the requests, or you can call the
method closeIdleConnections(...) on the connection pool to close
only the connections that have been open and idle for a given
timespan. It depends on the requency of your requests whether
connection keep-alive is a performance improvement or not.

http://jakarta.apache.org/commons/httpclient/performance.html#Connection_persistence
http://jakarta.apache.org/commons/httpclient/apidocs/org/apache/commons/httpclient/HttpConnectionManager.html#closeIdleConnections(long)

cheers,
  Roland