We are trying to access a large volume of data from a remote database, but the time it takes to get the data from the database is more than the maximum timeout for the web server, so the webpage is not getting displayed. How can we solve this problem?
- Extend the maximum timeout for the web page.
- Optimize the query to return the data faster.
- Reduce the amount of data you return.
- Increase the bandwidth to the database.
- Tune the transport protocol to carry more data per packet.
- Last and most importantly for remote access across a slow line: denormalize the query. One query returning many rows will have a far faster throughput than many queries returning a small number of rows. Differently put, the submission and processing of a query itself can easily longer than the actual retrieval of the rows.
Joe Sam Shirah adds:
jGuru received several answers to this question on the JDBC side, most of which emphasized narrowing the query to take less time. This is excellent advice, but not always possible. Additionally, other tasks may bring up the same issues with servlets. During January, 2000, there was an exchange of messages on Sun's servlet mailing list which discussed the issue and provided a more general answer. Essentially, the advice is to start a new thread in the servlet to do the work and then, using refresh in the header, repeatedly send a status message until the long running task is done.