This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

is jdbc connection deadly for application servers ?

 
heiner weilandt
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i have developed some web applications with directly jdbc-connections. i know that connection pooling is much faster and better, but can the jdbc-connections bring the application server to dead ? the page vies per days is 60 (quiet low) !
(performance and on shutdown to an unsecure standing)
some of my colleges say, that is deadly, but is this true ?
the server can be hang up by simple jdbc-connections on the same or another db-server ?
please help me to answer this question
heiner

[ December 19, 2002: Message edited by: heiner weilandt ]
 
Lorus Ghut
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a somewhat simular simular question.
I am devloping a "small" web application, based on jsp, servlets, and a mySql database and my concerns is how to implement this application so that it will handle multiple users with good performance. My page is requested at about 3000 times a day, will I need to use a connection pool?, I develop a thread safe application i.e all users(incomming requests) will instantiate their own controller classes which connect to the database.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(keep in mind that I'm making these numbers up as I go)
No, it isn't essential to implement Connection Pooling, you can get away without it.
BUT...
Each response will be slower.
Every time you need to hit the database you create a connection. In the case of a very small query like "select password from user_table where username=?", the query takes the smallest fraction of a second to return, but it will take you orders of magnitude (.1 to .5 of a second?) to create the Connection.
If you have 1000 database hits, the database and application serevr both spend 1000 times this sitting around.
If your site is only getting 60 hits a day, you won't notice except that the pages might take .2 second longer to return, or as much as 1 second if it has 5 database hits.
The other side is that you never design a site so that it only works if no-one visits. It isn't that great an issue to manage Connections via a pool, and it's worth it just for the sake of having one less performance issue to worry about.
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I totally disagree. I think it's nearly criminal to use connections without a pool. The reason is that programmers make mistakes. If you forget to put even ONE connection.close() statement in your code without pooling you have a mega memory leak (each connection is about 1MB, BTW). With a pooling implementation even if you forget to close the connection, it will be reaped by the pool when a timeout expires.
Kyle
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep, I was assuming the JDBC code was correct.
But if programmers make mistakes, they can forget to return Connections to the pool. Idealy the Pool should timeout connections and recreate them, but you'd still be assuming the pool manages this correctly.
In the case where the difference between pool or no pool is only Connection re-use, ignoring other effects like programmer error, there is little immediate benefit when very few hits are made any way.
(I agree that you always use Connection Pooling where possible, just playing Devils Advocate)
I suppose another benefit to Connection Pooling is the ability to limit the limit the load on the database. This is another effect you won't encounter if you are getting 60 hits a day. :roll:
Connection Pools can grow and shrink depending on demand, so that you have spare Connections available, but you don't hold onto too many such that it becomes a resource hog. You can also set up an upper limit so that it doesn't just keep creating Connections until the whole system chokes.
Connections are database resources, not Java resources, so it makes sense to have some sort of wrapper on them to make sure they are managed in a responsible way.
It's too early in the morning. I'm rambling.
Therefore: Connection Pools are a good thing. Not using them might not kill you, but you'll never know until too late.
 
Manjunath Subramanian
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"each connection is about 1MB, BTW"
Just curious Kyle, How did you arrive upon that?
Thanks,
Manjunath
 
Ken Shamrock
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems that other language like asp doesn't make use of connection pool (I donno) ? If this is the case, Servlet is far more complex then other languages. ie, need to concern more things
 
Asher Tarnopolski
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
come on guys, of corse you can live without the connection pooling. there are some guys out there on Vespas. you can join them or you can drive in a brand new porsche. it's just a matter of choice.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by David O'Meara:
The other side is that you never design a site so that it only works if no-one visits. It isn't that great an issue to manage Connections via a pool, and it's worth it just for the sake of having one less performance issue to worry about.
 
DC Dalton
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have found that Connection Pooling, although very server friendly is NOT mandatory. Case in point...I webmaster one site on a hosting company that doesnt allow pooling (they really havent a clue) so we have to use standard connections.... the site receives approximately 2000 visitors a day & 1/2 of the site requires a connection on every servlet. On an average I would have to say each visitor creates 10 or so connections during their visit to the site.... Now I am NOT saying this is the right way to go, far from it. We are stuck with a moron hosting company that, although they offer servlets, still thinks Java is a good cup of coffee. What Im saying is that in a pinch a good Linux box / MySQL setup can withstand a lot more connections than you might think. The one absolutely VITAL thing in this situation is making sure all of your objects are closed (ResultSets, Statements & Connections!
 
Bruce Jin
Ranch Hand
Posts: 672
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don�t think JDBC is deadly. I have used it for 3 years (for local and remote database access) and never saw it brought down anything. (my win2000 crashed numerous time during this period for no reason). On the other hand any code can kill the server if not code properly.
Connection pool is very easy to code. For example, see Marty Hall�s book or web-site to download one.
I think one can do without connection pool. Make sure the connection is always close (put in finally {} for example). Each connection will cost a fraction of a second.
Sometimes connection may not be very practical to code. For example, the database may require a user ID to connect to the database. In this case the connection is user specific.
Regards.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic