You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Massimo Signori <si...@webscience.it> on 2004/10/25 13:49:39 UTC

still got problems with too TCP connections open

Hello, i'm still having a lot of problems with my code and with TCP
connections; at this point I just don't know if the problem is HttpClient
but I really don't know how to fix this problem...

here's what my code do: 
Method downloadFileViaHttpClient downloads a ZIP file from a server while
method notifyTimeServer notifies elapsed time to the server every 5 seconds.


Now, here's the code:

HttpClient is instantiated ONE time in both cases.

private void downloadFileViaHttpClient(String remoteFile, String savePath)
throws DownloadException {
        
        
        try {
            logger.debug("DOWNLOADING FILE... " + remoteFile);
            
            method = new GetMethod(remoteFile);
            
            
                
                statusCode=client.executeMethod(method);
                
                FileOutputStream out = new FileOutputStream(savePath);
                
                InputStream in = method.getResponseBodyAsStream();
                
                byte[] buffer = new byte[4096];
                int len = 0;
                while ((len = in.read(buffer)) > 0) {
                    out.write(buffer, 0, len);
                }
                
                in.close();
                out.close();
                
                
        }
        catch	(Exception e) {
             method.releaseConnection();
            throw new
DownloadException(DownloadException.DOWNLOADING_ERROR);
        }
        finally{
            method.releaseConnection();
        }
    }

And the other's method code:

private void notifyTimeServer() {
        
        logger.debug("notifyTimeServer, " + timerURL);
        
        HttpMethod method = new GetMethod(timerURL);
        
                 
            logger.debug("Establishing connection");
            
            try {
                statusCode = client.executeMethod(method);
                
                if (statusCode != -1) {
                 
                    logger.debug("Connection estabilished");
                    byte[] responseBody = method.getResponseBody();
                    
                }
            }
            
            catch (Exception e) {
                logger.error("Error calling jsp "  + e.getMessage());
                                //
            }
            finally{
                method.releaseConnection();
            }
               
    }

NotifyTimeServer is called every 5 seconds... I call releaseConnection...
but... 

Looking with TCPView the number of connections open... about 5000 !!!!

Thanks to all for any help

Best regards, 

Massimo


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


R: R: still got problems with too TCP connections open

Posted by Massimo Signori <si...@webscience.it>.
Hello Oleg, 
fortunately my problem was not caused by HttpClient. 

Thank you very much for your help.

Best regards,
Massimo

-----Messaggio originale-----
Da: Oleg Kalnichevski [mailto:oleg.kalnichevski@bearingpoint.com] 
Inviato: lunedì 25 ottobre 2004 15.03
A: HttpClient Project
Oggetto: Re: R: still got problems with too TCP connections open


Massimo,

Disable connection reuse using the following little trick:

==================================================

public class MyConnectionManager extends SimpleHttpConnectionManager {
    

  public MyConnectionManager() {
    super();
  }
       

  public void releaseConnection(final HttpConnection conn) {
    // Always close the damn thing
    conn.close();
    super.releaseConnection(conn);
  }

}
==================================================

...
this.client = new HttpClient(MyConnectionManager());
==================================================


If you still see connections piling up, then lost likely this is a
platform specific issue, which has nothing to do with HttpClient.


Please let me know the result of the test and I'll try to think of
further recommendations.

Oleg





On Mon, 2004-10-25 at 14:46, Massimo Signori wrote:
> My application is running on winXP with SP2, jre version 1.4.2_05 and
> connection manager is default.
>

> Massimo
>

>

> -----Messaggio originale-----
> Da: Oleg Kalnichevski [mailto:oleg.kalnichevski@bearingpoint.com]

> Inviato: lunedì 25 ottobre 2004 14.00
> A: HttpClient Project
> Oggetto: Re: still got problems with too TCP connections open
>

>

> Massimo,
>

> What platform is your application running on? What is the JRE version?
> What connection manager is being used: default (simple), multithreaded
> or a custom one?
>

