Optimising for speed

software development


I’m trying to squeeze ever possible source of latency out of my app. I’ve done some basic benchmarking and my total page load time is roughly 555ms. I’m trying to figure out what accounts for this time:

Pinging the server takes about 167ms and there’s probably very little I can do about that.

I used [font=Courier]register_shutdown_function()[/font] at the very beginning of my [font=Courier]init.php[/font] file and pass it the time. Then the shutdown function calculates the entire execution time and logs it to a file. Average is 23ms.

I compared load times between PHP5.3 and FastCGI and found that FastCGI was roughly 45ms faster. So I assume that the 45ms difference means the time to instantiate PHP? I don’t use FastCGI because load testing has shown that I get more errors, i.e. killed processes, at high loads. I assume this is because FastCGI uses more memory, but in my simple benchmarking, it only seems to use an extra 1MB or so.

These requests are all Ajax requests, so is it safe to assume that the remaining 320ms can be explained by the JavaScript? A friend who knows much more than I has suggested that it’s more likely to be latency within the DH network rather than JavaScript. So I compared the load times with an older, slower, version of the script I use now and according to Chrome’s developer tools, the longer JavaScript will show up as increased receiving time, not waiting time. The 320ms that I can’t account for is reported as waiting time, so maybe he’s right.

Does anyone have any ideas on some part of the process which could account for some of the latency?

I know, I know. 325ms is not much. But 95+ of the requests to my site are these Ajax requests, so even a 10% increase in speed is actually beneficial. I’ve already cut out about 250ms and reduced DB connections to 10% of what they were previously.

[code]167ms ping
23ms script
45ms load php
320ms JavaScript??? Dreamhost???

555ms total[/code]