Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Improving Database Query Execution Time from Data Access Object  RSS feed

 
Ochi Elty
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am writing a DAO object that will be retrieving data from 5 unrelated tables. The queries will be executing sequentially. I am thinking of creating a thread for each query, so they will execute in parallel to improve performance. Is this a good solution? I just read that there is an overhead for creating a Thread. I'm thinking also of creating a ThreadPool so I won't create thread anytime I need it. Any suggestion on how to create a good ThreadPool.

Thanks a lot.







 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are likely to be far bigger overheads running the queries and streaming the results back over the network, and that work is not going to change regardless of whether you run sequentially or in parallel. Why don't you try both approaches and see which performs better?
 
Ochi Elty
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will try both approach and benchmark the result. I'm too concern about the performance since the application will be used by an organization with low end server machines due to budget constraints. I'm trying to improve execution time by fine tuning the codes of the application.
 
Kees Jan Koster
JavaMonitor Support
Rancher
Posts: 251
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First benchmark and then let us know what your results are. From there we can help you tune this.

For background threads, read up on how to use futures in Java http://java.sun.com/javase/6/docs/api/java/util/concurrent/Future.html

Kees Jan
 
axel garcia
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Won't independent queries require independent connections?

You might be execute faster at the expense of hogging
the connections?
 
Kees Jan Koster
JavaMonitor Support
Rancher
Posts: 251
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's where the careful measurement of the benchmark comes in. :-) You won't know until you try on the production hardware.
 
R van Vliet
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At the risk of derailing the topic slightly. How did you end up requiring data from 5 unrelated tables yet requiring said data for a single DAO? What is the relationship and why does it not have a similar relationship in your data model. The reason I'm asking is because if you can add said relationship in your data model you can probably create a single query to retrieve all required data for your DAO and let the database worry about optimizations such as parallelism, fetch buffers, caching, etc.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!