On Thu, 2007-02-08 at 16:55 +0800, allen huang wrote:
> Thank you Oleg, your tip is useful for me. So do you have good idea to how
> to measure the difference between persistence connection and non-persistence
> connection? Actually one of my desination in this testing is, how more fast
> when use persistence connection than non-.
> 

Allen,

If you are familiar with Apache Benchmark [1], you can use similar tool
based on HttpClient [2]. Both tools can optionally enable / disable
connection persistence.

Hope this helps

Oleg

[1] http://httpd.apache.org/docs/2.0/programs/ab.html
[2]
http://svn.apache.org/repos/asf/jakarta/commons/proper/httpclient/trunk/src/contrib/org/apache/commons/httpclient/contrib/benchmark/



> On 2/7/07, Oleg Kalnichevski <[EMAIL PROTECTED]> wrote:
> >
> > 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).After<
> > http://jakarta.apache.org%29.After>testing,
> > > 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: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to