Return-Path: Delivered-To: apmail-jakarta-commons-user-archive@www.apache.org Received: (qmail 56323 invoked from network); 7 Feb 2007 14:01:22 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 7 Feb 2007 14:01:22 -0000 Received: (qmail 6537 invoked by uid 500); 7 Feb 2007 14:01:24 -0000 Delivered-To: apmail-jakarta-commons-user-archive@jakarta.apache.org Received: (qmail 6449 invoked by uid 500); 7 Feb 2007 14:01:23 -0000 Mailing-List: contact commons-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Jakarta Commons Users List" Reply-To: "Jakarta Commons Users List" Delivered-To: mailing list commons-user@jakarta.apache.org Received: (qmail 6437 invoked by uid 99); 7 Feb 2007 14:01:23 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Feb 2007 06:01:23 -0800 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: neutral (herse.apache.org: local policy) Received: from [62.2.95.247] (HELO smtp.hispeed.ch) (62.2.95.247) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Feb 2007 06:01:13 -0800 Received: from [192.168.1.102] (84-75-116-76.dclient.hispeed.ch [84.75.116.76]) (authenticated bits=0) by smtp.hispeed.ch (8.12.11.20060308/8.12.11/taifun-1.0) with ESMTP id l17E0iRl003057 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO) for ; Wed, 7 Feb 2007 15:00:49 +0100 Subject: Re: [httpclient_common]_why httpclient's speed is the same with JDK httpurlconnection From: Oleg Kalnichevski To: Jakarta Commons Users List In-Reply-To: <84c568dd0702061706y30f2d5di8e9fc193727169ca@mail.gmail.com> References: <84c568dd0702061706y30f2d5di8e9fc193727169ca@mail.gmail.com> Content-Type: text/plain Date: Wed, 07 Feb 2007 15:00:44 +0100 Message-Id: <1170856844.5089.14.camel@okhost> Mime-Version: 1.0 X-Mailer: Evolution 2.8.1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: ClamAV version 0.88.7, clamav-milter version 0.88.7 on smtp-02.tornado.cablecom.ch X-Virus-Status: Clean X-DCC-spamcheck-01.tornado.cablecom.ch-Metrics: smtp-02.tornado.cablecom.ch 1377; Body=1 Fuz1=1 Fuz2=1 X-Virus-Checked: Checked by ClamAV on apache.org On Wed, 2007-02-07 at 09:06 +0800, allen huang wrote: > Hi, > I have a problem when trying to comparing the speed between JDK > HttpURLConnection and HttpClient. > > Now I have two methods, one is performed with jdk(1.5) httpurlConnection, > the other is performed with httpClient( 3.0.1). Both of them try to download > the same webpage(http://jakarta.apache.org).Aftertesting, > the average time which performed JDK httpurlconnection is 200ms, > so as the one which performed httpclient.That means their speeds are almost > the same. > > So, since HttpClient use persistence connection default but JDK do not, why > httpClient's speed could not be more fast than JDK? > > Another problem is, is it normal to httpclient to use 200ms to download a > page like http://jakarta.apache.org? I mean, when using persistence > connection, maybe this could not be accepted. > > Any help will be great appreciated > Allen Essentially you are measuring the speed of JIT compiler, DNS hostname lookup, and that of the link to your ISP. I suspect this measurement does reflect the performance of the underlying HTTP engines at all. Please consider running your tests against an HTTP server on the local network, making a significant number of repetitions to eliminate data distortions due to JVM startup, JIT compilation and other factors You might want to use this benchmarking tool to test performance of HttpClient [1]. The HttpClient benchmark tool supports a subset of commands of the Apache Benchmark (ab) and produces similar output. Hope this helps Oleg [1] http://svn.apache.org/repos/asf/jakarta/commons/proper/httpclient/trunk/src/contrib/org/apache/commons/httpclient/contrib/benchmark/ > ----------------------------------------Source to httpclient > method------------------------------------- > public void testGetMethod(){ > > MultiThreadedHttpConnectionManager manager=new > MultiThreadedHttpConnectionManager(); > manager.getParams().setConnectionTimeout(3000); > manager.getParams ().setDefaultMaxConnectionsPerHost(1); > // manager.getParams().setMaxTotalConnections(30); > HttpClient httpClient = new HttpClient(manager); > // Set the default host/protocol for the methods to connect to. > // This value will only be used if the methods are not given an > absolute URI > // httpClient.getHostConfiguration().setProxy("192.168.0.10",80); > // httpClient.getHostConfiguration().setHost("jakarta.apache.org", > 80, "http"); > GetMethod method = new GetMethod(" http://jakarta.apache.org"); > for (int i=0;i<10;i++){ > try { > > // System.out.println(" - about to get something from " + > method.getURI()); > // execute the method > long start=System.currentTimeMillis(); > httpClient.executeMethod(method); > > // System.out.println(" - get executed"); > // get the response body as an array of bytes > byte[] bytes = method.getResponseBody(); > System.out.println("cost time is "+(System.currentTimeMillis > ()-start)); > > // System.out.println(new String(bytes)); > // System.out.println(" - " + bytes.length + " bytes read"); > > } catch (Exception e) { > System.out.println(" - error: " + e); > } finally { > // always release the connection after we're done > method.releaseConnection(); > // System.out.println(" - connection released"); > } > } > } > ------------------------------------------source code to JDK > httpurlconnection------------------------------------------------ > public void testJDKHttpURlconnection() { > > for (int i = 0; i < 10; i++) { > try { > long start = System.currentTimeMillis(); > URL requestedURL = new URL("http://jakarta.apache.org"); > HttpURLConnection conn = (HttpURLConnection) requestedURL > .openConnection(); > > conn.setRequestProperty("User-Agent", > "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0 > )"); > > conn.setUseCaches(false); > > conn.connect(); > > BufferedInputStream remoteBIS = new BufferedInputStream(conn > .getInputStream()); > ByteArrayOutputStream baos = new > ByteArrayOutputStream(10240); > byte[] buf = new byte[1024]; > int bytesRead = 0; > while (bytesRead >= 0) { > baos.write(buf, 0, bytesRead); > bytesRead = remoteBIS.read(buf); > } > byte[] content = baos.toByteArray(); > System.out.println("cost time is " > + (System.currentTimeMillis() - start)); > > } catch (Exception e) { > } > } > } --------------------------------------------------------------------- To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-user-help@jakarta.apache.org