Jump to content
opalepatrick

Debugging Load Delay - Where to start

Recommended Posts

Trying to work out what is causing an approx. 20 second when loading a page of thumbs for a product catalogue. I have debug = true without any issues. Also, I have checked the server error logs and nothing either. I have several processwire installations on this server all operating fine. Some with very similar setups. I have checked the selector with selector test module and it seems OK. Looking on chrome inspect, the problem is right at the start where the delay occurs. Once that passes, everything loads almost instantly. Also, this occurs on chrome & firefox. Oh, and I should say that no other page is affected that I am aware of.

So, as I am finding this a bit frustrating, I was wondering if anyone has any tips as how to debug this? Just in case I have put the code for the page below.

edit: One other thing the product_cats field is a page fieldtype.

<?php
require_once("inc/header.inc"); 
$type = $page->title;

$selector = "product_cats.title=" . $type;

$products = $pages->find("$selector, limit=12");
//print_r($products);
$pagination = $products->renderPager(array(
    'nextItemLabel' => "Next",
    'previousItemLabel' => "Prev",
    'listMarkup' => "<ul class='MarkupPagerNav pagination'>{out}</ul>",
    'currentItemClass' => "current",
    'firstItemClass' => "arrow",
    'lastItemClass' => "arrow"
));
?>
<div class="row firstrow lastrow">
	<div class="pagination-centered">
		<?=$pagination?>
	</div>
	<?php
	foreach($products AS $product) {
		$pageimage = $product->images->first();
	 	?>
	    <div class="small-6 medium-4 large-4 columns" itemscope itemtype="http://schema.org/Product">
			<a href="<?= $product->url ?>"><img src="<?=$pageimage->pimLoad('myPrefix')->canvas(350, 350, array(255,255,255,0))->pimSave()->url ?>" itemprop="image"></a>
			<div class="prod_panel panel">
				<h5 itemprop="name"><?= $product->id ?> <?= $product->title ?></h5>
			</div>
		</div>
		<?php
	}
	?>
	<div class="clearer"> </div>
	<div class="pagination-centered">
		<?=$pagination?>
	</div>
</div>
<?php
require_once("inc/footer.inc");

Share this post


Link to post
Share on other sites

Just for interest, have you looked at the file size of the thumbs?

PIM maybe creating a higher quality thumb than you need.

Share this post


Link to post
Share on other sites

Either the pim function for the image

Or what are you searching with?

$selector = "product_cats.title=" . $type;

$products = $pages->find("$selector, limit=12");

Is that a repeater? How many repeaters are there?

Share this post


Link to post
Share on other sites

Other than that, try stripping out things like canvas and calls to schema.org and generally simplify it down and see what that achieves.

I sometimes kick out my headers and footers as well so I am not adding JS and CSS to the problem - doesn't matter what it looks like, just how fast it loads at that point.

Then start adding bits back ... :)

  • Like 1

Share this post


Link to post
Share on other sites

Thanks Joss. I did strip the pim stuff and other bits, bit by bit, but not the headers. Should do that. That is a multiple page fieldtype Soma (not a repeater afaik). I did wonder if that was causing an issue.

edit: Stripped headers footers and pim and still got the delay. So, has to be the selector? I should have a loop?

Share this post


Link to post
Share on other sites

So, just following on from above. I have used that exact same script previously without a problem.

It appears to be specific to this setup. Basically when I run it, the cpu shoots up to 100% and stays there and stops every other site on my vps from doing anything.  It was working and I cannot for the life of me think what has happened that could have messed things up. I did run a few queries on the database directly without an issue, and on the server using top, the cpu problem is on the apache service (not mysqld).

Anyway... rambling. Bit stuck. Any comments gratefully received.

Share this post


Link to post
Share on other sites

er... not knowing exactly what your set up here is, but it sounds like you are basically grabbing a huge amount of information and then trying to deal with it.

But I cant see where that is happening.

