hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ben Wong" <bw...@adaptiveinternational.com>
Subject GetMethod Performance
Date Mon, 16 Feb 2004 05:40:54 GMT
Hi,

I have noticed significant performance difference between using
HttpClient and Socket.

I tried to use GetMethod to download a 2MB file from a Webserver sitting
in the LAN. When I do it with HttpClient, it takes around 13-15 seconds
while it will only take less than half a second with Socket.

I was running the code below on a Sun Blade 100 with Solaris 8
installed. J2SDK1.4.2_03 and HttpClient 2.0 final were used.

Any help would be appreciated.

Thanks,
Ben

HttpClient code:
----------------
HttpClient client = new HttpClient();
GetMethod get = new
GetMethod("http://192.168.0.1/commons-httpclient-2.0-final.zip");
	
int statusCode = client.executeMethod(get);
System.out.println("Status Code: " + statusCode);
int size = 0;
	
InputStream in = get.getResponseBodyAsStream();
byte [] data = new byte[10000];
int read = 0;
	
while ((read = in.read(data)) > 0) {
	size += read;
}

in.close();
get.releaseConnection();

Socket Code:
------------
Socket soc = new Socket("192.168.0.11", 80);
InputStream in = soc.getInputStream();
OutputStream out = soc.getOutputStream();

String command = "GET
http://192.168.0.1/commons-httpclient-2.0-final.zip
HTTP/1.0\nUser-Agent: Jakarta Commons-HttpClient/2.0final\nHost:
10.0.3.11\n\n";
byte [] send = command.getBytes();

out.write(send);
byte b[] = new byte[4096];
int size = 0;
int count = 0;
while( (size = in.read(b)) >= 0) {
	count += size;
}
in.close();
out.close();

soc.close();





---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org


Mime
View raw message