views:

199

answers:

4

I have been trying to use spring 3.0 SimpleJdbcTemplate and it takes 5 mins to insert 1500 records, whereas it take me a few secs. to insert using straight JDBC. Not sure what I am doing wrong.

A: 

do batch insert

+1  A: 

Are you caching connections or are you reconnecting to the database everytime?

In general we have seen almost no difference when calling JDBC via Spring and in some cases we have seen speedup. Your results do seem strange

Fortyrunner
+1  A: 

If you are building batch consider using Spring batch - JdbcBatchItemWriter with proper chunk settings will load these 1500 records in a second...

rihards
+1  A: 

Some things worth checking:

  • The overhead might be on the transaction managed by Spring at the application level. Look what kind of transaction manager you are using (look for bean "transactionManager"). If you are using JTA, that's probabily where your problem is. Since it's fast with JDBC the bottleneck doesn't seem to be the db.
  • Depending how your app is using that transaction it might be holding everything in memory before it finishes all 1500 requests and commits. Do you see a large difference in memory usage (the Spring one should be a lot higher)?
  • What kind of DB connection pool are you using on either case?

Quick way to profile your app:

Get the pid - "jps -l"

Memory: "jmap -histo PID" (check if there's some form of memory leak)

Check what's going on under the hood: "jstack PID" (look for slow or recursive method calls)

Felipe Oliveira