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 Boquan Xie <qu...@hotmail.com> on 2007/04/03 23:02:23 UTC

Too many file descriptors in TIME_WAIT state

Hi,

I am a new user of HttpClient and I am trying to do a performance test which 
including httpclient requests.

I have serveral threads constantly sending requests and getting responses. 
In the main thread, I keep a multithreadedhttpconnectionManager and a 
httpClient. the instance of the httpclient is passed to each thread.

    MultiThreadedHttpConnectionManager connectionMgr = new 
MultiThreadedHttpConnectionManager();
    HttpClient hClient = new HttpClient();
    hClient.getHostConfiguration().setHost("sottamlab1", 9300, "http");
    hClient.setHttpConnectionManager(connectionMgr);

in each of threads:

   while (true)
   {
      PostMethod postMethod = new 
PostMethod("http://sottamlab1:9300/p2pd/servlet/dispatch");

      postMethod.addRequestHeader("soapaction", "someaction");
      postMethod.addRequestHeader("Content-Type", "text/xml");

      postMethod.setRequestBody(requestBody);
      this.hClient.executeMethod(postMethod);

      InputStream is = postMethod.getResponseBodyAsStream();

      postMethod.releaseConnection();
  }

After a very short time ( < 1 min ), running the program with 3 threads, a 
large number of file descriptors is left at state TIME_WAIT in tcpview. is 
this normal ? It seems to me that httpclient/multithreadedHttpClientManager 
didnot reuse the connections for me. Am I missing something in the code ?

if I run the program with 1 thread, the problem of large number of file 
descriptors in TIME_WAIT state doesnot happen.

Please help !

_________________________________________________________________
Get a FREE Web site, company branded e-mail and more from Microsoft Office 
Live! http://clk.atdmt.com/MRT/go/mcrssaub0050001411mrt/direct/01/


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


Re: Too many file descriptors in TIME_WAIT state

Posted by William Rose <wr...@zip-it.org>.
Hi there,

IIRC, you should consume all the data from the input stream as well as 
calling releaseConnection().

So put in something like:

  byte[] buffer = new byte[65536];
  int bytes;
  while( (bytes = is.read(buffer)) > 0 )
    ;
between the getResponseBodyAsStream and releaseConnection.

cheers,

Will


Boquan Xie wrote:
>
> Hi,
>
> I am a new user of HttpClient and I am trying to do a performance test 
> which including httpclient requests.
>
> I have serveral threads constantly sending requests and getting 
> responses. In the main thread, I keep a 
> multithreadedhttpconnectionManager and a httpClient. the instance of 
> the httpclient is passed to each thread.
>
>    MultiThreadedHttpConnectionManager connectionMgr = new 
> MultiThreadedHttpConnectionManager();
>    HttpClient hClient = new HttpClient();
>    hClient.getHostConfiguration().setHost("sottamlab1", 9300, "http");
>    hClient.setHttpConnectionManager(connectionMgr);
>
> in each of threads:
>
>   while (true)
>   {
>      PostMethod postMethod = new 
> PostMethod("http://sottamlab1:9300/p2pd/servlet/dispatch");
>
>      postMethod.addRequestHeader("soapaction", "someaction");
>      postMethod.addRequestHeader("Content-Type", "text/xml");
>
>      postMethod.setRequestBody(requestBody);
>      this.hClient.executeMethod(postMethod);
>
>      InputStream is = postMethod.getResponseBodyAsStream();
>
>      postMethod.releaseConnection();
>  }
>
> After a very short time ( < 1 min ), running the program with 3 
> threads, a large number of file descriptors is left at state TIME_WAIT 
> in tcpview. is this normal ? It seems to me that 
> httpclient/multithreadedHttpClientManager didnot reuse the connections 
> for me. Am I missing something in the code ?
>
> if I run the program with 1 thread, the problem of large number of 
> file descriptors in TIME_WAIT state doesnot happen.
>
> Please help !
>
> _________________________________________________________________
> Get a FREE Web site, company branded e-mail and more from Microsoft 
> Office Live! http://clk.atdmt.com/MRT/go/mcrssaub0050001411mrt/direct/01/
>
>
> ---------------------------------------------------------------------
> 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: Too many file descriptors in TIME_WAIT state

Posted by Roland Weber <RO...@de.ibm.com>.
"Boquan Xie" <qu...@hotmail.com> wrote on 03.04.2007 23:02:23:

> After a very short time ( < 1 min ), running the program with 3 threads, 
a 
> large number of file descriptors is left at state TIME_WAIT in tcpview. 
is 
> this normal ?

On Windows, yes. See the recent discussions about BindException
on this mailing list. They include some links to workarounds.

cheers,
  Roland