You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by allen huang <co...@gmail.com> on 2007/02/07 02:06:36 UTC

[httpclient_common]_why httpclient's speed is the same with JDK httpurlconnection

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

----------------------------------------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) {
            }
        }
    }

Re: [httpclient_common]_why httpclient's speed is the same with JDK httpurlconnection

Posted by allen huang <co...@gmail.com>.
Hi Craig,
I use JDK5.0. Actually, Some guys told me that HttpClient is very fast. Then
I perform this testing to find how more it runs than JDK httpurlconnection.
And, of course, the test result could not feed my need, in another words, I
think this speed(200ms to download a normal page about tens of kbytes)is too
flow. And, I wonder if my using to httpclient is perfect, I just follow the
apache guide to do that.

On 2/7/07, Craig McClanahan <cr...@apache.org> wrote:
>
> On 2/6/07, allen huang <co...@gmail.com> 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?
>
>
> What JDK are you using?  IIRC, the JDK's HttpUrlConnection class has
> defaulted to persistent HTTP connections since at least JDK 1.1 days.



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.
>
>
> The timing of something like this, especially on a relatively small page,
> is
> going to be so dominated by the speed of your connection to the Internet
> that "acceptable" is in the eyes of the beholder.  Is it fast enough for
> your requirements?  If so, it doesn't matter which technology you choose
> --
> they both work.  Is it too slow?  Then it doesn't matter which technology
> you choose -- they both fail to meet your needs.  Is your average need to
> download multiple megabytes instead of a couple hundred kbytes?  Then the
> test you ran is totally meaningless because it did not reflect your real
> requirements.
>
> Any help will be great appreciated
>
>
> Craig
>

Re: [httpclient_common]_why httpclient's speed is the same with JDK httpurlconnection

Posted by Craig McClanahan <cr...@apache.org>.
On 2/6/07, allen huang <co...@gmail.com> 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?


What JDK are you using?  IIRC, the JDK's HttpUrlConnection class has
defaulted to persistent HTTP connections since at least JDK 1.1 days.

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.


The timing of something like this, especially on a relatively small page, is
going to be so dominated by the speed of your connection to the Internet
that "acceptable" is in the eyes of the beholder.  Is it fast enough for
your requirements?  If so, it doesn't matter which technology you choose --
they both work.  Is it too slow?  Then it doesn't matter which technology
you choose -- they both fail to meet your needs.  Is your average need to
download multiple megabytes instead of a couple hundred kbytes?  Then the
test you ran is totally meaningless because it did not reflect your real
requirements.

Any help will be great appreciated


Craig

Re: [httpclient_common]_why httpclient's speed is the same with JDK httpurlconnection

Posted by sebb <se...@gmail.com>.
On 08/02/07, maomaode <ma...@gmail.com> wrote:
> I think the HttpClient essentially use the urlconnection, then i would
> ask why httpclient will faster than urlconnection?

As far as I know, HttpClient does not use URLConnection - it uses Sockets.

This is what gives it the ability to manage connections more flexibly
than URLConnection.

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


Re: [httpclient_common]_why httpclient's speed is the same with JDK httpurlconnection

Posted by allen huang <co...@gmail.com>.
Agree with you. But I think httpclient's target is not only this. Httpclient
has a connection pool to keep the links with the remote http server, and
httpurlconnection download a page with re-opening the connection each time,
why their speeds are not different?

On 2/8/07, maomaode <ma...@gmail.com> wrote:
>
> I think the HttpClient essentially use the urlconnection, then i would
> ask why httpclient will faster than urlconnection?
> I think the benefit of HttpClient is that it manage the connection, that
> make your code more neat, you can focus on the business logic...
> > 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
> >
> > ----------------------------------------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
>
>

Re: [httpclient_common]_why httpclient's speed is the same with JDK httpurlconnection

Posted by maomaode <ma...@gmail.com>.
I think the HttpClient essentially use the urlconnection, then i would 
ask why httpclient will faster than urlconnection?
I think the benefit of HttpClient is that it manage the connection, that 
make your code more neat, you can focus on the business logic...
> 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
>
> ----------------------------------------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


