EE Insider Tips
Sponsored by Mijingo's EE 2 Screencasts
ExpressionEngine mini-howtos created by the EE Insider community.
Create a performance indicator
When setting up a site, I often create a performance indicator that displays the number of queries and the time it took for EE to generate the page. This is helpful for debugging purposes, to test caching, etc.
I create a sub-template called something like “performance” (I use a sub-template so I can embed it in multiple templates). In this sub-template, I put the following code:
{if logged_in && member_group == "1"}
<div style="position: absolute; top: 0; left: 0; position: fixed; background-color: #000; color: #fff; font-size: 9px; padding: 5px;">
{elapsed_time} seconds / {total_queries} queries
</div>
{/if}
I wrap the DIV within a conditional that checks to see if I’m logged in as a super admin (which effectively hides this information from the site’s regular visitors).
If I am logged in, the above code creates a small div that is positioned absolutely in the upper-left corner of my design and displays the number of seconds and DB queries it took to load that page.
Erik Reagan — 08:07 on 05.29.2009
That’s a simple yet fantastic idea. Everyone should optimize loading time but having real numbers in front of you like that helps point you in the right direction whether it be query caching or what have you. Thanks for sharing
mirkob — 15:24 on 06.02.2009
what’s the max number of queries it’s advised to have?
mindprint — 00:10 on 06.03.2009
Great. very helpful.
Why do you check for logged_in and member_group? I would have thought that just having check for member_group will suffice.
Jason Morehead — 05:18 on 06.03.2009
@mirkob: There really isn’t an advisable number. It all depends on the site and what you’re doing. For example, how many instances of the weblog entries tag you’ve got in a particular template and what you’re using them for.
@mindprint: Using just “member_group” would probably suffice, but I guess I’m a little anal and I want to make doubly sure that that information won’t be seen by just anyone.
OrganizedFellow — 11:02 on 06.04.2009
AWESOME tip!
Using it already with some referrer stats
moogaloo — 10:55 on 10.03.2009
nice… a bit of a newbish question tho (i have a BIG site coming up so performance will be pretty important) - presumably, if you have caching on, you would expect to have fewer weblog queries as they’ve already been queried, constructed, made and cached for future calls of the same query?
which is a good thing as it means quicker load times?
Jason Morehead — 05:47 on 10.04.2009
That is correct. If you have caching enabled, EE will cache DB queries, template info, etc.—all of which will improve overall performance. And you can get a good idea of just how much things improve with the performance indicator.
moogaloo — 00:27 on 10.05.2009
cool.
erik’s made one of his own as an extension: http://expressionengine.com/forums/viewthread/131026/