> Oleg
>

> On Mon, 2004-10-25 at 13:49, Massimo Signori wrote:
> > Hello, i'm still having a lot of problems with my code and with TCP
> > connections; at this point I just don't know if the problem is
HttpClient
> > but I really don't know how to fix this problem...
> >

> > here's what my code do:

> > Method downloadFileViaHttpClient downloads a ZIP file from a server
while
> > method notifyTimeServer notifies elapsed time to the server every 5
> seconds.
> >

> >

> > Now, here's the code:
> >

> > HttpClient is instantiated ONE time in both cases.
> >

> > private void downloadFileViaHttpClient(String remoteFile, String
savePath)
> > throws DownloadException {
> >        

> >        

> >         try {
> >             logger.debug("DOWNLOADING FILE... " + remoteFile);
> >            

> >             method = new GetMethod(remoteFile);
> >            

> >            

> >                

> >                 statusCode=client.executeMethod(method);
> >                

> >                 FileOutputStream out = new FileOutputStream(savePath);
> >                

> >                 InputStream in = method.getResponseBodyAsStream();
> >                

> >                 byte[] buffer = new byte[4096];
> >                 int len = 0;
> >                 while ((len = in.read(buffer)) > 0) {
> >                     out.write(buffer, 0, len);
> >                 }
> >                

> >                 in.close();
> >                 out.close();
> >                

> >                

> >         }
> >         catch	(Exception e) {
> >              method.releaseConnection();
> >             throw new
> > DownloadException(DownloadException.DOWNLOADING_ERROR);
> >         }
> >         finally{
> >             method.releaseConnection();
> >         }
> >     }
> >

> > And the other's method code:
> >

> > private void notifyTimeServer() {
> >        

> >         logger.debug("notifyTimeServer, " + timerURL);
> >        

> >         HttpMethod method = new GetMethod(timerURL);
> >        

> >                 

> >             logger.debug("Establishing connection");
> >            

> >             try {
> >                 statusCode = client.executeMethod(method);
> >                

> >                 if (statusCode != -1) {
> >                 

> >                     logger.debug("Connection estabilished");
> >                     byte[] responseBody = method.getResponseBody();
> >                    

> >                 }
> >             }
> >            

> >             catch (Exception e) {
> >                 logger.error("Error calling jsp "  + e.getMessage());
> >                                 //
> >             }
> >             finally{
> >                 method.releaseConnection();
> >             }
> >               

> >     }
> >

> > NotifyTimeServer is called every 5 seconds... I call
releaseConnection...
> > but...

> >

> > Looking with TCPView the number of connections open... about 5000 !!!!
> >

> > Thanks to all for any help
> >

> > Best regards,

> >

> > Massimo
> >

> >

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

>
****************************************************************************
> ***********************
> The information in this email is confidential and may be legally
privileged.
> Access to this email by anyone other than the intended addressee is
> unauthorized.  If you are not the intended recipient of this message, any
> review, disclosure, copying, distribution, retention, or any action taken
or
> omitted to be taken in reliance on it is prohibited and may be unlawful.
If
> you are not the intended recipient, please reply to or forward a copy of
> this message to the sender and delete the message, any attachments, and
any
> copies thereof from your system.
>
****************************************************************************
> ***********************
>

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

>

>

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

****************************************************************************
***********************
The information in this email is confidential and may be legally privileged.
Access to this email by anyone other than the intended addressee is
unauthorized.  If you are not the intended recipient of this message, any
review, disclosure, copying, distribution, retention, or any action taken or
omitted to be taken in reliance on it is prohibited and may be unlawful.  If
you are not the intended recipient, please reply to or forward a copy of
this message to the sender and delete the message, any attachments, and any
copies thereof from your system.
****************************************************************************
***********************

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



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


Re: R: still got problems with too TCP connections open

Posted by Oleg Kalnichevski <ol...@bearingpoint.com>.
Massimo,