Re: JNDI + dbcp + commons-dbcp-1.2.1.jar

Posted by Henri Yandell <fl...@gmail.com>.
At a guess, the Oracle code is trying to cast the connection to
OracleConnection or some such. It's not an OracleConnection as DBCP
wraps that with its own Connection implementation.

Try doing:

adTemp = ArrayDescriptor.createDescriptor("ARR_VARCHAR",
 ((DelegatingConnection)con).getDelegate() );

with an import of:

import org.apache.commons.dbcp.DelegatingConnection;

Hen

On 2/8/07, karthik <ka...@xius.org> wrote:
>
>  Hi
>
>    Currently ,When i wanted to port my application "xyz.war" from  OC4j
> (oracle) to TOMCAT5.5
>    I found some problems regarding JNDI usage in tomcat with Commons DBCP
>
> I have made use of Resource tag as follows
>
> <Resource name="jdbc/tomcattest"
> auth="Container"
> type="javax.sql.DataSource"
> driverClassName="oracle.jdbc.driver.OracleDriver"
> url="jdbc:oracle:thin:@//192.168.150.112:11654/xyz"
> username="voise_20"
> password="voise_20"
> maxActive="100"
> maxIdle="10"
> maxWait="-1"/>
>
>
>    I still get the cast exception as below for Array Discriptor being used
>
>    java.lang.ClassCastException
>         at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:108)
>         at
> com.xius.infinet.ums.UMSBusinessClass.makeNewRolesAdmin(UMSBusinessClass.jav
> a:423)
>
>
>    The Code being used  is as follows
>
> 1>>  con = (DBConnectionManager.getInstance()).getConnection();
> 2>>  htReturnData = new Hashtable();
> 3>>  adTemp = ArrayDescriptor.createDescriptor("ARR_VARCHAR", con);
> 4>>  ar = new ARRAY(adTemp, con, saPrivileges);
> 5>>  OracleCallableStatement cstmt = null;
> 6>>  InfinetUtility.log("UMSBusinessClass.makeNewRolesAdmin " + "{CALL
> UMS_ADMIN.ROLEPROFILE_INSERT(?,?,?,to_number(?),?)}");
> 7>>  cstmt = (OracleCallableStatement) con.prepareCall("{CALL
> UMS_ADMIN.ROLEPROFILE_INSERT(?,?,?,to_number(?),?)}");
> 6>>  cstmt.setString(1, sRoleName);
> 9>>  cstmt.setString(2, sRoleDesc);
> 10>> cstmt.setARRAY(3, ar);
> 11>  cstmt.setString(4, new String("" + iNwId));
> 12>> cstmt.registerOutParameter(5, java.sql.Types.INTEGER);
> 14>  cstmt.execute();
>
>
> The exact nature of problem lies in line number "7" where ever the casting
> happens
>
>
> plz Can somebody explain me why am i getting this error as a result of using
> "commons-dbcp-1.2.1.jar"
>
>
>
> with regards
> Karthik
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>

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


Re: [httpclient_common]_why httpclient's speed is the same with JDK httpurlconnection

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Wed, 2007-02-07 at 18:15 +0000, sebb wrote:
> On 07/02/07, Oleg Kalnichevski <ol...@apache.org> 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.
> 
> [...]
> 
> > 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.
> >
> 
> s/does/does not/ ??
> 
> S///!
> 

Yep. I meant to say 'does NOT reflect'. Excuse my Ruslish.

Oleg


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


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


RE: JNDI + dbcp + commons-dbcp-1.2.1.jar

Posted by karthik <ka...@xius.org>.
Hi

  No Reply for the same


With regards
Karthik

-----Original Message-----
From: karthik [mailto:karthikn@xius.org]
Sent: Monday, February 26, 2007 12:15 PM
To: Jakarta Commons Users List
Subject: JNDI + dbcp + commons-dbcp-1.2.1.jar


Hi

  Sorry for delay in answering.

We already have the configurations done as u said
and that application executes vey well in most of the cases Except wher ever
there is this
piece of code

>>ArrayDescriptor adNumb = ArrayDescriptor.createDescriptor("ARR_NUMB",
con); << Line number 423

