Return-Path: Delivered-To: apmail-jakarta-commons-httpclient-dev-archive@www.apache.org Received: (qmail 68409 invoked from network); 16 Feb 2004 06:18:01 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 16 Feb 2004 06:18:01 -0000 Received: (qmail 99776 invoked by uid 500); 16 Feb 2004 06:17:38 -0000 Delivered-To: apmail-jakarta-commons-httpclient-dev-archive@jakarta.apache.org Received: (qmail 99756 invoked by uid 500); 16 Feb 2004 06:17:38 -0000 Mailing-List: contact commons-httpclient-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Commons HttpClient Project" Reply-To: "Commons HttpClient Project" Delivered-To: mailing list commons-httpclient-dev@jakarta.apache.org Received: (qmail 99743 invoked from network); 16 Feb 2004 06:17:38 -0000 Received: from unknown (HELO mxout2.cac.washington.edu) (140.142.33.4) by daedalus.apache.org with SMTP; 16 Feb 2004 06:17:38 -0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.32.139]) by mxout2.cac.washington.edu (8.12.11+UW04.02/8.12.11+UW04.02) with ESMTP id i1G6Hmvn009226 for ; Sun, 15 Feb 2004 22:17:48 -0800 Received: from [10.0.1.2] (pool-151-199-20-176.bos.east.verizon.net [151.199.20.176]) (authenticated bits=0) by smtp.washington.edu (8.12.10+UW03.09/8.12.11+UW04.02) with ESMTP id i1G6HksZ011392 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=NOT) for ; Sun, 15 Feb 2004 22:17:48 -0800 Mime-Version: 1.0 (Apple Message framework v612) In-Reply-To: <002201c3f44f$8737ca40$9c03000a@bluvy> References: <002201c3f44f$8737ca40$9c03000a@bluvy> Content-Type: text/plain; charset=US-ASCII; format=flowed Message-Id: Content-Transfer-Encoding: 7bit From: Michael Becke Subject: Re: GetMethod Performance Date: Mon, 16 Feb 2004 01:17:43 -0500 To: "Commons HttpClient Project" X-Mailer: Apple Mail (2.612) X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Hi Ben, I believe your HttpClient numbers are being inflated by one-time initialization costs. I was able to get approximately the same numbers with HttpClient and Socket. Please see my examples attached below: Mike HttpClient code: HttpClient client = new HttpClient(); GetMethod get = new GetMethod("http://www.google.com"); client.executeMethod(get); get.getResponseBodyAsString(); get.releaseConnection(); client = new HttpClient(); get = new GetMethod("SOME_URL"); long start = System.currentTimeMillis(); int statusCode = client.executeMethod(get); int size = 0; InputStream in = get.getResponseBodyAsStream(); byte [] data = new byte[4096]; int read = 0; while ((read = in.read(data)) > 0) { size += read; } in.close(); get.releaseConnection(); long end = System.currentTimeMillis(); System.out.println(end-start); Socket code: HttpClient client = new HttpClient(); GetMethod get = new GetMethod("http://www.google.com"); client.executeMethod(get); get.getResponseBodyAsString(); get.releaseConnection(); long start = System.currentTimeMillis(); Socket soc = new Socket("HOST", 80); InputStream in = soc.getInputStream(); OutputStream out = soc.getOutputStream(); String command = "GET /SOME_FILE\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(); long end = System.currentTimeMillis(); System.out.println(end-start); On Feb 16, 2004, at 12:40 AM, Ben Wong wrote: > 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 > --------------------------------------------------------------------- To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org