Now, your database query (find) it is looking for what exactly? The fact that you have used this script before sound like the problem may be in the quantity you are dealing with in this case, or something like that. In other words, not so much what you are returning but what you are searching.

If the CPU usage is rocketing, then it sounds like you are getting stuck in a loop somewhere - searching on itself or something.

Can you refine the search in anyway to make it more specific?

  • Like 1

Share this post


Link to post
Share on other sites

So if you remove all that code, it is gone?


You can also use 

$runtimer = Debug::timer();

... code

$runtimer = Debug::timer($runtimer);
echo "Time: $runtimer";

Edit: corrected syntax...

  • Like 1

Share this post


Link to post
Share on other sites

Well, been investigating around in a few more circles :-)

I can't execute Soma's code as the page isn't even loading now. It hangs completely using 100% of cpu. (Actually, I went to make a nice cup of horlicks and it had loaded after 5 minutes or so)

The max results on this page would be 10 or so products max. So not even scratching it.

I replaced wire btw, not that it did any good :-). Removed unwanted modules as well.

Share this post


Link to post
Share on other sites

What on earth are you calling that is doing that?

just for an experiment, what happens to the page if you remove the query and its associated code completely? Just in case it is NOT the product query that is causing the problem

Share this post


Link to post
Share on other sites

Hi Joss. Minor breakthrough!

As you can imagine I have a lot for different categories using this script. I have been testing using just one category. I had stripped everything back to core and instead of looking for 'side chairs', I got bored and looked for sofas and bingo! instant result. So then I restored everything and checked every category without a problem save for that single category 'side chairs' - Really bizarre.

So, now I am looking at the difference between that category and every other. Strange one as all I am doing is matching the category with the category field in products. Same as for all the others.  :huh:

Share this post


Link to post
Share on other sites

Well, at least that means that your script structure is probably fine.

Thinking back to the maintenance man in my old studio who used to shout to us to check the plug was in the wall before phoning him saying "its broke again," start going through the obvious.

I am assuming that the categories are a group of pages under a set parent using the same parent. And you are using the title field to search by.

To start with, the problem with using the title field is if you rename the category you might have an issue.

So, just for interest, search by id instead. See if that is okay.

  • Like 1

Share this post


Link to post
Share on other sites

Thanks for all your patience Joss. I am using the scenario you referred to with the cats under one parent and the actual products just listed under a different parent.

I tried using the id, and it is a tad faster, although it doesn't resolve the issue. Now I am getting more to thinking it may be something to do with the page weight. So I am going to load up some of the other categories to match the number on the problem one and see what happens. The images are definitely not large, but it may be pointing to another issue re my server. So, I will return!

It's true about the handyman though :-)

Share this post


Link to post
Share on other sites

The quickest way to check the page weight is to stop rendering the images.

One thing I had with PIM the other day (the first time I had used it) was that in its default configuration, the images it was producing had a significantly higher file size than the originals, despite being smaller pixel wise. This was because it was saving at a much higher quality than I had saved the originals.

Then again, you only have 12 images here.

I am not sure if you are also overworking your code a bit (this is the point when Soma might tell you that I am talking rubbish - he knows WAY more than I do)

Just digging out a similar bit of code from an old blog of mine:

function getPostsbyCategory() {
	$thisCategory = wire("page");

	$posts = wire("pages")->find("post_category_select=$thisCategory");

	$out =" ";
	foreach ($posts as $post) {
		$text = implode(' ',array_slice(str_word_count($post->summary,1),0,$maxpostlength));
		$out .="<div class='posts clearfix'>";
		$out .="<a href='{$thisCategory->url}{$post->name}'><h4>{$post->title}</h4></a>";
		$out .="$text...<a href='{$thisCategory->url}{$post->name}'>read more</a>";
		$out .="</div>";
	}
	
echo $out;
}

Ignore me truncating the text in the middle.