Still we get the ClassCast Exceptions at those mentioned palces....

java.lang.ClassCastException
         at
oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:108)
         at

com.xius.infinet.ums.UMSBusinessClass.makeNewRolesAdmin(UMSBusinessClass.jav
 a:423)


Somebody people on the Web mentioned to fetche the inner Delegated
Connection from the wrapped ones
to solve the same, but no refrences were made.


Please  We Only have the Exceutable (war file and no source code avaliable
for the same)

My limitation is limited to JNDI connection changes to be made when running
on Apache Tomcat 5 and above


Please help me


with regards
Karthik



-----Original Message-----
From: Henri Yandell [mailto:flamefew@gmail.com]
Sent: Thursday, February 22, 2007 11:10 PM
To: Jakarta Commons Users List
Subject: Re: JNDI + dbcp + commons-dbcp-1.2.1.jar


Did you try what I suggested?

Hen

On 2/20/07, karthik <ka...@xius.org> wrote:
>
> Hi
>
>  Do any body in here have solutions for this form request
>
>
>
>
> with regards
> Karthik
>
>
> -----Original Message-----
> From: karthik [mailto:karthikn@xius.org]
> Sent: Thursday, February 08, 2007 9:57 PM
> To: Jakarta Commons Users List
> Subject: JNDI + dbcp + commons-dbcp-1.2.1.jar
>
>
>
>  Hi
>
>    Currently ,When i wanted to port my application "xyz.war" from  OC4j
> (oracle) to TOMCAT5.5
>    I found some problems regarding JNDI usage in tomcat with Commons DBCP
>
> I have made use of Resource tag as follows
>
> <Resource name="jdbc/tomcattest"
> auth="Container"
> type="javax.sql.DataSource"
> driverClassName="oracle.jdbc.driver.OracleDriver"
> url="jdbc:oracle:thin:@//192.168.150.112:11654/xyz"
> username="voise_20"
> password="voise_20"
> maxActive="100"
> maxIdle="10"
> maxWait="-1"/>
>
>
>    I still get the cast exception as below for Array Discriptor being used
>
>    java.lang.ClassCastException
>         at
oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:108)
>         at
>
com.xius.infinet.ums.UMSBusinessClass.makeNewRolesAdmin(UMSBusinessClass.jav
> a:423)
>
>
>    The Code being used  is as follows
>
> 1>>  con = (DBConnectionManager.getInstance()).getConnection();
> 2>>  htReturnData = new Hashtable();
> 3>>  adTemp = ArrayDescriptor.createDescriptor("ARR_VARCHAR", con);
> 4>>  ar = new ARRAY(adTemp, con, saPrivileges);
> 5>>  OracleCallableStatement cstmt = null;
> 6>>  InfinetUtility.log("UMSBusinessClass.makeNewRolesAdmin " + "{CALL
> UMS_ADMIN.ROLEPROFILE_INSERT(?,?,?,to_number(?),?)}");
> 7>>  cstmt = (OracleCallableStatement) con.prepareCall("{CALL
> UMS_ADMIN.ROLEPROFILE_INSERT(?,?,?,to_number(?),?)}");
> 6>>  cstmt.setString(1, sRoleName);
> 9>>  cstmt.setString(2, sRoleDesc);
> 10>> cstmt.setARRAY(3, ar);
> 11>  cstmt.setString(4, new String("" + iNwId));
> 12>> cstmt.registerOutParameter(5, java.sql.Types.INTEGER);
> 14>  cstmt.execute();
>
>
> The exact nature of problem lies in line number "7" where ever the casting
> happens
>
>
> plz Can somebody explain me why am i getting this error as a result of
using
> "commons-dbcp-1.2.1.jar"
>
>
>
> with regards
> Karthik
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>

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


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


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


JNDI + dbcp + commons-dbcp-1.2.1.jar

Posted by karthik <ka...@xius.org>.
Hi

  Sorry for delay in answering.

We already have the configurations done as u said
and that application executes vey well in most of the cases Except wher ever
there is this
piece of code

