views:

382

answers:

3

I'm new to app development and CI as a whole, so I've got an oodle of questions.

What is profiling? How is it used? How does it work? What is considered a "long" time?

More importantly,

How do I use it to improve performance?

The reason I'm asking is b/c my app is really sluggish right now.

+1  A: 

Here are a few threads I discovered when researching CI performance / benchmarking:

http://codeigniter.com/forums/viewthread/101804/P0/

http://www.haughin.com/2008/02/13/optimizing-and-scaling-your-codeigniter-application/

In the first thread, I believe there was some discussion of benchmarking, but I never found a definitive set of numbers that would help benchmark an app.

someoneinomaha
+2  A: 

As should become clear when you use profiling it's used to see how fast aspects of the page are. Put this line in the main controller near the start (eg in the constructor right after you call the parent's constructor:

$this->output->enable_profiler(TRUE);

This will print a lot of profiling information at the bottom of your resulting page. This will include all the database queries, how long the take and how long was spent in the controllers (PHP time as opposed to database query time).

If something is slow start by enabling the profiler and checking if it's the controller or the queries (or both). If it's the database queries, then you need to improve them and that's a whole topic in itself. If it's the controllers then you need to find out what code specifically is causing the slowdown.

Have a read of http://codeigniter.com/user_guide/libraries/benchmark.html and start placing the benchmarking start and stop tags where you think it's likely to cause slow speeds, loops and any recursive functions are the first places you should check. Once you find a slow segment of code you need to find how to optmise it, which again is a whole can of worms on its own.

It is possible that slow speeds are due to bad hardware, a busy server, a slow connection or a ton of other issues, those are outside the scope of this question though.

Edit: Just want to add that you don't use CI's profiler or benchmarking functionality to improve the speed, only to find where the speed needs to be improved. I know it's a minor thing, but just thought I should point it out.

Sid
Thanks for the edit! That was helpful!
Kevin Brown
+3  A: 

In performance tuning, the bottom line is how long does the program take, in wall-clock time, to finish the given task. I know that sounds like DUH, but that's the one concept everyone can agree on.

There is a very firmly held belief that in order to find the code that you can fruitfully optimize to speed up the program, you do it my measuring time taken by various functions and counting how many times they are called.

Even hardware engineers, who I would have thought would know better, have offered to provide me with nice timer and counter chips, when they were building a board set that I was trying to program, thinking that would help me tune the software.

NO THANK YOU, I told them. All I need is a way to stop it at random and ask what the heck is it doing, and why is it doing it. It's the drop-in-on-your-worker-at-random-and-ask-what-he's-doing approach. If I do this several times, and a good chunk of the time is being spent less than productively, the chance I won't catch it is basically nil.

Here is more on the subject.

Mike Dunlavey