Welcome Guest, Not a member yet? Register   Sign In
How to increase performance?
#1

[eluser]chobo[/eluser]
Hi, I've just rewritten some code that use to be all crammed on one page (php with html all mixed up) and broken into a few libraries. I was curious to see what the performance difference was between the old code and new code, and unfortunately the old code is roughly 3 times faster when running apache ab benchmark on that page (it is noticeably slower).

Now I don't want to go back to using the old code because it took me a couple of days just to figure out what was going on (and I wrote it a month ago)... so it's a nightmare to maintain. I'm not sure if the extra slowness is because I broke that page into classes and maybe that's causing the slower performance, or maybe it's codeigniter, or a combination of both.

Could someone give me a few tips on making the new page perform better? Thanks!
#2

[eluser]coolfactor[/eluser]
Frameworks are always going to be slower. My top recommendation is to not cheap out on the hosting solution. Pay a few extra dollars to get a quality server that isn't overloaded with other sites. I pay $50 a month for a Virtual Private Server, which is a step up from Shared Hosting, the most common type of hosting. My sites are very snappy on that server.

The real performance gain you're going to notice is your time in managing the site. Frameworks, particularly one like CodeIgniter, are designed to make you faster, not necessarily your site. They save you tons of time in developing and managing a site.
#3

[eluser]coolfactor[/eluser]
CodeIgniter's caching mechanism is also very very fast, so I recommend using it for any pages that don't change very often. I usually set it to cache pages for 30 minutes at a time.
#4

[eluser]chobo[/eluser]
I think I'll look into the caching and benchmark libraries in codeigniter, maybe there is something I can tweak a bit. Thanks for the suggestions Smile
#5

[eluser]Derek Allard[/eluser]
One other thought, is to not load or autoload any libraries or helpers, models, etc, that you don't need on that page. Personally, if I have a commonly used library I tend to autoload it for convenience, but there is a small performance hit for doing so when you don't need it.

Also, I second CF's suggestion for the cache. It really is great.
#6

[eluser]chobo[/eluser]
I just tried the page caching and it's awesome. One line of code and it now performs just as fast as the old version. God I love this framework... Thanks for the help guys!
#7

[eluser]chobo[/eluser]
Just one more quick question. Is there a way or technique to specify a cache time for partial views in a function? I've searched around and couldn't find an implementation for that. Thanks!
#8

[eluser]coolfactor[/eluser]
[quote author="chobo" date="1186282535"]Just one more quick question. Is there a way or technique to specify a cache time for partial views in a function? I've searched around and couldn't find an implementation for that. Thanks![/quote]

That's a popular question here. No, there is no way with the current cache mechanism. Different ideas have been tossed around for how to implement partial caching. The trick is to do it in such a way that all the processing needed by the partial is avoided if the partial is already cached and hasn't timed out.

I may integrate this into my View library, and it would use the following type of implementation:

Code:
if ($this->view->partIsNotCached('main_content')) {
  
    // ... do all the processing needed to render the part

    // render the part
    $this->view->cachePart('main_content', 'path/to/partial/view');
}

In my own projects, I haven't found a great enough need to add in partial caching. The added overhead of checking to see if a partial is already cached would cancel out the benefits of caching the partial anyway. To get around that, the caching mechanism could load in all the cache files once into an array, but then we're using up memory that affects performance.

So, I'd really like someone to illustrate an example of where partial caching would provide any significant performance improvement. If it is to avoid database caching, well there's plenty that can be done on that front to improve performance, including database caching, which is a feature of CodeIgniter.
#9

[eluser]Vik[/eluser]
Is there a benefit to installing eaccelerator?
#10

[eluser]chobo[/eluser]
I'm going to take a look at the database caching. The way I setup my navigation just makes caching very hard, because everything is routed to the same page, so it's not really worth caching.




Theme © iAndrew 2016 - Forum software by © MyBB