Thanks for the replies. I do have some code between the getResponseBodyAsStream and releaseConnection, and I simplied it in the first email:

  InputStream is = postMethod.getResponseBodyAsStream();
  SAXReader reader = new SAXReader();
  Document doc = reader.read(is);

  postMethod.releaseConnection();

I assumed that it consumed all the data in the inputStream. and releaseConnection is supposed to close the inputStream too.

I tried the workarounds Roland mentioned, and added the registry entries:

TcpTimedWaitDelay (30)
MaxUserPort(32678)

Then the number of the file descriptors at state TIME_WAIT became much less and under control while I ran my performance test program.

Thank you all for your help!

-- Boquan

From: "Xie, Boquan" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Date: Wed, 4 Apr 2007 14:40:26 -0400

From: William Rose <[EMAIL PROTECTED]> Subject Re: Too many file descriptors in TIME_WAIT state Date Tue, 03 Apr 2007 21:32:47 GMT
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 !


_________________________________________________________________
Exercise your brain! Try Flexicon. http://games.msn.com/en/flexicon/default.htm?icid=flexicon_hmemailtaglineapril07


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to