hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: CLOSE_WAIT
Date Mon, 20 Oct 2008 17:05:12 GMT
On Sun, 2008-10-19 at 18:12 -0700, Mohit Anchlia wrote:
> Thanks. Couple of questions. What do I expect to see when I turn on
> the context logging? 

Debug logs

> How do I determine if those connections are being
> re-used?
> 

You'll have analyze debug logs of the session.

> Also, I am using log4j.xml and not log4j.properties, is there a place
> that gives some example of configuring log4j.xml. If not then I'll
> search log4j manuals.

Actually reading the f manual sometimes truly helps

Oleg

> 
> Thanks again
> 
> On Mon, Oct 13, 2008 at 2:40 PM, Oleg Kalnichevski <olegk@apache.org> wrote:
> > On Mon, 2008-10-13 at 10:43 -0700, Mohit Anchlia wrote:
> >> I saw quite a few posts on how to get rid of CLOSE_WAIT. And based on
> >> those posts I changed my code but still I see CLOSE_WAITS. Below is my
> >> test code:
> >>
> >>
> >> public class Test {
> >>     private static  MultiThreadedHttpConnectionManager con = new
> >> MultiThreadedHttpConnectionManager();
> >>     private static void doGet(HttpClient client) {
> >>         System.out.println("CONN POOL " + con.getConnectionsInPool());
> >>         //System.out.println("DEF CON "
> >> +client.getHttpConnectionManager().getParams().getDefaultMaxConnectionsPerHost());
> >>         //System.out.println("MAX CON " +
> >> client.getHttpConnectionManager().getParams().getMaxTotalConnections()
> >> );
> >>
> >>         GetMethod get = new GetMethod("http://localhost:8080/s/e");
> >>                     get.setQueryString("version=V07.08&request_type=1");
> >>              get.addRequestHeader( "Connection", "close");
> >>         try {
> >>             long statusCode = client.executeMethod(get);
> >>             System.out.println(IOUtils.toString(get.getResponseBodyAsStream()));
> >>             if (statusCode != HttpStatus.SC_OK) {
> >>                            }
> >>              Thread.sleep(1000);
> >>         } catch(IOException ioe){
> >>                 ioe.printStackTrace();
> >>                     }catch (Exception e){} finally {
> >>             if (get != null) get.releaseConnection();
> >>         }
> >>     }
> >>     public static void main(String []a) throws Exception{
> >>
> >>         HttpConnectionManagerParams params = new HttpConnectionManagerParams();
> >>         params.setDefaultMaxConnectionsPerHost(2);
> >>         //params.setMaxConnectionsPerHost(2);
> >>         params.setMaxTotalConnections(2);
> >>         con.setParams(params);
> >>
> >>         HttpClient client = new HttpClient();
> >>         client.getParams().setParameter("http.connection.timeout", new
> >> Integer(1000));
> >>        int i = 0;
> >>        while ( i++ < 500){
> >>         client = new HttpClient(con);
> >>         doGet(client);
> >>         client = null;
> >>         con.closeIdleConnections(1000l);
> >>         //con.deleteClosedConnections();
> >>        }
> >> /////////////
> >>
> >> so I am closing connection after each call, but still I see lot of
> >> CLOSE_WAIT. Is there something that I am doing incorrectly? I was
> >> expecting that above code will get rid of CLOSE_WAIT
> >>
> >
> > Firstly, turn context logging on and see if HttpClient is reusing
> > connections
> >
> > http://hc.apache.org/httpclient-3.x/logging.html
> >
> > Secondly, neither Thread#sleep() nor #closeIdleConnections() can
> > guarantee exact timing. If you want all idle connections closed
> > immediately you should pass 0 as a parameter to
> > #closeIdleConnections();
> >
> > con.closeIdleConnections(0L);
> >
> > Hope this helps
> >
> > Oleg
> >
> >> ---------------------------------------------------------------------
> >> 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
> >
> >
> 
> ---------------------------------------------------------------------
> 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


Mime
View raw message