Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pooling in tomcat

Status
Not open for further replies.

dendenners

Programmer
Jul 17, 2001
110
0
0
IE
Can you get tomcat to open a pool of connections to a database at startup, and if so, where do I start? I'm pretty new to tomcat but I've been using weblogic for a while. Incidentally, would anyone care to give a brief list of the disadvantages/limitations of using tomcat vs. a commercial server like weblogic?
Thanks in advance
DMC
 
WebLogic is also overkill and entirely too expensive for just Servlets/JSP, even the Express Edition. I develop for WebLogic on a daily basis but I would never recommend someone to go with such an expensive solution when there are so many free or cheap solutions out there to do the same. Resin or Tomcat is more than adequate for simple Servlets and JSP.

If you are doing serious EJB development and need the ultra feature rich clustering that WebLogic offers (as my current project does) than it is a no brainer. Go with either WebLogic or WebSphere. If on the otherhand you are doing simple EJB solutions there are other less expensive App Servers available and as long as you don't use its custom extensions you shouldn't need to worry about vendor lockin.

It sounds like you are just doing plain Servlet/JSP stuff, stick with Tomcat or Resin... unless you prefer to pay the 10K per CPU license for WebLogic.
 
I agree with wushutwist. Tomcat will be adequate for most all but for those projects that have tons of money to spend, then you should really use the expensive stuff.
Ha ;-) Actually if EJB full feature set was necessary, I would be investigating the open source jBoss implementation closely.

But for connection pooling I looked on the jakarta.apache.org web-site. I don't have any experience with it but look at the subproject "Commons". In the components section-- at the "DBCP" and "Pool" components. These probably are what you are looking for.

I expect these reusable components to be more generic solutions and not specifically designed for servlet/jsp use. In which case you would need to create your own ServletContext (application) level attribute that uses these pooling components and in turn implements the ServletContext lifecycle event interfaces. Download Servlet 2.3 API and read up on these. You would be implementing javax.servlet.ServletContextListener interface.

Also, you might want to look under jakarta subproject "Taglib". There is a DBTag tag library there. However, at a glance, I didn't see anything about pooling there. It looks like they are opening a new connection for each request.

For an Oracle database senario, I will step out on limb here: it is my understanding that Oracle connections are multi-threaded. So, if JDBC to Oracle is multi-threaded, i.e. thread-safe, then you can have multiple threads using the same connection object. And service() doGet() doPost() are processing a request on a per thread basis then maybe you can just create one connection object that is used across many requests. I am not sure you need connection pooling for Oracle connections. Please test and read further on this.

pfist
 
Was looking at the J2SE 1.4 datasheet for a different reason and came across new connection pooling functionality. See JDBC excerpt below. This assumes you can use 1.4 version.

pfist
---------------------------------------------------------------

JDBC 3.0 technology enables universal data access from virtually any source -
relational databases, spreadsheets, and flat files. Version 1.4 consolidates the separate core and optional JDBC packages into a single offering, and provides enhancements such as Connection Pool configuration improvements, Statement pooling for Pooled Connections, and a description of the migration path from the
JDBC SPI (Service Provider Interface) to the J2EETM Connector Architecture.
 
Unfortunately there are no major JDBC Drivers that support JDBC 3.0 yet. Give it a year and it will be useful.
 
I am new to Tomcat and am confused as to how to setup a DataSource that could be looked up via JNDI at all!
I have under my server.xml
Code:
      <Realm  className=&quot;org.apache.catalina.realm.JDBCRealm&quot; debug=&quot;99&quot;
             driverName=&quot;sun.jdbc.odbc.JdbcOdbcDriver&quot;
          connectionURL=&quot;jdbc:odbc:testDB&quot;
              userTable=&quot;users&quot; userNameCol=&quot;Admin&quot; userCredCol=&quot;&quot;
          userRoleTable=&quot;&quot; roleNameCol=&quot;&quot; />

          <Resource name=&quot;jdbc/testDb&quot; auth=&quot;Container&quot;
                    type=&quot;javax.sql.DataSource&quot;/>
          <ResourceParams name=&quot;jdbc/testDb&quot;>
            <parameter><name>user</name><value>Admin</value></parameter>
            <parameter><name>password</name><value></value></parameter>
            <parameter><name>driverClassName</name>
              <value>org.hsql.jdbcDriver</value></parameter>
            <parameter><name>driverName</name>
              <value>sun.jdbc.odbc.JdbcOdbcDriver:testDb</value></parameter>
          </ResourceParams>

Also, running on NT 4 Workstation, I have an ODBC connection with system DSN Named testDb which connects to an access DB.

When I try to execute
Code:
    InitialContext ic = new InitialContext();
    DataSource theDataSource = (DataSource)ic.lookup(&quot;jdbc/testDb&quot;);

I encountered javax.naming.NameNotFoundException: Name jdbc is not bound in this Context

Any help would be appreciated.
 
your lookup should be for
&quot;java/env/jdbc/testDb&quot;
 
