hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Aaron <atdi...@gmail.com>
Subject HttpClient/TCP experts--how do I rapidly use http connections?
Date Tue, 29 Nov 2005 23:19:02 GMT
In my email (inlined below) you'll see a description of how I am using
HTTP client to rapidly generate HTTP post requests to a server--for
performance testing purposes.  The tool I'm writing creates a
multi-threaded HttpClient object (configured w/
MultiThreadedConnectionManager) and then kicks off N threads that each
use this object to execute PostMethods.  When any of the N threads
finishes its request and releases the connection, a new thread takes
its place and executes a PostMethod.  And so on--so that effectively
my tool is greedily keeping 10 PostMethods executing at any given
time.

Each thread is executing code that looks like this:

// client thread
...
final long start = sampleTime();
myHttpClient.executeMethod(post);
final long finish = sampleTime();
reportResponseTime(finish - start);
...

At first I was getting BindExceptions when I configured the tool to
use N > 5 concurrent threads.  I resolved this by registering my own
http socket factory with HttpClient--*my* socket factory did this:

{
   socket = createSocket();
   socket.setReuseAddress(true); // *** This is the important change ***
   return socket;
}

This alleviated my BindExceptions, HOWEVER setting reuseAddress to
true caused my response times to go up--even for cases where N <= 5.
That is,  I was getting better response times when I didn't set
reuseAddress.

My response times improve (in all cases) when I introduce a
significant sleep time (e.g., 1s) at the end of each thread (before it
allows another thread to wake and execute a post method)--HOWEVER, I
do not want to throttle my throughput like this.

I suspect that there is some TCP/HttpClient related issues here that I
do not understand completely.  Is there an expert on this that can
give me some insight into this problem?  Why did setReuseAddress(true)
prevent the BindExceptions, but cause greater response times?  How do
I reuse http connections or execute post methods as fast as possible,
without effecting my response times?

Thanks for any help!!

Aaron



On 11/16/05, Rajat Sharma <rsharma@airvananet.com> wrote:
> a) You can try reusing your connections for the subsequent post methods, if this fits
in your test scenario.
> b) Put socket timeout. ttpClient.setTimeout() andHttpClient.setConnectionTimeout() should
suffice.
> c) Bind exceptions can also come since on Unix there is a limit of number of total TCP
sockets you can open. This limit is 1024. You can increase this limit
>   by ulimit command.
>
> I hope it helps.
> Raj
>
> -----Original Message-----
> From: Aaron [mailto:atdixon@gmail.com]
> Sent: Wednesday, November 16, 2005 3:25 PM
> To: httpclient-user@jakarta.apache.org
> Subject: rapid http connection use
>
>
> Hi,
>
> I am writing a performance testing tool that uses HttpClient; the tool
> kicks off N threads, and each thread creates a PostMethod and executes
> it via an HttpClient instance (configured with
> MultiThreadedHttpConnectionManager). When each request thread
> finishes, another thread takes its place immediately and
> creates/executes another post method using the same HttpClient.  The
> result is that I am rapidly creating PostMethods and executing them.
> (I am ensuring that releaseConnection() is called in each thread.)
>
> I am getting repeated java.net.BindExceptions, and I understand from
> the research that I've done that this can happen if you are creating
> socket connections so rapidly.  This has to do with TCP connections
> sitting in a CLOSED state for some time after being closed.
>
> My tool can be configured to have each request thread sleep some
> number of milliseconds after releasing its connection.  When I
> configure this sleep time to be high (~1 sec), the BindExceptions go
> away.  I assume this is time needed for the released TCP connection to
> leave its CLOSED state.  However, that this sleep time must be so high
> is what concerns me.
>
> HttpClient experts, can you help me around this issue?  How do I
> dispatch these threads more quickly, without getting BindExceptions?
>
> Thanks for any insights--
>
> Aaron
>
> ---------------------------------------------------------------------
> 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


Mime
View raw message