I don't appeared to have explicitly referenced the title field, but I cant remember why. I have left out any limits or pagination here.

  • Like 1

Share this post


Link to post
Share on other sites

The previous advice you gave about checking plugs was on the money, in the sense that it paid to go back to the beginning and step it through.

It was caused by the images. Two things compounding. One, I had for some reason uploaded very large images, something I normally never do, but if I remember, I was checking pim and forgot to go back and optimise afterwards. Also, that was compounded by me not using pim properly and stating the quality. I also have a feeling (may be wrong) that the image was being resized every time as opposed to the cache being used. But  can't be sure about that. It may have just been the sheer load on the page.

I have reverted to previous practice and optimised the images first. Quick with imagemagick and everything appears to be sorted. So with your help, Joss, and Soma's I have managed to swirl back up and out of the rabbit hole I got myself into. Thanks once again. By the way, I reverted to just using size() as well.

  • Like 2

Share this post


Link to post
Share on other sites

Yeah, that damned mains plug in the wall - gets you every time...

Good luck with the rest of the site!

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Jarden Black
      Hi everyone,
      [edit: do not loose your time reading this post, I solved it by disabling cache in the Pages2Pdf module... sorry 😓]
       
      I do not know if I should post on the Pages2Pdf thread or here. Mods, feel free to move the post.
       
      Since three days I am scratching my head  to understand a weird thing happening with $session and $config->debug used in conjunction with Pages2Pdf module. For information, I tested it on a fresh install of ProcessWire 3.0.96 with PHP-7.0.28 and Pages2Pdf-1.1.7 (domain: http://session.sites.sek/). I will try to explain what is going on.
       
      What I am trying to achieve :
      In a template, I need to set some sessions variables which are then echo'd in the PDF document.
      (on the test installation, the basic-page template (page /about/?pages2pdf) serve the PDF, the home and sitemap template set the session variable.)
       
      The problem :
      From the template sitemap, I set a variable: $session->setFor('pdf', 'myvar', 'Session set from Sitemap template');
      From the template home, I set a variable: $session->setFor('pdf', 'myvar', 'Session set from Home template');
      Then in the PDF default template, I echo the session variable: <p>Session: <?= $session->getFor('pdf', 'myvar'); ?></p>
       
      Now I turn ON debug mode ($config->debug = true) :
      Then I navigate to  "http://session.sites.sek/home/" and the session variable "myvar" is set to "Session set from Home template". Then I navigate to  "http://session.sites.sek/sitemap/" and the session variable "myvar" is set to "Session set from Sitemap template". Now I want my PDF document, so I navigate to "http://session.sites.sek/about/?pages2pdf=1" and I get my PDF document with the right session var : "Session set from Sitemap template" For the moment, nothing special happen. Everything work great. We are in debug mode.
       
      Now I turn OFF debug mode ($config->debug = false) :
      Then I navigate to  "http://session.sites.sek/home/" and the session variable "myvar" is set to "Session set from Home template". Then I navigate to  "http://session.sites.sek/sitemap/" and the session variable "myvar" is set to "Session set from Sitemap template". Then I navigate back to "http://session.sites.sek/home/" and the session variable "myvar" is set back to "Session set from Home template". Now I want my PDF document - as expected, the "myvar" should be set to "Session set from Home template" - so I navigate to "http://session.sites.sek/about/?pages2pdf=1" and here the problem happen. Instead of echoing  "Session set from Home template" in the PDF document, the phrase "Session set from sitemap" is echo'd (the last value recorded before switching from debug ON).  
       
      I made two small screencasts to show the issue :
      DEBUG ON (Everything is OK)
       
      DEBUG OFF
       
       
      I am missing something ? EDIT: YES, you are dumb!
       
       
    • By flydev
      Hi everyone,
      [edit: do not loose your time reading this post, I solved it by disabling cache in the Pages2Pdf module... sorry 😓]
       
      I do not know if I should post on the Pages2Pdf thread or here. Mods, feel free to move the post.
       
      Since three days I am scratching my head to understand a weird thing happening with $session and $config->debug used in conjunction with Pages2Pdf module. For information, I tested it on a fresh install of ProcessWire 3.0.96 with PHP-7.0.28 and Pages2Pdf-1.1.7 (domain: http://session.sites.sek/). I will try to explain what is going on.
       
      What I am trying to achieve :
      In a template, I need to set some sessions variables which are then echo'd in the PDF document.
      (on the test installation, the basic-page template (page /about/?pages2pdf) serve the PDF, the home and sitemap template set the session variable.)
       
      The problem :
      From the template sitemap, I set a variable: $session->setFor('pdf', 'myvar', 'Session set from Sitemap template');
      From the template home, I set a variable: $session->setFor('pdf', 'myvar', 'Session set from Home template');
      Then in the PDF default template, I echo the session variable: <p>Session: <?= $session->getFor('pdf', 'myvar'); ?></p>
       
      Now I turn ON debug mode ($config->debug = true) :
      Then I navigate to  "http://session.sites.sek/home/" and the session variable "myvar" is set to "Session set from Home template". Then I navigate to  "http://session.sites.sek/sitemap/" and the session variable "myvar" is set to "Session set from Sitemap template". Now I want my PDF document, so I navigate to "http://session.sites.sek/about/?pages2pdf=1" and I get my PDF document with the right session var : "Session set from Sitemap template" For the moment, nothing special happen. Everything work great. We are in debug mode.
       
      Now I turn OFF debug mode ($config->debug = false) :
      Then I navigate to  "http://session.sites.sek/home/" and the session variable "myvar" is set to "Session set from Home template". Then I navigate to  "http://session.sites.sek/sitemap/" and the session variable "myvar" is set to "Session set from Sitemap template". Then I navigate back to "http://session.sites.sek/home/" and the session variable "myvar" is set back to "Session set from Home template". Now I want my PDF document - as expected, the "myvar" should be set to "Session set from Home template" - so I navigate to "http://session.sites.sek/about/?pages2pdf=1" and here the problem happen. Instead of echoing  "Session set from Home template" in the PDF document, the phrase "Session set from sitemap" is echo'd (the last value recorded before switching from debug ON).  
       
      I made two small screencasts to show the issue :
      DEBUG ON (Everything is OK)
       
      DEBUG OFF
       
       
      I am missing something ? EDIT: YES, you are dumb!
      Why it is working with debug mode ON and not vice-versa ?
      Is there someone who already spotted this strange behavior ?
      Is there a PHP settings which should be modified ?
       
      ====================================================
      Edit:
      I needed to post just to figure myself that Pages2Pdf cache the document when $config->debug is false.
      😬😬😬
       
    • By chrizz
      Usually I write modules just for me and my projects because they are more or less individual. Mail Debugger is the first module which might be interested for someone else as well. 
      https://modules.processwire.com/modules/mail-debugger/
      Basically it covers two use cases: 
      1) Log outgoing emails
      2) In debug mode mails are send to a specified email address instead of the original recipient(s)
      I checked the compatibility for PW 3+ because unfortunately I don't have any other version for testing currently. Feel free to drop me a comment if the module works also for older PW versions. 
    • By horst
      Hi, here is a very useful tool that check your images in websites against responsiveness:
      https://github.com/ausi/respimagelint
       

    • By microcipcip
      Does anybody know why I am unable to debug images? I only see the field name, but not the array with the list of images, I tried xdebug and tracy debugger...

      This is my code: var_dumb($page->fields) or dumbAll($page->fields).
      This is what I see, note that I have several images (array) in this page:


      If I try foreach on the fieldgroup and output the fieldname I can get the image url...
      P.S. a little bit off topic...but is there a way to just get the data/values of the fields? I don't really care about all the other fields like hooks, wire, notices, etc etc...
×
×
  • Create New...