>>ArrayDescriptor adNumb = ArrayDescriptor.createDescriptor("ARR_NUMB",
con); << Line number 423

Still we get the ClassCast Exceptions at those mentioned palces....

java.lang.ClassCastException
         at
oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:108)
         at

com.xius.infinet.ums.UMSBusinessClass.makeNewRolesAdmin(UMSBusinessClass.jav
 a:423)


Somebody people on the Web mentioned to fetche the inner Delegated
Connection from the wrapped ones
to solve the same, but no refrences were made.


Please  We Only have the Exceutable (war file and no source code avaliable
for the same)

My limitation is limited to JNDI connection changes to be made when running
on Apache Tomcat 5 and above


Please help me


with regards
Karthik



-----Original Message-----
From: Henri Yandell [mailto:flamefew@gmail.com]
Sent: Thursday, February 22, 2007 11:10 PM
To: Jakarta Commons Users List
Subject: Re: JNDI + dbcp + commons-dbcp-1.2.1.jar


Did you try what I suggested?

Hen

On 2/20/07, karthik <ka...@xius.org> wrote:
>
> Hi
>
>  Do any body in here have solutions for this form request
>
>
>
>
> with regards
> Karthik
>
>
> -----Original Message-----
> From: karthik [mailto:karthikn@xius.org]
> Sent: Thursday, February 08, 2007 9:57 PM
> To: Jakarta Commons Users List
> Subject: JNDI + dbcp + commons-dbcp-1.2.1.jar
>
>
>
>  Hi
>
>    Currently ,When i wanted to port my application "xyz.war" from  OC4j
> (oracle) to TOMCAT5.5
>    I found some problems regarding JNDI usage in tomcat with Commons DBCP
>
> I have made use of Resource tag as follows
>
> <Resource name="jdbc/tomcattest"
> auth="Container"
> type="javax.sql.DataSource"
> driverClassName="oracle.jdbc.driver.OracleDriver"
> url="jdbc:oracle:thin:@//192.168.150.112:11654/xyz"
> username="voise_20"
> password="voise_20"
> maxActive="100"
> maxIdle="10"
> maxWait="-1"/>
>
>
>    I still get the cast exception as below for Array Discriptor being used
>
>    java.lang.ClassCastException
>         at
oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:108)
>         at
>
com.xius.infinet.ums.UMSBusinessClass.makeNewRolesAdmin(UMSBusinessClass.jav
> a:423)
>
>
>    The Code being used  is as follows
>
> 1>>  con = (DBConnectionManager.getInstance()).getConnection();
> 2>>  htReturnData = new Hashtable();
> 3>>  adTemp = ArrayDescriptor.createDescriptor("ARR_VARCHAR", con);
> 4>>  ar = new ARRAY(adTemp, con, saPrivileges);
> 5>>  OracleCallableStatement cstmt = null;
> 6>>  InfinetUtility.log("UMSBusinessClass.makeNewRolesAdmin " + "{CALL
> UMS_ADMIN.ROLEPROFILE_INSERT(?,?,?,to_number(?),?)}");
> 7>>  cstmt = (OracleCallableStatement) con.prepareCall("{CALL
> UMS_ADMIN.ROLEPROFILE_INSERT(?,?,?,to_number(?),?)}");
> 6>>  cstmt.setString(1, sRoleName);
> 9>>  cstmt.setString(2, sRoleDesc);
> 10>> cstmt.setARRAY(3, ar);
> 11>  cstmt.setString(4, new String("" + iNwId));
> 12>> cstmt.registerOutParameter(5, java.sql.Types.INTEGER);
> 14>  cstmt.execute();
>
>
> The exact nature of problem lies in line number "7" where ever the casting
> happens
>
>
> plz Can somebody explain me why am i getting this error as a result of
using
> "commons-dbcp-1.2.1.jar"
>
>
>
> with regards
> Karthik
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>

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


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


Re: JNDI + dbcp + commons-dbcp-1.2.1.jar

Posted by Henri Yandell <fl...@gmail.com>.
Did you try what I suggested?

Hen

