使 PHP 性能分析可预测 [英] Making PHP performance profiling predictable
问题描述
我正在使用 xdebug 和 PHP 进行一些性能分析.但是当我不止一次运行同一个脚本时,我经常得到非常不同的时间.所以很难知道对结果有多大信心.
I'm using xdebug with PHP to do some performance profiling. But when I run the same script more than once, I often get very different times. So it's hard to know how much faith to put in the results.
很明显,一台机器上发生的很多事情都会影响 PHP 的性能.但是我能做些什么来减少变量的数量,从而使多个测试更加一致?
Obviously there's a lot happening on a machine that can affect PHP's performance. But is there anything I can do to reduce the number of variables, so multiple tests are more consistent?
我在 Mac OS X 上的 Apache 下运行 PHP.
I'm running PHP under Apache, on Mac OS X.
推荐答案
- 尽可能减少盒子上无关服务的数量.
- 减少 Apache 进程的数量.
- 通过多次加载脚本来准备各种缓存.可能使用 Apache 的
ab
或siege
等基准测试工具>,以确保所有 Apache 子进程都被命中. - 使用
curl
或wget
从命令行分析您的脚本,以便 Apache 只提供一种资源:脚本本身.
- Reduce the number of unrelated services on the box as much as possible.
- Cut down on the number of Apache processes.
- Prime the various caches by loading your script a few times. Possibly use a benchmarking tool like Apache's
ab
orsiege
, to make sure all Apache children are hit. - Profile your script from the command line using
curl
orwget
so that Apache only serves one resource: the script itself.
通过省略其中一些步骤来获得更多真实世界"数字可能存在争议.我期待着这个问题可能会得到其他答案.
There may be an argument for getting more "real world" numbers by omitting some of these steps. I look forward to other answers this question may receive.
这篇关于使 PHP 性能分析可预测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!