You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Tim Funk <fu...@joedog.org> on 2003/05/26 14:44:53 UTC

Re: DB pooling and architecture and performance

(Sorry of the below is unclear - I wrote this in a minute on my way on an 
appointment)

  DBCP is a database pooling library. It by iteslf will hold all your 
database connections. Then when your servlet is run, the servlet will use 
JNDI to obtain a reference to the datasource (which is implemented by one hte 
dbcp classes). Then from the datasource - your get your Connection. Then when 
your are done with the connection - you close it. Closing it does not really 
close the connection. It actually returns it back to the database pool since 
you are not looking directly at the database connection but a facade.

JNDI lookups are cheap. It will be near the quickness of a hashtable lookup. 
So while obtaining a connectino feels like a lot of code overhead - it is ver 
fast.

In your scenario - you cannot scale since each servlet has its own 
connection. So at most best a servlet can only server one request at a time. 
But with the above scenario, you server serve the number of db connections 
available at a time.

 From a probability point of view - not all the servlets are serving a 
request at the same time. Most likely the same servlet is serving multiple 
requests at the same time. For more info on dbcp with tomcat:

http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html


-Tim

Munteanu Gabriel wrote:
> I want to reuse DB Connections in my web-application.
> I used dbcp with datasource, I did the configuration, and also I run some
> test servlets. All is ok.
> I have put in all my servlets init() method the code to get a Connection
> from the dbcp datasource.
> 
> Aagin all ok, but I am thinking that I do not reuse anything.
> Once the servlets are running, the method init() is never called, so if I
> have 100 DB Connections
> for my 100 servlets.
> 
> If I would have created the connections in the classic way with
> DriverManager and the rest, and put this code
> in the init() method of all me servlets, I think the performance woub be the
> same at runtime. (the service method would
> have a Connection object either way).
> 
> Now, I am thinking that I must put my datasource getConnection() in the
> service() method and at the end of
> the method retrunConnection(). And this way [ONLY WAY?] I would reuse the
> Connections, because if there is
> a demand simultaneous of 15 pages with DB connections, I could get 15
> Connections from the pool, and give them back after I use them.
> 
> I am waiting for comments.
> any URL where DB-pooling is explained in VERY profound way?
> 
> Gabi
> 
> 
> ---------------------------------------------------------------------
> 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