0

I have a page that displays the top 10 most recent entries in a particular channel. When I add an entry to the Channel and load this page, it takes forever to load. However, subsequent loads go faster. I think it's faster due to the MySQL query being cached.

What things can I do to troubleshoot this problem? Why are the initial loads so slow? What params can I pass to exp:channel:entry to speed up queries? Any other suggestions why things might be slow?

NOTE: this particular channel has a lot of relationship field types. I'm wondering if that's potentially a problem.

UPDATE 1:

Initial page load: Total Execution Time 218.7162. Subsequent page loads are like this: Total Execution Time 1.7793.

  • When you say initial page load, what are you doing to reset between tests? Are you restarting MySQL? This sounds more like a database issue to me. 300 queries should not take over 3 minutes to load. Can you enable the EE output profiler and see whether any particular queries are taking longer than others? – Adrian Macneil Feb 10 '13 at 12:33
  • I'm investigating. Problem might be a few queries in a custom addon. It might not be a problem for Stack Exchange, actually. – ExpressionEngineNewbie Feb 10 '13 at 13:05
5

First off it would be a good idea to establish how slow your template is rendering and how many database queries are being performed. I would then strip back your template and add each element back into it individually seeing how many additional queries are needed and how much additional time they take.

Turn on the Output Profiler by going to Admin > System Administration > Output and Debugging. This will show a bunch of useful information including execution time, memory usage and the number of queries performed.

The relationship fields are probably the main issue in your template as each one will be adding about 3 additional queries per entry. Times that by the 10 entries in your channel entries loop and you are potentially using 30 queries for each relationship field that is being displayed.

If you have to display relationships or any add-on that uses it's own database table in a listing there are a few things you can do to reduce the number of queries. I will commonly write a plugin with my own custom queries to get the information I need more directly. Greg Aker wrote a good article on creating Expression Engine plugins. Stash is also very helpful when you need to use query intensive tags more than once.

Unfortunately there's not really a magic bullet when it comes to performance. One of the great things about Expression Engine is that's easy to construct and template quite complex websites. However you can get yourself into a bit of trouble if you don't understand what's going on behind the scenes. Familiarising yourself with the output profiler and the database queries that are being run for each tag will go a long way when thinking about how you can build a site with performance in mind.

| improve this answer | |
  • Good points. On the page that lists 10 Channel entries (my search engine results page), I actually don't need the values of all the relationship fields. I probably only need a couple. Is there a way to tell EE not to do the additional queries for certain relationships (e.g like the disable parameter)? – ExpressionEngineNewbie Feb 10 '13 at 7:07
  • Just checked. It was a total of 275 queries on that one page. – ExpressionEngineNewbie Feb 10 '13 at 7:23
  • Initial page load: Total Execution Time 218.7162. Subsequent page loads are like this: Total Execution Time 1.7793. – ExpressionEngineNewbie Feb 10 '13 at 8:05
  • 275 queries is a lot but probably shouldn't be taking that long. The relationship fields won't add any queries unless you include their tags in your templates. It sounds like there's something else in your template that's causing the delay. If you set 'Display Template Debugging?' to yes in the 'Output and Debugging' preferences you can see how long each tag/section of your template take to parse. – Dylan Feb 11 '13 at 3:10
2

You might use the parameter disable="categories|category_fields|member_data|custom_fields|pagination|trackbacks" within the channel entry tag.

| improve this answer | |
  • Can you please explain what each of those are? What's the difference between categories and category_fields? I think I don't need member_data, so that's good. What are custom_fields? I think I need pagination. No clue what are trackbacks. – ExpressionEngineNewbie Feb 9 '13 at 6:19
  • 1
  • there is no benefit to disabling categories and category fields separately. The former includes the latter. Also, trackbacks never made it to EE2 - they're purely for EE1. – James Smith May 13 '13 at 14:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.