[prev in list] [next in list] [prev in thread] [next in thread]
List: httpclient-users
Subject: RE: PROBLEM WITH setMaxTotalConnections
From: Oleg Kalnichevski <olegk () apache ! org>
Date: 2007-03-26 15:00:41
Message-ID: 1174921241.4774.82.camel () okhost
[Download RAW message or body]
On Mon, 2007-03-26 at 16:57 +0200, Joan Balagueró wrote:
> Hello Oleg,
>
> Ok, now I'm understand how the httpclient pool Works (I didn't know anything
> about blocking connections until expires the pool timeout).
>
> Because my application hasn't to wait for getting connections (instead of
> this, it has to throw a exception), I'll set the
> objHttp.getParams().setConnectionManagerTimeout to 1ms. I suppose that
> setting this to 0 is equivalent to infinite timeout??
>
That's correct.
Oleg
> Thanks a lot,
>
> Joan.
>
>
> -----Mensaje original-----
> De: Oleg Kalnichevski [mailto:olegk@apache.org]
> Enviado el: lunes, 26 de marzo de 2007 16:07
> Para: HttpClient User Discussion
> Asunto: RE: PROBLEM WITH setMaxTotalConnections
>
> On Mon, 2007-03-26 at 15:39 +0200, Joan Balagueró wrote:
> > Hello (again),
> >
> > I write a small program to test the maxTotalConnections.
> >
> > It's an application with a static httpClient (multithreaded). The main
> > program inits this variable and starts 20 threads that use it to connect
> to
> > our website. Again, I set the limit of active connections to 1. With these
> > conditions, all threads are able to connect to destination perfectly (I've
> > repeated the same with 200 threads).
> >
> > I don't know what to do to limit the number of connections. I don't know
> if
> > I'm doing something wrong or if this is a bug of httpClient 3.1
> >
> > Any suggestions will be much appreciated.
> >
> > Thanks,
> >
> > Joan.
> >
>
> Joan,
>
> As I said in my previous post to you, it is perfectly plausible all
> worker threads simply use the same lone connection to execute HTTP
> methods. Those worker threads spend most of the time blocked waiting to
> obtain a connection from the connection pool, but this is another
> story.
>
> You can easily test this assumption by setting the connection manager
> timeout to a very low value (50 ms or something). If you start seeing
> ConnectionPoolTimeoutException exceptions thrown by the connection
> manager, HttpClient is all right
>
> Oleg
>
> >
> > The code is the following:
> >
> > package com.vcfw.admin.utils;
> >
> > import java.io.BufferedInputStream;
> > import java.io.ByteArrayOutputStream;
> > import java.util.concurrent.CountDownLatch;
> >
> > import org.apache.commons.httpclient.HttpClient;
> > import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
> > import org.apache.commons.httpclient.cookie.CookiePolicy;
> > import org.apache.commons.httpclient.methods.PostMethod;
> >
> > public class testHttp
> > {
> > public static HttpClient objHttp = null;
> > public static CountDownLatch cdlStart = new CountDownLatch(1);
> >
> > // Main.
> > public static void main(String[] args)
> > {
> > // The thread
> > Runnable r = new Runnable()
> > {
> > public void run()
> > {
> > try
> > {
> > // Wait until start...
> > testHttp.cdlStart.await();
> >
> > // Send the POST request.
> > PostMethod objPost = new PostMethod("http://www.grupoventus.com");
> > testHttp.objHttp.executeMethod(objPost);
> >
> > // Read the response.
> > BufferedInputStream bis = new
> > BufferedInputStream(objPost.getResponseBodyAsStream());
> > ByteArrayOutputStream bos = new ByteArrayOutputStream();
> > byte[] buffer = new byte[4098];
> > int numBytes;
> >
> > while ((numBytes = bis.read(buffer)) >= 0) bos.write(buffer, 0,
> > numBytes);
> > byte[] byteResponse = bos.toByteArray();
> >
> > // Print the response.
> > System.out.println(new String(byteResponse));
> >
> > // Close all
> > objPost.releaseConnection();
> > bis.close();
> > bos.close();
> > }
> > catch (Exception e) { e.printStackTrace(); }
> > }
> > };
> >
> > // MAIN PROGRAM.
> > try
> > {
> > // Init the static httpClient
> > objHttp = new HttpClient(new MultiThreadedHttpConnectionManager());
> >
> objHttp.getHttpConnectionManager().getParams().setMaxTotalConnections(1);
> >
> objHttp.getHttpConnectionManager().getParams().setConnectionTimeout(2000);
> > objHttp.getHttpConnectionManager().getParams().setSoTimeout(10000);
> >
> objHttp.getHttpConnectionManager().getParams().setStaleCheckingEnabled(true)
> > ;
> > objHttp.getParams().setCookiePolicy(CookiePolicy.RFC_2109);
> >
> > // Start 20 threads that connect to "http://www.grupoventus.com".
> > for (int i = 0; i < 20; i++)
> > {
> > new Thread(r).start();
> > }
> >
> > // Start !!
> > cdlStart.countDown();
> > }
> > catch (Exception e) { e.printStackTrace(); }
> > }
> >
> > }
> >
> >
> >
> > ---------------------------------------------------------------------
> > 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
>
>
>
> ---------------------------------------------------------------------
> 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
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic