![]() |
CI with Ajax is too slow ??? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: CI with Ajax is too slow ??? (/showthread.php?tid=60010) |
CI with Ajax is too slow ??? - El Forum - 12-27-2013 [eluser]Unknown[/eluser] I use CI (2.1.3) for a big project with several pages in Ajax en Jquery. I have many sensors that are written in the database and I use Ajax to display the values every 30 seconds. But we have some problems with speed for the ajax pages and more we use pages more the response time increases. I did a simple test and I did benchmark (i user console.time and console.timeEnd, see the code after) (time in ms) 147 177 267 400 164 441 166 173 288 388 154 565 202 270 326 369 117 479 165 296 294 401 127 322 233 192 268 436 171 429 112 236 238 364 122 424 --------------------------------------------------- 165 228 271 413 155 472 (average time in ms) detail of result 165 ms : on the first page with PDO 228 ms : on the first page with CI 271 ms : after login 413 ms : after 2 minutes with a lot of click on pages 155 ms : after 4 minutes with PDO 472 ms : after 4 minutes with a lot of click on pages I do not understand why time increases ? I thought to rewrite the class Loader only for Ajax with removing the view, the translation .... but I am not satisfied with the response time PDO CI 22 130 My_Controller (with extend CI_Controller) 22 105 with CI_Controller (without extend CI_controller) 22 99 LoaderForAjax (make my new Loader class (copy of Core Loader without view, language, ) 22 52 load page with controller en index 22 64 use CI with PDO 9 50 only one instruction : echo "hello world"; Solution : The solution is to use the PDO on Ajax pages, but I did not want to rewrite all my queries, and especially I will not have the benefits of CI (security, DB ...) Question : Do you have another solution for me ? or maybe I used wrong CI (see my code after) ? Thank for your help Cédric code to call ajax Code: $('.ci').on('click', function() { Code Ajax with CI and DB Code: <?php Code Ajax with PDO Code: <?php CI with Ajax is too slow ??? - El Forum - 12-27-2013 [eluser]jonez[/eluser] Was your testing done locally or on a server? You should should not use synchronous AJAX calls unless absolutely necessary. Quote:and more we use pages more the response time increases.If every user is calling a complex query on an interval it's going to hammer your server. Optimize the query, check for missing indexes or add additional ones. It could be that the faster queries are cached results (data hasn't changed) and the higher ones aren't. CI with Ajax is too slow ??? - El Forum - 12-27-2013 [eluser]Unknown[/eluser] thank for your reply, the time is given with a server on internet, I was 155ms for PDO and 475ms for CI. And My little test is on local, 22ms PDO and 130 CI Good point for asynchronous Ajax, but this is just an example for my test. The query for the test is not complicated: Code: SELECT date_cnx, address, information FROM connection WHERE userid = 112 ORDER BY DESC LIMIT 10 date_cnx I use only Query Bindings: Code: $ sql = "SELECT * FROM WHERE id = some_table AND status = AND author =??" Code: $ this-> db-> query ("SELECT * FROM some_table WHERE id = 3 AND status = 'live' AND author = 'Rick'"); For cache management, great idea, I found the documentation, I try this http://ellislab.com/codeigniter/user-guide/database/caching.html see you soon for results |