Disable connection reuse using the following little trick:

==================================================
public class MyConnectionManager extends SimpleHttpConnectionManager {
    
  public MyConnectionManager() {
    super();
  }
       
  public void releaseConnection(final HttpConnection conn) {
    // Always close the damn thing
    conn.close();
    super.releaseConnection(conn);
  }

}
==================================================
...
this.client = new HttpClient(MyConnectionManager());
==================================================

If you still see connections piling up, then lost likely this is a
platform specific issue, which has nothing to do with HttpClient.

Please let me know the result of the test and I'll try to think of
further recommendations.

Oleg




On Mon, 2004-10-25 at 14:46, Massimo Signori wrote:
> My application is running on winXP with SP2, jre version 1.4.2_05 and
> connection manager is default.
>
> Massimo
>
>
> -----Messaggio originale-----
> Da: Oleg Kalnichevski [mailto:oleg.kalnichevski@bearingpoint.com]
> Inviato: lunedì 25 ottobre 2004 14.00
> A: HttpClient Project
> Oggetto: Re: still got problems with too TCP connections open
>
>
> Massimo,
>
> What platform is your application running on? What is the JRE version?
> What connection manager is being used: default (simple), multithreaded
> or a custom one?
>
> Oleg
>
> On Mon, 2004-10-25 at 13:49, Massimo Signori wrote:
> > Hello, i'm still having a lot of problems with my code and with TCP
> > connections; at this point I just don't know if the problem is HttpClient
> > but I really don't know how to fix this problem...
> >
> > here's what my code do:
> > Method downloadFileViaHttpClient downloads a ZIP file from a server while
> > method notifyTimeServer notifies elapsed time to the server every 5
> seconds.
> >
> >
> > Now, here's the code:
> >
> > HttpClient is instantiated ONE time in both cases.
> >
> > private void downloadFileViaHttpClient(String remoteFile, String savePath)
> > throws DownloadException {
> >        
> >        
> >         try {
> >             logger.debug("DOWNLOADING FILE... " + remoteFile);
> >            
> >             method = new GetMethod(remoteFile);
> >            
> >            
> >                
> >                 statusCode=client.executeMethod(method);
> >                
> >                 FileOutputStream out = new FileOutputStream(savePath);
> >                
> >                 InputStream in = method.getResponseBodyAsStream();
> >                
> >                 byte[] buffer = new byte[4096];
> >                 int len = 0;
> >                 while ((len = in.read(buffer)) > 0) {
> >                     out.write(buffer, 0, len);
> >                 }
> >                
> >                 in.close();
> >                 out.close();
> >                
> >                
> >         }
> >         catch	(Exception e) {
> >              method.releaseConnection();
> >             throw new
> > DownloadException(DownloadException.DOWNLOADING_ERROR);
> >         }
> >         finally{
> >             method.releaseConnection();
> >         }
> >     }
> >
> > And the other's method code:
> >
> > private void notifyTimeServer() {
> >        
> >         logger.debug("notifyTimeServer, " + timerURL);
> >        
> >         HttpMethod method = new GetMethod(timerURL);
> >        
> >                 
> >             logger.debug("Establishing connection");
> >            
> >             try {
> >                 statusCode = client.executeMethod(method);
> >                
> >                 if (statusCode != -1) {
> >                 
> >                     logger.debug("Connection estabilished");
> >                     byte[] responseBody = method.getResponseBody();
> >                    
> >                 }
> >             }
> >            
> >             catch (Exception e) {
> >                 logger.error("Error calling jsp "  + e.getMessage());
> >                                 //
> >             }
> >             finally{
> >                 method.releaseConnection();
> >             }
> >               
> >     }
> >
> > NotifyTimeServer is called every 5 seconds... I call releaseConnection...
> > but...
> >
> > Looking with TCPView the number of connections open... about 5000 !!!!
> >
> > Thanks to all for any help
> >
> > Best regards,
> >
> > Massimo
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org
>
> ****************************************************************************
> ***********************
> The information in this email is confidential and may be legally privileged.
> Access to this email by anyone other than the intended addressee is
> unauthorized.  If you are not the intended recipient of this message, any
> review, disclosure, copying, distribution, retention, or any action taken or
> omitted to be taken in reliance on it is prohibited and may be unlawful.  If
> you are not the intended recipient, please reply to or forward a copy of
> this message to the sender and delete the message, any attachments, and any
> copies thereof from your system.
> ****************************************************************************
> ***********************
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org