On 2/20/07, karthik <ka...@xius.org> wrote:
>
> Hi
>
>  Do any body in here have solutions for this form request
>
>
>
>
> with regards
> Karthik
>
>
> -----Original Message-----
> From: karthik [mailto:karthikn@xius.org]
> Sent: Thursday, February 08, 2007 9:57 PM
> To: Jakarta Commons Users List
> Subject: JNDI + dbcp + commons-dbcp-1.2.1.jar
>
>
>
>  Hi
>
>    Currently ,When i wanted to port my application "xyz.war" from  OC4j
> (oracle) to TOMCAT5.5
>    I found some problems regarding JNDI usage in tomcat with Commons DBCP
>
> I have made use of Resource tag as follows
>
> <Resource name="jdbc/tomcattest"
> auth="Container"
> type="javax.sql.DataSource"
> driverClassName="oracle.jdbc.driver.OracleDriver"
> url="jdbc:oracle:thin:@//192.168.150.112:11654/xyz"
> username="voise_20"
> password="voise_20"
> maxActive="100"
> maxIdle="10"
> maxWait="-1"/>
>
>
>    I still get the cast exception as below for Array Discriptor being used
>
>    java.lang.ClassCastException
>         at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:108)
>         at
> com.xius.infinet.ums.UMSBusinessClass.makeNewRolesAdmin(UMSBusinessClass.jav
> a:423)
>
>
>    The Code being used  is as follows
>
> 1>>  con = (DBConnectionManager.getInstance()).getConnection();
> 2>>  htReturnData = new Hashtable();
> 3>>  adTemp = ArrayDescriptor.createDescriptor("ARR_VARCHAR", con);
> 4>>  ar = new ARRAY(adTemp, con, saPrivileges);
> 5>>  OracleCallableStatement cstmt = null;
> 6>>  InfinetUtility.log("UMSBusinessClass.makeNewRolesAdmin " + "{CALL
> UMS_ADMIN.ROLEPROFILE_INSERT(?,?,?,to_number(?),?)}");
> 7>>  cstmt = (OracleCallableStatement) con.prepareCall("{CALL
> UMS_ADMIN.ROLEPROFILE_INSERT(?,?,?,to_number(?),?)}");
> 6>>  cstmt.setString(1, sRoleName);
> 9>>  cstmt.setString(2, sRoleDesc);
> 10>> cstmt.setARRAY(3, ar);
> 11>  cstmt.setString(4, new String("" + iNwId));
> 12>> cstmt.registerOutParameter(5, java.sql.Types.INTEGER);
> 14>  cstmt.execute();
>
>
> The exact nature of problem lies in line number "7" where ever the casting
> happens
>
>
> plz Can somebody explain me why am i getting this error as a result of using
> "commons-dbcp-1.2.1.jar"
>
>
>
> with regards
> Karthik
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>

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


RE: JNDI + dbcp + commons-dbcp-1.2.1.jar

Posted by karthik <ka...@xius.org>.
Hi

 Do any body in here have solutions for this form request




with regards
Karthik


-----Original Message-----
From: karthik [mailto:karthikn@xius.org]
Sent: Thursday, February 08, 2007 9:57 PM
To: Jakarta Commons Users List
Subject: JNDI + dbcp + commons-dbcp-1.2.1.jar



 Hi

   Currently ,When i wanted to port my application "xyz.war" from  OC4j
(oracle) to TOMCAT5.5
   I found some problems regarding JNDI usage in tomcat with Commons DBCP

I have made use of Resource tag as follows

<Resource name="jdbc/tomcattest"
auth="Container"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@//192.168.150.112:11654/xyz"
username="voise_20"
password="voise_20"
maxActive="100"
maxIdle="10"
maxWait="-1"/>


   I still get the cast exception as below for Array Discriptor being used

   java.lang.ClassCastException
	at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:108)
	at
com.xius.infinet.ums.UMSBusinessClass.makeNewRolesAdmin(UMSBusinessClass.jav
a:423)


   The Code being used  is as follows