being new to java and tomcat i am finding all this very confusing :(

i know i want connection pooling to a mysql DB but i haven't got a clue where to start. does tomcat have it's own basic DB pooling?
from the basic point of view, i have mysql, j2sdk, tomcat4 and a mysql JDBC driver installed - what else do i need to download to get pooling working or do i already have the tools? maybe this seems a dumb question but i've read the descriptions of a number of tools but they are all in java buzzwords and make no sense to me.

links or book recommendations would be great.
 
I had the same problem:
Name jdbc is not bound in this Context

Solved it by creating an application context in server.xml and made sure the resource were nexted in that context. Is there a way to declare a global (available to all app contexts)?
 
Also, try this as the DataSource:
java:comp/env/jdbc/testDb

What's strange is that for WebSphere, the following works:
jdbc/testDb

 
probably u need to set the jndi logical name
in web.xml file. the code u need to set in that is below

<resource-ref>
<description> your own description.
</description>
<res-ref-name>jdbc/testDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth> Container</res-auth>
</resource-ref>

this web.xml file is under web-inf/web.xml but not
conf/web.xml. take care .

let me know what happend later.

 
I am currently having the same naming problem as mentioned in previous posts, but I've tried all other fixes posted.

In server.xml :
<Context className=&quot;org.apache.catalina.core.StandardContext&quot; cachingAllowed=&quot;true&quot; charsetMapperClass=&quot;org.apache.catalina.util.CharsetMapper&quot; cookies=&quot;true&quot; crossContext=&quot;false&quot; debug=&quot;0&quot; docBase=&quot;C:\jakarta-tomcat\webapps\addedtime&quot; mapperClass=&quot;org.apache.catalina.core.StandardContextMapper&quot; path=&quot;/addedtime&quot; privileged=&quot;false&quot; reloadable=&quot;true&quot; swallowOutput=&quot;false&quot; useNaming=&quot;true&quot; wrapperClass=&quot;org.apache.catalina.core.StandardWrapper&quot;>

<Resource name=&quot;jdbc/addedtime&quot; auth=&quot;Container&quot; scope=&quot;Shareable&quot; type=&quot;javax.sql.DataSource&quot;/>

In web.xml(addedtime/WEB-INF/web.xml):
<resource-ref>
<description>dbConnection</description>
<res-ref-name>jdbc/addedtime</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>


In my class file I have:
Context ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup(&quot;java/env/jdbc/addedtime&quot;);

I ran through it and it gets the initial context fine...but my error log has:

javax.naming.NameNotFoundException: Name java is not bound in this Context
 
Hello All,
I just spent the past two weeks playing around with tomcat's connection pool, and I'm not very impressed. I'm in the process of porting a webapp to WebSphere and using tomcat to test with. Apparently Tomcat and websphere use the same mechanism for connection pooling (DataSource with jndi lookup, perhaps weblogic does this as well). After following the (poor) documentation and finally setting up a few beans which do the jndi lookup/SQL and referring to those beans inside jsp's, I got the implementation working. Using one browser, the implementation worked fine, however when I tried to benchmark the solution using httperf, I quickly realized how poor this implementation truly is. The problem seemed to occur in the jndi lookup. Apparently tomcat would start a new background thread for every call that came in, if all other threads serving jsp in question were busy. I can only assume that it was taking entirely too long to do the jndi lookup, acquire a connection and execute the corresponding sql statement. Tomcat was running on a p4 2ghz with 1.5 gig of ram. Overall the benchmark did not allow more than 10 get requests per second to be executed without more background threads being started up. This meant in effect that if we had a buildup of more than 10 req/sec for more than a few minutes, tomcat would lock. Prior to using the jndi solution, our team was using a modified version of DDConnectionBroker at opensource.devdaily.com. The main problem with this connection broker was that it did not allow the extra unused connections to be returned to the sql server. We took a day and fixed this and now after experiencing both solutions, I'm very glad we can still fall back. Our database machine isn't a behemoth (ultra 5 w/128mb running postgresql), but with 35 processes opened, we were able to serve about 32 connections a second with no errors whatsoever. Given this drastic increase in performance, I can only assume that the db server is not the bottleneck in the jndi solution. I won't say that I'm 100% sure we didn't have an error in our use of the jndi solution, but over a week and a half with more than one programmer working the issue, we couldn't find an adequate solution. Any comments?
 
No comments, but a couple of questions, perhaps.

I'm not that familiar with DDConnectionBroker - I took a quick look, and didn't really see any J2EE implementation examples, just an application. Not sure how relevant that would be for something of this type. I'd be curious as to how the pooling is being handled internally, given that it appears to require that you have a broker object available in scope somewhere for it to work. Where do you store the broker object between requests?

But could you clarify on a few things? Are you stating that when using the DDConnectionBroker with Tomcat you can go for more than 10 req/sec with no lockup? If so, what is your maximum with that particular implementation? What are your Tomcat settings, or are you using the defaults? What are your settings in the pool configuration? What are the actual metrics on the thread counts, and how are they being determined? Tool(such as JProbe), verbose console logging, or assumption?

Just a thought. If you check out the Websphere peformance tuning guidelines(since that is the deployment target), you will find that they recommend avoiding frequent JNDI calls if possible, since they tend to be expensive. They have methods of caching these references, but they are proprietary in nature and require some extra programming. It is generally customary to get a datasource once, and then reuse it since it is threadsafe - that eliminates the expense. That principle carries over for most JNDI based lookup mechanisms for datasources, I believe. Not sure if you are using some Model 2 implementation such as Struts or whether you are going with straight jsp's, so it's hard for me to push a particular strategy.

Just curious - have you posted to the Tomcat User list about this?
 
I think the problem is that a java class file is not completely a part of the webapp, so it does not see the connection pooling. Try using a servlet instead and see what happens
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top