You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Prabhakar, Achal" <AP...@Central.UH.EDU> on 2003/05/21 01:18:22 UTC

RE: DBCP Connection Pool is slower than setting up direct connec t ion to mySql

You can try this:
Do the lookup and datasource creation in a servlet that is loaded at
startup. Put a reference to the DataSource in the ServletContext using
setAttribute and use that from any place within the same context.

-Achal


-----Original Message-----
From: Richie Chauhan [mailto:richie@ajava.biz]
Sent: Tuesday, May 20, 2003 5:45 PM
To: 'Tomcat Users List'
Subject: RE: DBCP Connection Pool is slower than setting up direct
connect ion to mySql


Thanks Achal, Micael

I guess I need to figure out how to do the lookup in a servlet and pass
that information to the tag. I do need to connect to the same database
in several different places apart from that particular tag. But the tag
was the first place I thought of to see if I could get any performance
gains.

And I would very much appreciate seeing what you have in mind Micael.

Thanks Again. 

Richie

-----Original Message-----
From: Micael [mailto:caraunltd@harbornet.com] 
Sent: Tuesday, May 20, 2003 1:05 PM
To: Tomcat Users List
Subject: RE: DBCP Connection Pool is slower than setting up direct
connect ion to mySql

Why not do the initialization on startup with a servlet, if you want to
do 
that.  But, why would you want JNDI information restricted to a tag?
Why 
would you want to do lazy initialization of JNDI configuration?

At 03:49 PM 5/20/03 -0500, you wrote:
>If it were a servlet, I would put the lookup and datasource creation
code in
>the servlet init method and retain this reference for the life of the
>servlet. And put the clean up code in destroy method.
>
>Now this being custom tags, I am not sure if one can use the same
approach.
>-Achal
>
>
>
>-----Original Message-----
>From: Richie Chauhan [mailto:richie@ajava.biz]
>Sent: Tuesday, May 20, 2003 1:18 PM
>To: 'Tomcat Users List'
>Subject: RE: DBCP Connection Pool is slower than setting up direct
>connect ion to mySql
>
>
>Any Suggestions as to how to go about doing the JNDI lookup and
>DataSource connection elsewhere.
>
>Thanks
>
>Richie
>
>-----Original Message-----
>From: Prabhakar, Achal [mailto:APrabhakar@Central.UH.EDU]
>Sent: Tuesday, May 20, 2003 8:09 AM
>To: 'Tomcat Users List'
>Subject: RE: DBCP Connection Pool is slower than setting up direct
>connect ion to mySql
>
>Doing JNDI lookup and DataSource creation in the doStartTag may not be
a
>good idea. How about doing these two steps in some other place and just
>creating a connection in doStartTag??
>
>-Achal
>
>
>
>-----Original Message-----
>From: Richie Chauhan [mailto:richie@ajava.biz]
>Sent: Tuesday, May 20, 2003 10:50 AM
>To: Tomcat
>Subject: DBCP Connection Pool is slower than setting up direct
>connection to mySql
>
>
>Hello all,
>Sorry I am putting this up again. Still have had no luck in solving my
>problem.
>
>I have a custom tag in which I open the connection in the doStartTag()
>method and close the recordset etc in the doEndTag(). The code is at
the
>end of the email.
>
>I know the connections are being pooled as I start mysql with logging.
>When I use the code below, the logs clearly show that a new connection
>is being made every time I access the page. However when I use the new
>version with the connection pooling specific stuff, the connections are
>made at first as necessary, and then reused for subsequent page hits(No
>new CONNECT log entries).
>
>The database and queries I used are identical, as I am running tomcat
>with 2 virtual hosts, dev and stage(dev is the new one and stage has
the
>old code). The database both of them access is the same.
>
>I read somewhere that the jndi lookup may actually be slower than the
>mm.mysql driver creating a connection (The connection setup/teardown
may
>not be that expensive in this case as the database is on the same
>dedicated network). But I am extremely skeptical of this thought, and I
>only came across that idea once, and it obviously flies in the face of
>everything else out there (I have a problem with long run on
sentences).
>
>Any thoughts???
>
>Thanks
>
>Richie
>
>Here's the code ......
>
>    public int doStartTag() throws JspException
>    {
>       StringBuffer sql = new StringBuffer();
>         String path = "jdbc:mysql://jupiter/ajavaDB";
>
>...build sql string
>
>       try
>       {
>         //******THIS STUFF BELOW I REPLACE WITH THE CONNECTION POOL
CODE
>       //   Class.forName("org.gjt.mm.mysql.Driver");
>       //   con = DriverManager.getConnection(path, "....", "....");
>
>          Context ctx = new InitialContext();
>          if(ctx != null)
>          {
>          DataSource ds =
>(DataSource)ctx.lookup("java:comp/env/jdbc/ajavaDB");
>                 if(ds != null)
>             {
>                 con = ds.getConnection();
>                 if(con != null)
>                 {
>                         stmt = con.createStatement();
>                         rs = stmt.executeQuery(sql.toString());
>                         setVariables();
>                 }//end if con
>             }//end if ds
>             }//end if ctx
>
>       } catch (SQLException e)
>       {
>          throw new JspTagException("An SQLException occurred!");
>       } catch (ClassNotFoundException e)
>       {
>          throw new JspTagException("JDBC Driver not found.");
>       }
>       return EVAL_BODY_TAG;
>    }
>
>
>    public int doEndTag() throws JspException
>    {
>       try
>       {
>          if(rs != null)
>          {
>             rs.close();
>             rs = null;
>          }
>          if(stmt != null)
>          {
>             stmt.close();
>             stmt = null;
>          }
>          if(con != null)
>          {
>             con.close();
>             con = null;
>          }
>       } catch (SQLException e)
>       {}
>
>       return EVAL_PAGE;
>    }
>
>Richie Chauhan
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org



LEGAL NOTICE

This electronic mail  transmission and any accompanying documents
contain 
information belonging to the sender which may be confidential and
legally 
privileged.  This information is intended only for the use of the 
individual or entity to whom this electronic mail transmission was sent
as 
indicated above. If you are not the intended recipient, any disclosure, 
copying, distribution, or action taken in reliance on the contents of
the 
information contained in this transmission is strictly prohibited.  If
you 
have received this transmission in error, please delete the message.
Thank 
you  



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



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

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