***************************************************************************************************
The information in this email is confidential and may be legally privileged.  Access to this email by anyone other than the intended addressee is unauthorized.  If you are not the intended recipient of this message, any review, disclosure, copying, distribution, retention, or any action taken or omitted to be taken in reliance on it is prohibited and may be unlawful.  If you are not the intended recipient, please reply to or forward a copy of this message to the sender and delete the message, any attachments, and any copies thereof from your system.
***************************************************************************************************

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


R: still got problems with too TCP connections open

Posted by Massimo Signori <si...@webscience.it>.
My application is running on winXP with SP2, jre version 1.4.2_05 and
connection manager is default.

Massimo


-----Messaggio originale-----
Da: Oleg Kalnichevski [mailto:oleg.kalnichevski@bearingpoint.com] 
Inviato: lunedì 25 ottobre 2004 14.00
A: HttpClient Project
Oggetto: Re: still got problems with too TCP connections open


Massimo,

What platform is your application running on? What is the JRE version?
What connection manager is being used: default (simple), multithreaded
or a custom one?

Oleg

On Mon, 2004-10-25 at 13:49, Massimo Signori wrote:
> Hello, i'm still having a lot of problems with my code and with TCP
> connections; at this point I just don't know if the problem is HttpClient
> but I really don't know how to fix this problem...
> 
> here's what my code do: 
> Method downloadFileViaHttpClient downloads a ZIP file from a server while
> method notifyTimeServer notifies elapsed time to the server every 5
seconds.
> 
> 
> Now, here's the code:
> 
> HttpClient is instantiated ONE time in both cases.
> 
> private void downloadFileViaHttpClient(String remoteFile, String savePath)
> throws DownloadException {
>         
>         
>         try {
>             logger.debug("DOWNLOADING FILE... " + remoteFile);
>             
>             method = new GetMethod(remoteFile);
>             
>             
>                 
>                 statusCode=client.executeMethod(method);
>                 
>                 FileOutputStream out = new FileOutputStream(savePath);
>                 
>                 InputStream in = method.getResponseBodyAsStream();
>                 
>                 byte[] buffer = new byte[4096];
>                 int len = 0;
>                 while ((len = in.read(buffer)) > 0) {
>                     out.write(buffer, 0, len);
>                 }
>                 
>                 in.close();
>                 out.close();
>                 
>                 
>         }
>         catch	(Exception e) {
>              method.releaseConnection();
>             throw new
> DownloadException(DownloadException.DOWNLOADING_ERROR);
>         }
>         finally{
>             method.releaseConnection();
>         }
>     }
> 
> And the other's method code:
> 
> private void notifyTimeServer() {
>         
>         logger.debug("notifyTimeServer, " + timerURL);
>         
>         HttpMethod method = new GetMethod(timerURL);
>         
>                  
>             logger.debug("Establishing connection");
>             
>             try {
>                 statusCode = client.executeMethod(method);
>                 
>                 if (statusCode != -1) {
>                  
>                     logger.debug("Connection estabilished");
>                     byte[] responseBody = method.getResponseBody();
>                     
>                 }
>             }
>             
>             catch (Exception e) {
>                 logger.error("Error calling jsp "  + e.getMessage());
>                                 //
>             }
>             finally{
>                 method.releaseConnection();
>             }
>                
>     }
> 
> NotifyTimeServer is called every 5 seconds... I call releaseConnection...
> but... 
> 
> Looking with TCPView the number of connections open... about 5000 !!!!
> 
> Thanks to all for any help
> 
> Best regards, 
> 
> Massimo
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org

