Folks,

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

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?

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

-- 
~Rajesh.B

-- 
~Rajesh.B

Reply via email to