PHP Classes

Slow code

Recommend this page to a friend!

      PHP Preemptive Cache  >  PHP Preemptive Cache package blog  >  Improving Your PHP Co...  >  All threads  >  Slow code  >  (Un) Subscribe thread alerts  
Subject:Slow code
Summary:Roughly approach to detect slow code fragments
Messages:3
Author:ger ler
Date:2015-09-08 07:21:31
 

  1. Slow code   Reply   Report abuse  
Picture of ger ler ger ler - 2015-09-08 07:21:31
Hello Joseluis,

nice Article and interesting caching technique.

When I have to analyse code for performance issues I mostly use logging methods. It's easy to extend these (often given) loggers with some performance functionality like memory usage an script execution time.

Something like this I use to log:

$this->justLog((microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']).'s @' . $this->getMemoryUsage().'MB: in function X before calling function Y', $arrayOfFurtherInformation);

With this method I divide the code to look at into smaller pieces to faster find slowing parts. I also prevent XDebug from falsifying my measurements...


Best regards,
Gerald

  2. Re: Slow code   Reply   Report abuse  
Picture of Joseluis Laso Joseluis Laso - 2015-09-08 07:45:12 - In reply to message 1 from ger ler
Hi Gerald.

You are right.

But, be in mind that the example that I'll expose in the second part it's based on the console, as a server task or something like that. And, in this case I'm not sure if could be applied your notes. But I'll try, of course.

Related with the memory usage I have a version in local that uses php native functions to limit the amount of data cached. The target: prevent hang of the script, but all my tests didn't improve the speed because the memory_usage introduces lags. I'm very interested in how you are implemented your $this->getMemoryUsage().

Thank you so much for your comments.

  3. Re: Slow code   Reply   Report abuse  
Picture of ger ler ger ler - 2015-09-08 14:14:34 - In reply to message 2 from Joseluis Laso
Hey Joseluis,

I also mainly use the php native function memory_get_usage(), but it has an fallback that could be interesting for you.
I found it on stackoverflow:
stackoverflow.com/questions/2290611 ...
The post of Alix Axel also reads the memory usage the running OS determines:
exec('ps -eo%mem,rss,pid | grep ' . getmypid(), $output);
And have a look at the comment of greg on Alix' post...

I look forward to your second part