我对加载类别route=product/category
中所有产品的脚本进行了一些基准测试。我在整个脚本中插入了一些微时间函数,得到了以下结果:
Array
(
[0] => 1386295629.1175
[1] => 1386295629.1556
[2] => 1386295629.1562
[3] => 1386295629.1562
[4] => 1386295629.4826
[5] => 1386295629.49
[6] => 1386295629.4908
[7] => 1386295629.491
)
从开始到结束,加载整个页面的数据需要0.3735秒。这包括所有SQL查询和图像大小调整(如果需要)。我在这个页面上运行了基准测试:
http://www.hollywoodcollectibles.com/baseball/autographed-baseball-balls
您会注意到,加载该页面需要10秒以上的时间,而大部分时间都用于请求而非响应。因此,瓶颈实际上根本不在SQL中。大多数其他类别的产品数量较少,根本没有遇到这种瓶颈。
我运行了另一个基准测试,这次测量了呈现实际输出$this->response->setOutput($this->render());
所需的时间
Array
(
[0] => 1386296946.8589
[1] => 1386296964.206
)
现在,我们正在取得进展。Opencart花了17.34秒来呈现输出。
在这之后,我迷失了方向。有人能告诉我$this->render()
函数在Opencart中的位置吗?并可能给我任何其他关于在哪里查找瓶颈的建议吗?
我不知道这是否会对您有所帮助,但该函数在system/engine/controller.php
中
protected function render() {
foreach ($this->children as $child) {
$this->data[basename($child)] = $this->getChild($child);
}
if (file_exists(DIR_TEMPLATE . $this->template)) {
extract($this->data);
ob_start();
require(DIR_TEMPLATE . $this->template);
$this->output = ob_get_contents();
ob_end_clean();
return $this->output;
} else {
trigger_error('Error: Could not load template ' . DIR_TEMPLATE . $this->template . '!');
exit();
}
}
system/library/pagination.php
中还有另一个函数render(),但我认为这只是为了分页。