ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Help tracking down a slow template issue

October 04, 2012 9:36am

Subscribe [3]
  • #1 / Oct 04, 2012 9:36am

    Jamie G

    6 posts

    Hi there, I have a template that displays a series of thumbnails taken from YouTube and Vimeo, using the Video Player module.

    When the page loads there is a very consistent delay of around 10 seconds after it starts loading the page and before it starts loading all the resources. I had thought the delay was caused by the images loading from the external sites so I wrote a script to save them to the server. This has made almost no difference.

    Here’s the offending code:

    {exp:channel:entries channel="Portfolio" category="{segment_category_ids}"}
         <?php
    
         $imgOrig = "{work_video}{thumbnail_large}{/work_video}";
         $imgName = basename($imgOrig);
    
         if ($imgName == '0.jpg') {
          $tokens = explode('/', $imgOrig);
          $imgName = $tokens[sizeof($tokens)-2];
          $imgName = $imgName.'.jpg';
         }
    
         $srcNew = $_SERVER['DOCUMENT_ROOT'] .'/images/thumbs/';
         $imgNew = $srcNew . $imgName;
    
         if (!file_exists($imgNew)) {
          $ch = curl_init($imgOrig);
          $fp = fopen($imgNew, 'wb');
          curl_setopt($ch, CURLOPT_FILE, $fp);
          curl_setopt($ch, CURLOPT_HEADER, 0);
          curl_exec($ch);
          curl_close($ch);
          fclose($fp);
         }
    
        echo '<li sty1e="background-image: url({work_video}http://'.$_SERVER["SERVER_NAME"].'/images/thumbs/'.$imgName.'{/work_video});">';
    
         ?>
         
          <a href="http://{url_title_path=">_       <hgroup>_        <h3>{title}</h3>_        <h4>{entry_date format="%F, %Y"}</h4><p>_       </hgroup>_      </a><br />
         </li><br />
         {/exp:channel:entries}

    As I said above my PHP hasn’t really made any difference to the timing and now I’m not sure how to figure out the problem.

    Thanks in advance.

  • #2 / Oct 06, 2012 2:08pm

    Dan Decker

    7338 posts

    Hi Jamie,

    Thanks for posting and Welcome to the Forums!

    I’m sorry you are seeing a lag!

    To get a clear look at where the hangup is, your best info is going to be Template Debugging. To do that, visit Admin-> System Administration-> Output and Debugging: Display Template Debugging?

    The output of the debugger is only visible to logged in Super Admins, so it’s safe to leave on.

    What I suggest is going back the your standard template code, minus the PHP and see where the lag comes in.

    Report back with that output and we’ll walk it out.

    Cheers,

  • #3 / Oct 06, 2012 7:31pm

    Jamie G

    6 posts

    Hi Dan, thanks for the help.

    See the debugging output file attached. Also despite being a bit incomplete, the client asked me to put the site live, so you can see the site here: http://brownianmotion.co.uk

    The problem pages are portfolio and the home page.

  • #4 / Oct 08, 2012 1:18pm

    Shane Eckert

    7174 posts

    Hey Jamie G,

    Thank you for the info.

    There is a rather large jump when calling the entries. It makes me wonder how you are calling the entries.

    Would you be able to put that bit of code here? Just straight out of the template. What renders on the page does not seem to justify the 15 second wait I had. I have a feeling we can change the way the portfolio is being built.

    Cheers,

  • #5 / Oct 08, 2012 1:34pm

    Jamie G

    6 posts

    Hi Shane, thanks for taking a look.

    I’m not totally sure which bit you’re after so here’s the whole template:

    {embed="embeds/document-header" title="{lv_portfolio_title}"}
    <div id="page">
     <header class="clearfix">
      <div class="container">
       <h1><a href="/">Brownian Motion</a></h1>
       {nav}
      </div>
     </header>
     <div role="main" id="page">
      <div class="container">
       <header class="clearfix">
        <hgroup>
         <h1>{lv_portfolio_title}</h1>
         <h2>{lv_portfolio_subtitle}</h2>
    <p>    </hgroup><br />
        {share}<br />
       </header><br />
       <section id="work" class="repeater clearfix portfolio {segment_category_ids}"><br />
        <ul class="clearfix"><br />
         {exp:channel:entries channel="Portfolio" category="{segment_category_ids}"}<br />
         <li><br />
          <a href="http://{url_title_path=">_       <hgroup>_        </p><h3>{title}</h3>_        <h4>{entry_date format="%F, %Y"}</h4><p>_       </hgroup>_      </a><br />
         </li><br />
         {/exp:channel:entries}<br />
        </ul><br />
       </section><br />
       {if segment_2 ==""}<br />
           <ul id="filter"><br />
         <br />
               {exp:channel:categories style="linear" category_group="6" show_empty="no" }<br />
                   <li><a href="/portfolio/type/{category_url_title}/">{category_name}</a></li><br />
               {/exp:channel:categories}<br />
        </ul></p>
    
    <p>       <ul id="filter2"><br />
        <br />
               {exp:channel:categories style="linear" category_group="11" show_empty="no"}<br />
                   <li><a href="/portfolio/dits/{category_url_title}/">{category_name}</a></li><br />
               {/exp:channel:categories}<br />
        </ul><br />
       {/if}<br />
       {if segment_2=="type"}<br />
        <ul id="filter"><br />
         <li><a href="/portfolio">All</a></li><br />
            {embed="embeds/get_categories" from_category_group="11"}<br />
        </ul><br />
       {/if}<br />
       {if segment_2=="dits"}<br />
        <ul id="filter"><br />
         <li><a href="/portfolio">All</a></li><br />
            {embed="embeds/get_categories" from_category_group="6"}<br />
        </ul><br />
       {/if}<br />
       {if segment_2=="cats"}<br />
        <ul id="filter"><br />
         <li><a href="/portfolio">All</a></li><br />
        </ul><br />
       {/if}<br />
      </div><br />
     </div><br />
    </div><br />
    {footer}<br />
    {document-footer}

    I’ve removed the PHP mentioned before, for better formatting since it’s not affecting things. I also tried previously to remove the all the filter menus (all those segment ifs at the bottom but that also made no difference). The header and footer are on all the pages so I’m assuming no problem there.

    Is that what you’re after?

  • #6 / Oct 09, 2012 11:53am

    Shane Eckert

    7174 posts

    Hi Jamie,

    Nothing sticks out here.

    As you removed bits from the page, what did the retests show? Any speed up?

    Thank you,

  • #7 / Oct 23, 2012 8:43am

    Jamie G

    6 posts

    Hi sorry for the gap in responding.

    If I remove all page elements aside from the channel entry it makes no difference. What does make a difference is the number of entries.

    If I limit the number of entries to 8 for example then the delay is a fairly consistant 3 seconds rather than 10-15 when all entries were displayed. If I try 16 then I get a 4-9 second delay.

    As I mentioned before this delay also happens on the home page which displays entries from this channel, so it is specific to the channel.

    The only thing unusual about this channel as far as I can see is that it has Video Player and Expresso fieldtypes…

  • #8 / Oct 24, 2012 11:21am

    Shane Eckert

    7174 posts

    Hi Jamie,

    Is the content really heavy?

    Can you enable the template profiler and check the footer to see where the load times jump?

    ** To turn debugging on please go to your Control Panel and navigate to Admin->System Administration-> Output and Debugging. Please set the last two settings, which are “Display Output Profiler?” and “Display Template Debugging?”, to yes.

    That will give us some more information.

    Thank you,

  • #9 / Oct 24, 2012 12:15pm

    Jamie G

    6 posts

    Hi Shane, no the content isn’t really that heavy, you can see the page: http://brownianmotion.co.uk/portfolio

    Currently there’s 47 fairly small images, the total transferred size as reported by the browser is 1.2MB (including all js, css and images) but even without the images the template takes about 5 seconds to load before everything starts to load. The template alone is 19.40KB.

    I think you saw my template profile attached a few posts back. I’ve done another which I’ll attach. It looks to me like the jump is here:

    (0.056603 / 6.15MB) -> Method Called: entries
    (16.969791 / 12.77MB) -> Data Returned

    Thanks again for the help.

  • #10 / Oct 25, 2012 10:45am

    Shane Eckert

    7174 posts

    Hello Jamie,

    I would like to get in a take a look.

    Please be on the lookout for an email from EllisLab.

    Thank you,

  • #11 / Oct 25, 2012 10:50am

    Jamie G

    6 posts

    Thanks Shane, reply on the way.

  • #12 / Oct 26, 2012 3:17am

    Shane Eckert

    7174 posts

    Hi Jamie,

    Thank you. I sent you a reply.

    Thank you,

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases