Dreamhost support have invited us to let them know if we notice any performance issues, so here is a script that could do that.
It takes the pulse of each website into which the script in my previous post has loaded the file ‘jtime.php’.
This gets a list of domain names and for each item on the list (where the domain name is $2) calls
and sends an email report if any of the calls takes longer than a given number of seconds.
The script takes three parameters: the first is a dreamhost api key that can do ‘domain-list_domains’; the second parameter is an email address for sending reports of slow sites; the third parameter is the number of seconds that counts as slow.
In this version we are (for simplicity) discarding the output of the php call and looking only at StdErr which, if the ‘curl’ command succeeds, will be the elapsed time in seconds reported by ‘time’ or, if the ‘curl’ command fails, will be (if anything) an error message produced by the system.
It is tempting to lump any error results in with the slow results. However, as we are specifically targetting slow sites, Dreamhost support will surely jump on any excuse to ignore the reports, and if they see anything that says (for example) “Command terminated by signal 9” they will say “Ah! Your command was killed. Obviously it was using too many resources” and they will refuse to look further.
So, for now, we had better weed out the error results and send only the slow results. But how to tell the difference?
Well, in the course of logging nearly a million php calls, my logs have collected a surprising variety of error messages but, so far, none of the error messages begin with a number. So this script tests the first word of StdErr for numeric (“if $2 == $2+0”), and if numeric, assumes that it must be the time in seconds reported by ‘time’. We then compare this with the third parameter supplied to the script (“if $2 > $3”) and if greater, we pass the line through to ‘mail’.
Finally, we should send email only if there are any lines to send. The ‘-E’ option to ‘mail’ sends mail only if the message body is non-empty.
So this script sends an email if (and only if) any of the php calls take longer than a specified number of seconds, where the email message is a list of the slow domains and their times: for example,
or even (there has been another apache slowdown leading apparently to an apache reset at approx 17:20 on April 26th on 22.214.171.124, which is the same IP number that had a slowdown on March 4th/5th)
mydomain.com 5981.95 (that is, nearly an hour and 40 minutes, the current record)
Next I will ask Dreamhost support if this approach could help track down performance issues, and if so, for an email address for sending the results to.
Comments welcome, especially about any mistakes or wrong assumptions I’ve made.
P.S. … just to mention … these scripts are generic. Anyone could run them. They work equally well at my other host, which gives an interesting perspective on comparative performance.