debugging speed issues.

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Just thought I'd post this a the result of a few hours tracking absymal
page load speeds.

I had a page that someties loaded fast, but not after a databse update,
when it slowed to a crawl..using TOP on my Liux server showed that
mysqld was hofggong all te CPU fir ten secnds at a time.


anyway, it was obvious that somethig SQLish was at the heart of te
problem but what?

As part of yesterdays shenanigans I'd finally got error logging to a
logfile going, so I wrote a silly function.

function timestamp($place)
$t2= microtime();
error_log(" myscript stamped at :".$place."  at ".$t2);

And splattered calls to it all over the code.

Worked a treat. I found exactly where the time was being wasted, looked
at the code, and thought AHA!. Mysql has its cache flushed by an update,
and the raw select is taking about an INDEX'

Well Jerry is watching, so let's keep it php. The index worked like a
charm, and I go something like 50 times better speed. All's well that
ends well.. plus using compression is knocking the page size down
5:1..My javascript is now only doing the minimum, and things are looking up!

On to writing pdf's tomorrow.

Re: debugging speed issues.

The Natural Philosopher wrote:
Quoted text here. Click to load it

Funny you posted that . I had just written a similar function to solve a
recursive function problem in the wiki system I'm developing

example : wiki checks Home page , it has an include , }
, predecode function goes and fetches Links and embeds the contents into
the Home page.

I made the mistake of letting a friend have a go at it and by all
appearances he broke it . I had to use a logger so I could see wtf was
going on. Ended that he put a } embed on the Links page so i
had a runaway recursive predecode on my hands. The script spent all its
time doing embeds doing stupid amounts of sql queries.

I ended up NOT being such a lazy idiot and put a check to see if there
is an embed in a embed.

Lessons I learned .
1.) People try shit and can break a system if you don't think of it
first . Before you release code /product make sure you have someone play
with it to see if they can break it . ( you know, Beta testing)

2.) Make sure recursive functions can't runaway (  check number of
nested calls ) .

3.) use a debug feature to dump everything to a text file at least so
you can see everything that happens . Work out the kinks and then remove
it for production.

Remember kiddys all the programming experience you have won't protect
you from forgetting simple things or from your own laziness, that some
knuckle dragger will uncover in five minutes of faffing around and
breaking your project some how.

Anyone else faced  situations that we can learn from? ( php wise o corse)

regards trookat

Re: debugging speed issues.

trookat wrote:
Quoted text here. Click to load it
Well my day before yesterdays problem was exactly the same. Infinite

And the day before that, the longest time to write a line of php ever.
Took the best part of several days thinking about it and a day of
research and an hour of debugging.

yeah, I know it only nests 4 deep. If some nets deeper  some of teh
useful info will be lost but that's their problem.

SELECT distinct  (NOT isnull( as is_kit,
CONCAT_WS(':',,,, as catname,, kits.qty, overhead,  unit_price, as kit_id,
FROM  kits, product
LEFT join category as t4 on = product.category
LEFT JOIN category AS t3 ON = t4.parent
LEFT JOIN category AS t2 ON = t3.parent
LEFT join category as t1 on
LEFT JOIN kits as t0 on t0.parent =
WHERE  kits.parent='%d' and
ORDER by overhead DESC, is_kit, catname, name",

Now is that php or is that MySQL :-)


Re: debugging speed issues.

The Natural Philosopher wrote:
Quoted text here. Click to load it

Looks like MySQL to me.  The only PHP is a string being built.

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Re: debugging speed issues.

On Mon, 01 Dec 2008 18:20:11 +0000, a@b.c wrote:
Quoted text here. Click to load it

While I don't presume to speak for anyone, ISTM, advice on choosing
different NGs is more to help the poster than to exercise pedantry.  
If it turns out your problem is MySQL-related, for example, it's
natural to seek help in comp.databases.mysql, because you'll get more
answers from more experts.

Quoted text here. Click to load it

Nice job fixing your problem.

$email = str_replace('sig.invalid', '', $from);

Re: debugging speed issues.

Curtis wrote:
Quoted text here. Click to load it

Ao, in order to keep up with everything, I need

Comp.lang.php. // for langauge specific problems
comp.os.linux. // becaue many problems like between teh code and teh oS
alt.bugs.ie7 // because evertyone using a briwser in an app needs this
Comp.lang.html4 // because thats almost cetianly what teh php has to write.
comp.lang.javascript. /// becaue thats the otherthing teh php has to write.
comp.lang.sql // and that's the other stuff that php has to read.
comp.databases.mysql. // and thats the database 'OS' its on.

That's about as innefficient as listening to Jerry's solutions.

Probably at LEAST 30% of php programming is an interface to some sort of
database using some sort of SQL.

Probably about 90% of all php is outputting some form of formatted HTML.

Jerry reminds me of the people who wrote Pascal.

I/O doesn't exist in pure Pascal, because it can't be fitted into the
pure model of The Right Way to Write a Language.

Re: debugging speed issues.

The Natural Philosopher wrote:
Quoted text here. Click to load it

That's less than 1/2 of the newsgroups I pay attention to.

Those newsgroups are there for individual topics, not your convenience.
  The whole world is not interested in mysql, javascript, php and the rest.

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Site Timeline