CodeIgniter Forums
Sporadic slowness - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Sporadic slowness (/showthread.php?tid=33983)

Pages: 1 2


Sporadic slowness - El Forum - 09-15-2010

[eluser]imorris[/eluser]
I have a codeigniter app that I've deployed that I'm seeing sporadic slowness with. Sometimes the controller/page will take .5 seconds to load and sometimes it will take 5+ seconds to load. Do you have any advice you can provide in regards to troubleshooting this issue?

We've enabled profiling and don't see any abnormalities and we also don't see any issues in the apache logs.

This same application runs fine from my local PC, pointed at the same database.

The database is isolated on its own server.


Sporadic slowness - El Forum - 09-15-2010

[eluser]Phil Sturgeon[/eluser]
If you are using Windows sometimes CodeIgniter can have trouble making multiple writes to the log file so it ends up getting CRAZY slow. I had the same issue with 10+ second loads when config threshold was up to 4.


Sporadic slowness - El Forum - 09-15-2010

[eluser]imorris[/eluser]
Phil,
That was a really good idea about the logging but I have it set to "0". The app is setup on an Ubuntu server.


Sporadic slowness - El Forum - 09-17-2010

[eluser]imorris[/eluser]
Any other things I can look at to fix the sporadic performance issue?


Sporadic slowness - El Forum - 09-17-2010

[eluser]Pascal Kriete[/eluser]
Quote:We’ve enabled profiling and don’t see any abnormalities and we also don’t see any issues in the apache logs.

This makes it sound like it may be a network latency issue to the web server.

If you turn on the profiler or add {elapsed_time} to the page. On one of the slow loads, how long does it say it took to execute?


Sporadic slowness - El Forum - 09-17-2010

[eluser]imorris[/eluser]
Here's my welcome/index:
Code:
$this->output->enable_profiler(TRUE);
        
$this->benchmark->mark('my_mark_start');
$this->load->model('Member_model','',TRUE);
$this->benchmark->mark('my_mark_end');
        
$this->benchmark->mark('my_mark1_start');
$data['Members'] = $this->Member_model->get_members();
$this->benchmark->mark('my_mark1_end');

$this->benchmark->mark('my_mark2_start');
$data['checkins'] = $this->Member_model->get_last_ten_checkins();
$this->benchmark->mark('my_mark2_end');

$this->benchmark->mark('my_mark3_start');
$this->load->view('welcome_message',$data);
$this->benchmark->mark('my_mark3_end');


Here's my profiler:

Code:
Loading Time Base Classes   0.0080
My Mark   0.0023
My Mark1   0.0041
My Mark2   0.0013
My Mark3   0.0007
Controller Execution Time ( Welcome / Index )   5.0368
Total Execution Time   5.0448

My question is...My total profiler controller time is 5 seconds but my "mark" time is less than one second. How can I find out where the other 4.5 seconds are coming from?


Sporadic slowness - El Forum - 09-17-2010

[eluser]Pascal Kriete[/eluser]
Eeek! Are you autoloading anything? If it slows down that much it must be something happening in the constructor, or in CI's parent controller.

In CI 1.7.2 (which is what I assume you're on), the autoloading step happens in the parent constructor. So to benchmark it you'll need to tweak your own a little bit:
Code:
class Welcome extends Controller {

    function Welcome()
    {
        // instead of parent::Controller();
        parent::CI_Base();
        
        global $BM;
        
        $BM->mark('initialize_start');
        $this->_ci_initialize();
        $BM->mark('initialize_end');
    }
}



Sporadic slowness - El Forum - 09-20-2010

[eluser]imorris[/eluser]
The only thing I'm autoloading is 'databases' and 'DXAuth'.

I made the change as you suggested and here's what I got for output. What is "Initialize" and why is it taking so long?

Code:
Loading Time Base Classes   0.0077
Initialize   5.3600
My Mark   0.0034
My Mark1   0.0043
My Mark2   0.0013
My Mark3   0.0013
Controller Execution Time ( Welcome / Index )   5.3705
Total Execution Time   5.3783



Sporadic slowness - El Forum - 09-20-2010

[eluser]Pascal Kriete[/eluser]
Initialize is where the autloading is happening. Try removing the autoloaded stuff libraries one by one to see if that makes it go down.


Sporadic slowness - El Forum - 09-20-2010

[eluser]imorris[/eluser]
I've stopped autoloading DX_Auth. The only thing I'm autoloading now is my database. I'm still seeing sporadic slowness. Is there a way I can Benchmark the load and the connection process of the database?