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: HttpClient.executeMethod() performance
Date Mon, 21 Apr 2008 19:19:03 GMT

On Mon, 2008-04-21 at 14:36 +0530, Rajesh Balamohan wrote:
> Folks,
> 

Rajesh,

First off, please _DO NOT_ cross post dev and users lists.


> I am using HttpClient 3.0 in one of our projects. I have tried to give the
> code snippet below.
> 
> We try to initialize mutithreaded http connection manager once in our code
> like the following.
> 
> MultiThreadedHttpConnectionManager mthcm = new
> MultiThreadedHttpConnectionManager();
> mthcm.setMaxConnectionsPerHost(maxConnections);
> mthcm.setMaxTotalConnections(100);
> httpClient = new HttpClient(mthcm);
> 
> 
> And we try to reuse httpClient multiple times (SAME INSTANCE) in another
> method like the following.
> 
> PostMethod postMethod = new PostMethod("http://" + serverName + ":" + port +
> Constants.URL);
> BinaryEncoder be = new BinaryEncoder(); //ignore this since its our
> proprietary code
> ByteBuffer bb = be.encodeRequest(request);
> postMethod.setRequestBody(new String(bb.array()));
> try {
>     httpClient.executeMethod(postMethod);
>     } catch (Exception e) {
>            throw new MethodExecuteException(e);
>     }
> 
> While doing the profiling with JProbe, most of the time was being spent in
> httpClient.executeMethod(). Further analysis showed that most of the time
> spent INSIDE executeMethod() was in
> org.apache.commons.httpclient.Wire.wire(String,InputStream).
> 

Wire#wire is not meant to be executed unless you have wire logging on.
There is no point running any benchmarks with wire logging on, because
you just end up measuring performance of the underlying logging toolkit,
not that of HTTP transport. 

> And this method is spending most of the time in StringBuffer.append()
> internally.
> 
> *Observerations and Questions:
> *1. We are sending 2Kb payload in the POST method as binary content using
> BinaryEncoder we have got. Kindly note that this is not reported as
> timeconsuming method. So let us ignore the BinaryEncoder part.
> 2. Is there any other way to make better usage of HttpClient for 2Kb
> payloads. Maximum i can set is to "disable" nagle's algorithm so that the
> data can get flushed immediately. Also, set the MTU in OS to 1500 or so.
> 3. Is there a way to optimize Wire.wire()?
> 4. Are there any other parameters we can set to optimize httpClient further?
> 

Please refer to the HttpClient optimization guide

http://hc.apache.org/httpclient-3.x/performance.html

Hope this helps

Oleg

> It would be great if you could give pointers on this. Please let me know if
> you need more information on this.
> 


---------------------------------------------------------------------
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