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 Mohit Anchlia <mo...@gmail.com> on 2008/10/13 19:43:49 UTC

CLOSE_WAIT

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

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


Re: CLOSE_WAIT

Posted by Christine <ch...@christine.nl>.
On Mon, 2008-10-20 at 11:20 -0700, Mohit Anchlia wrote:
> So I did enable the logging and I get this, does it mean that the
> connections are being re-used:
> 
> 2008-10-20 11:13:50,715 DEBUG - Releasing connection back to connection manager.

I'm not an expert here, but this line suggests it does, in plain
English.

Christine


-- 
dagdag is just a two character rotation of byebye
www.christine.nl


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


Re: CLOSE_WAIT

Posted by Mohit Anchlia <mo...@gmail.com>.
So I did enable the logging and I get this, does it mean that the
connections are being re-used:

2008-10-20 11:13:50,715 DEBUG - Should NOT close connection, using HTTP/1.1
2008-10-20 11:13:50,715 DEBUG - Releasing connection back to connection manager.
2008-10-20 11:13:50,715 DEBUG - Should NOT close connection, using HTTP/1.1
2008-10-20 11:13:50,715 DEBUG - Releasing connection back to connection manager.
2008-10-20 11:13:50,716 DEBUG - Set parameter http.connection.timeout = 121000
2008-10-20 11:13:50,716 DEBUG - Open connection to sim1.p.i.com:8080
2008-10-20 11:13:50,706 DEBUG - Should NOT close connection, using HTTP/1.1
2008-10-20 11:13:50,717 DEBUG - Adding Host request header
2008-10-20 11:13:50,718 DEBUG - Set parameter http.connection.timeout = 121000
2008-10-20 11:13:50,718 DEBUG - Open connection to localhost:80
2008-10-20 11:13:50,719 DEBUG - Adding Host request header
2008-10-20 11:13:50,716 DEBUG - Adding Host request header
2008-10-20 11:13:50,719 DEBUG - Open connection to sim1.p.i.com:8080
2008-10-20 11:13:50,719 DEBUG - Open connection to localhost:80
2008-10-20 11:13:50,719 DEBUG - Releasing connection back to connection manager.
2008-10-20 11:13:50,723 DEBUG - Open connection to localhost:80
2008-10-20 11:13:50,724 DEBUG - Adding Host request header
2008-10-20 11:13:50,718 DEBUG - Set parameter http.connection.timeout = 121000
2008-10-20 11:13:50,725 DEBUG - Open connection to sim1.p.i.com:8080
2008-10-20 11:13:50,726 DEBUG - Open connection to sim1.p.i.com:8080
2008-10-20 11:13:50,725 DEBUG - Open connection to sim1.p.i.com:8080
2008-10-20 11:13:50,725 DEBUG - Open connection to sim1.p.i.com:8080
2008-10-20 11:13:50,726 DEBUG - Set parameter http.connection.timeout = 121000
2008-10-20 11:13:50,726 DEBUG - Open connection to sim1.p.i.com:8080
2008-10-20 11:13:50,725 DEBUG - Open connection to sim1.p.i.com:8080
2008-10-20 11:13:50,728 DEBUG - Open connection to sim1.p.i.com:8080
2008-10-20 11:13:50,729 DEBUG - Set parameter http.connection.timeout = 121000
2008-10-20 11:13:50,730 DEBUG - Open connection to sim1.p.i.com:8080
2008-10-20 11:13:50,730 DEBUG - Resorting to protocol version default
close connection po

On Mon, Oct 20, 2008 at 10:05 AM, Oleg Kalnichevski <ol...@apache.org> wrote:
> 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 <ol...@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
>
>

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


Re: CLOSE_WAIT

Posted by Oleg Kalnichevski <ol...@apache.org>.
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 <ol...@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


Re: CLOSE_WAIT

Posted by Mohit Anchlia <mo...@gmail.com>.
Thanks. Couple of questions. What do I expect to see when I turn on
the context logging? How do I determine if those connections are being
re-used?

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.

Thanks again

On Mon, Oct 13, 2008 at 2:40 PM, Oleg Kalnichevski <ol...@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


Re: CLOSE_WAIT

Posted by Oleg Kalnichevski <ol...@apache.org>.
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