Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring JDBC vs JDBC

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.

like image 681
seno Avatar asked Aug 09 '10 18:08

seno


2 Answers

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

like image 142
rihards Avatar answered Sep 22 '22 02:09

rihards


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 a bean with name transactionManager). If you are using JTA, that's probably where your problem is. Since it's fast with JDBC the bottleneck doesn't seem to be the db.
  • Depending on 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 in either of the cases?

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)

like image 37
Felipe Oliveira Avatar answered Sep 22 '22 02:09

Felipe Oliveira