****************************************************************************
***********************
The information in this email is confidential and may be legally privileged.
Access to this email by anyone other than the intended addressee is
unauthorized.  If you are not the intended recipient of this message, any
review, disclosure, copying, distribution, retention, or any action taken or
omitted to be taken in reliance on it is prohibited and may be unlawful.  If
you are not the intended recipient, please reply to or forward a copy of
this message to the sender and delete the message, any attachments, and any
copies thereof from your system.
****************************************************************************
***********************

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



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


Re: still got problems with too TCP connections open

Posted by Oleg Kalnichevski <ol...@bearingpoint.com>.
Massimo,

What platform is your application running on? What is the JRE version?
What connection manager is being used: default (simple), multithreaded
or a custom one?

Oleg

On Mon, 2004-10-25 at 13:49, Massimo Signori wrote:
> Hello, i'm still having a lot of problems with my code and with TCP
> connections; at this point I just don't know if the problem is HttpClient
> but I really don't know how to fix this problem...
> 
> here's what my code do: 
> Method downloadFileViaHttpClient downloads a ZIP file from a server while
> method notifyTimeServer notifies elapsed time to the server every 5 seconds.
> 
> 
> Now, here's the code:
> 
> HttpClient is instantiated ONE time in both cases.
> 
> private void downloadFileViaHttpClient(String remoteFile, String savePath)
> throws DownloadException {
>         
>         
>         try {
>             logger.debug("DOWNLOADING FILE... " + remoteFile);
>             
>             method = new GetMethod(remoteFile);
>             
>             
>                 
>                 statusCode=client.executeMethod(method);
>                 
>                 FileOutputStream out = new FileOutputStream(savePath);
>                 
>                 InputStream in = method.getResponseBodyAsStream();
>                 
>                 byte[] buffer = new byte[4096];
>                 int len = 0;
>                 while ((len = in.read(buffer)) > 0) {
>                     out.write(buffer, 0, len);
>                 }
>                 
>                 in.close();
>                 out.close();
>                 
>                 
>         }
>         catch	(Exception e) {
>              method.releaseConnection();
>             throw new
> DownloadException(DownloadException.DOWNLOADING_ERROR);
>         }
>         finally{
>             method.releaseConnection();
>         }
>     }
> 
> And the other's method code:
> 
> private void notifyTimeServer() {
>         
>         logger.debug("notifyTimeServer, " + timerURL);
>         
>         HttpMethod method = new GetMethod(timerURL);
>         
>                  
>             logger.debug("Establishing connection");
>             
>             try {
>                 statusCode = client.executeMethod(method);
>                 
>                 if (statusCode != -1) {
>                  
>                     logger.debug("Connection estabilished");
>                     byte[] responseBody = method.getResponseBody();
>                     
>                 }
>             }
>             
>             catch (Exception e) {
>                 logger.error("Error calling jsp "  + e.getMessage());
>                                 //
>             }
>             finally{
>                 method.releaseConnection();
>             }
>                
>     }
> 
> NotifyTimeServer is called every 5 seconds... I call releaseConnection...
> but... 
> 
> Looking with TCPView the number of connections open... about 5000 !!!!
> 
> Thanks to all for any help
> 
> Best regards, 
> 
> Massimo
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org

***************************************************************************************************
The information in this email is confidential and may be legally privileged.  Access to this email by anyone other than the intended addressee is unauthorized.  If you are not the intended recipient of this message, any review, disclosure, copying, distribution, retention, or any action taken or omitted to be taken in reliance on it is prohibited and may be unlawful.  If you are not the intended recipient, please reply to or forward a copy of this message to the sender and delete the message, any attachments, and any copies thereof from your system.
***************************************************************************************************

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