Welcome Guest, Not a member yet? Register   Sign In
CI with Ajax is too slow ???
#1

[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() {

    console.time('fonctionTest');
    
$.ajax({
  url: "<?php echo site_url('testAjaxCI'); ?>",
  type: 'POST',
  async : false,
  data: '',
  success: function(data)
  {
      console.timeEnd('fonctionTest');
      $('div.dataPdoCi').html(data);
      //alert (data);
      
  }});
    
});

Code Ajax with CI and DB

Code:
<?php


class TestAjaxCI extends CI_Controller {

    /**
     * Constructor
     */
    function __construct()
    {
        parent::__construct();
            
        $this->load->database();
        $this->load->model('connexion','',TRUE);  
    }

    /**
     */
    function index()
    {
        $data = array();        
        $ret = $this->connexion->lastConnection(112, 10);  
        // SELECT date_cnx, adresse, information FROM connexion WHERE id_utilisateur = 112 ORDER BY date_cnx DESC LIMIT 10");
        
        echo "AVEC CI<br/>";
          
        foreach ($ret as $data)
        {
            echo '<h3>', $data->date_cnx, ' ', $data->adresse, '</h3>';        
        }
          
        // affichage de la vue
     //   $this->load->view('testPost', $data);
    }

}

Code Ajax with PDO

Code:
&lt;?php
// Connection au serveur
$dns = 'mysql:host=127.0.0.1;dbname=dbname';
$utilisateur = 'dbuser';
$motDePasse = 'dbpass';

try {
    $connection = new PDO( $dns, $utilisateur, $motDePasse );
}
catch ( Exception $e )
{
    echo "Connection à MySQL impossible : ", $e->getMessage();
    die();
}

// On envois la requète
$select = $connection->query("SELECT date_cnx, adresse, information FROM connexion WHERE id_utilisateur = 112 ORDER BY date_cnx DESC LIMIT 10");

// On indique que nous utiliserons les résultats en tant qu'objet
$select->setFetchMode(PDO::FETCH_OBJ);

echo "AVEC PDO<br/>";
// Nous traitons les résultats en boucle
while( $enregistrement = $select->fetch() )
{
    // Affichage d'un des champs
    echo '<h3>', $enregistrement->date_cnx, ' ', $enregistrement->adresse, '</h3>';
}


Messages In This Thread
CI with Ajax is too slow ??? - by El Forum - 12-27-2013, 07:19 AM
CI with Ajax is too slow ??? - by El Forum - 12-27-2013, 01:44 PM
CI with Ajax is too slow ??? - by El Forum - 12-27-2013, 03:30 PM



Theme © iAndrew 2016 - Forum software by © MyBB