1>>  con = (DBConnectionManager.getInstance()).getConnection();
2>>  htReturnData = new Hashtable();
3>>  adTemp = ArrayDescriptor.createDescriptor("ARR_VARCHAR", con);
4>>  ar = new ARRAY(adTemp, con, saPrivileges);
5>>  OracleCallableStatement cstmt = null;
6>>  InfinetUtility.log("UMSBusinessClass.makeNewRolesAdmin " + "{CALL
UMS_ADMIN.ROLEPROFILE_INSERT(?,?,?,to_number(?),?)}");
7>>  cstmt = (OracleCallableStatement) con.prepareCall("{CALL
UMS_ADMIN.ROLEPROFILE_INSERT(?,?,?,to_number(?),?)}");
6>>  cstmt.setString(1, sRoleName);
9>>  cstmt.setString(2, sRoleDesc);
10>> cstmt.setARRAY(3, ar);
11>  cstmt.setString(4, new String("" + iNwId));
12>> cstmt.registerOutParameter(5, java.sql.Types.INTEGER);
14>  cstmt.execute();


The exact nature of problem lies in line number "7" where ever the casting
happens


plz Can somebody explain me why am i getting this error as a result of using
"commons-dbcp-1.2.1.jar"



with regards
Karthik





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


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


JNDI + dbcp + commons-dbcp-1.2.1.jar

Posted by karthik <ka...@xius.org>.
 Hi

   Currently ,When i wanted to port my application "xyz.war" from  OC4j
(oracle) to TOMCAT5.5
   I found some problems regarding JNDI usage in tomcat with Commons DBCP

I have made use of Resource tag as follows

<Resource name="jdbc/tomcattest"
auth="Container"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@//192.168.150.112:11654/xyz"
username="voise_20"
password="voise_20"
maxActive="100"
maxIdle="10"
maxWait="-1"/>


   I still get the cast exception as below for Array Discriptor being used

   java.lang.ClassCastException
	at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:108)
	at
com.xius.infinet.ums.UMSBusinessClass.makeNewRolesAdmin(UMSBusinessClass.jav
a:423)


   The Code being used  is as follows

1>>  con = (DBConnectionManager.getInstance()).getConnection();
2>>  htReturnData = new Hashtable();
3>>  adTemp = ArrayDescriptor.createDescriptor("ARR_VARCHAR", con);
4>>  ar = new ARRAY(adTemp, con, saPrivileges);
5>>  OracleCallableStatement cstmt = null;
6>>  InfinetUtility.log("UMSBusinessClass.makeNewRolesAdmin " + "{CALL
UMS_ADMIN.ROLEPROFILE_INSERT(?,?,?,to_number(?),?)}");
7>>  cstmt = (OracleCallableStatement) con.prepareCall("{CALL
UMS_ADMIN.ROLEPROFILE_INSERT(?,?,?,to_number(?),?)}");
6>>  cstmt.setString(1, sRoleName);
9>>  cstmt.setString(2, sRoleDesc);
10>> cstmt.setARRAY(3, ar);
11>  cstmt.setString(4, new String("" + iNwId));
12>> cstmt.registerOutParameter(5, java.sql.Types.INTEGER);
14>  cstmt.execute();


The exact nature of problem lies in line number "7" where ever the casting
happens


plz Can somebody explain me why am i getting this error as a result of using
"commons-dbcp-1.2.1.jar"



with regards
Karthik





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


Re: [httpclient_common]_why httpclient's speed is the same with JDK httpurlconnection

Posted by sebb <se...@gmail.com>.
On 07/02/07, Oleg Kalnichevski <ol...@apache.org> 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.

[...]

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

s/does/does not/ ??

S///!

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


Re: [httpclient_common]_why httpclient's speed is the same with JDK httpurlconnection

Posted by Oleg Kalnichevski <ol...@apache.org>.
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 <ol...@apache.org> 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: commons-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> >
> >


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


Re: [httpclient_common]_why httpclient's speed is the same with JDK httpurlconnection

Posted by allen huang <co...@gmail.com>.
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-.

On 2/7/07, Oleg Kalnichevski <ol...@apache.org> 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: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>

Re: [httpclient_common]_why httpclient's speed is the same with JDK httpurlconnection

Posted by Oleg Kalnichevski <ol...@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).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: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org