tags:

views:

65

answers:

3

I have been developing a web application for almost a year which I had started in college. After finishing, I made some changes to the database code that I had written during college. I used simple JDBC when I was in college, without the use of connection pooling and prepared statements. In the past month, I have realized the potential, and need to use connection pooling, and prepared statements because of the increase in data being queried and used.

I have implemented the connection pooling, but have not really noticed an increase in performance. If there was an increase in performance, then my question would be answered, but how can I validate that connection pooling and prepared statements are being used properly?

+4  A: 

I think prepared statement is more important from a security than a performance standpoint. If you are using them cool, you really should be. As long as 100% of your SQL is a prepared statement, you are "using them right"...

Connection pooling is something you won't notice under light load. 1 or 2 or 10 users, you will likely see 0 or near 0 difference. You would need to create some kind of load testing test to simulate 100s of simultaneous users, then compare performance with and without pooling.

bwawok
Noted should be that using `PreparedStatement` certainly gives a performance advantage since they are prepared, compiled and cached once in DB and reused forever. However, like as with connection pooling, the performance difference is completely negligible if you're the only one who is using the webapp :)
BalusC
@BalusC That depends on the DB and on the DB driver. Some won't compile them at all, some will after the same PreparedStatement instance has been used X number of times. Some will even make more roundtrips to the DB, 1 packet for the SQL, one for sending the actual parameters.
nos
@nos Which DB's might those be? Of course I don't mean a comprehensive list, but I've dealt with most of the "big" db's, and I include even HSQLDB in that, and all of them are significantly faster with prepared statements.TIA
mezmo
@nos: Yes, it depends on the DB. In practice, fortunately, there are a lot of decent DB's.
BalusC
+1  A: 

You won't see a performance improvement if opening and closing connections wasn't rate-limiting. Try looking at your database's profiling tools for a list of open connections. If you see open connections from your process when you have ostensibly closed them, the interface layer is doing connection pooling.

See also this other SO question on forcing a pooled connection to drop.

(Caveat:I use ADO and ADO.NET; JDBC might behave differently.)

Robert Calhoun
+1  A: 

You ask the connection pool for statistics to see if it works. If the connection pool library does not provide statistics, find a better library.

Thorbjørn Ravn Andersen