Server Side Loading
Server Side Loading
Hello,
I have a database Table with 2 million records. I am using Server-Side loading with Pagination.
My problem is:
When I first load the page, the loading of DataTables is not immediate, there is a gap of about 5 seconds even for the first loading of 10 records. Is it possible to reduce this time?
Say if, in the same table, I want to pre-fetch/cache load first 50 records within minimal loading time, and then load the rest of the records, based on search and as per pagination request, is there a easy way to do it?
i.e., Load first 50 records immediately as the page loads, and the rest can be as per request.
I tried deferLoading, but my problem is that my Database keeps regularly updated, and I cannot make a static table of first N records in HTML.
Thanks and Regards,
TU
This question has accepted answers - jump to:
Answers
I have a database table with 4 million records, loading in less then 0,5 second.
Your problem will certainly lay in the way how you select your records.
Please post your tables and used sql.
I am using standard v1.10 simple(...) function in server_processing.php
The SQL executed is below. All the values of $where, $order, $limit, are default.
I am not even filtering the table with a search... its the first default loading of a paginated table that is taking time. The desc of the mysql table is
I am NOT using the example class I wrote my own serverside code. Especially because i would have better understandings about what happens then (my lack of knowledge to understand the class well enough).
Jsut one of the the first hits in google about SQL_CALC_FOUND_ROWS:
http://www.percona.com/blog/2007/08/28/to-sql_calc_found_rows-or-not-to-sql_calc_found_rows/
This article tells you basicly that people often only counts the amont of queries instead of looking to the overall query process.
I started with the basic query. Later on i have build up the query depending on all sort and search options.
Hereby my own basic query, rewrite the values for your own situation and you will probably notice the quick response. After that you could try to add the other demands. If needed i can provide you with my code.
Using a tool to look at the ajax calls en -responses will greatly improve debugging tasks. I myself use Firebug, but their are other alternatives enough.
Thanks!! I will try out writing raw sql queries, and sql optimizations and share the results.
TU
Terradon, thx!!
Your suggestion of avoiding SQL_CALC_FOUND_ROWS reduced my loading time by half!! Still it is taking more time than I would like. I am also trying to optimize my SQL front with indexing and caching and partial in-memory loading.
In case, somebody has any suggestions/tricks on
Pre-Fetching'' and
Concurrent / Predictive Look-Ahead'' loading of say, first few pages of the DataTable, please let me know.Thanks!!
TU
I dont like caching sql results. The only entity knowing what sql results to cache, is the database itself, which already does it automatically for you. Focus on efficient queries, not a caching system application-side! it is the wrong approach!
My given eample was my first example to start for the first view of the table. I added all kind of search and order possibilties en ended up with building up 3 queries for everything.
ALWAYS use prepared statements, with PDO it's sooooooooooo easy to to. Quit mysqli, use PDO for easier coding. Some people will tell you it cost more time, but that is hardly to measure. Your queries themselves will have much more influence on needed time. I maintain a heavy ajaxed site with an avarage of 100-150 vistors simultaniously online without any database issues.
Hereby my final backend:
Hope this will help you to get the idea.
This script is still under development for improving, but it already works fast.
If you have any questions, let me know.