我们在运行时遇到了奇怪的性能问题:
- PHP 5.5.18-1 上的Zend Framework 2.3.3
- Doctrine MongoDB ODM 模块 ( https://github.com/doctrine/mongodb , https://github.com/doctrine/DoctrineMongoODMModule )
- 通过Vagrant在 VirtualBox 上运行 Ubuntu 12.04 ( https://vagrantcloud.com/hashicorp/boxes/precise64 )
我们确定这不是数据库问题(用真正的 MongoDB 实例尝试过,结果仍然相同)。
设想
我们以类似于以下的方式定义了与 Doctrine ODM 一起使用的对象:
<?php
namespace CatalogueManager\Document;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
use Doctrine\Common\Collections\ArrayCollection;
/*
* @ODM\Document(repositoryClass="CatalogueManager\Repository\ProductRepository")
*/
class Item
{
/** @ODM\Id */
protected $id;
/** @ODM\String */
protected $name;
/** @ODM\Timestamp */
protected $created;
/** @ODM\Timestamp */
protected $updated;
// ---------------------------------------------------------------------- //
/**
* Return properties as an array. Helper method to assist with converting
* doctrine objects to arrays so we can return front-end api calls as json.
*
* Required as currently Doctrine ODM do not support array hydration of
* referenced documents.
*
* @access public
* @return array
*
*/
public function toArray()
{
$arr = ['id' => $this->id,
'name' => $this->name,
'urlSlug' => $this->urlSlug,
'desc' => $this->desc,
'metaData' => $this->metadata,
'category' => $this->category,
'brand' => $this->brand,
'assets' => $this->assets,
'shipping' => $this->shipping,
'specs' => $this->specs,
'attrs' => $this->attrs,
'optionTypes' => $this->optionTypes
];
return $arr;
}
// ---------------------------------------------------------------------- //
/**
* Getter
*
* @access public
* @return string
*
*/
public function getId()
{
return $this->id;
}
/**
* Getter
*
* @access public
* @return string
*
*/
public function getName()
{
return $this->name;
}
// ---------------------------------------------------------------------- //
/**
* Setter
*
* @param string $value Property value
*
* @access public
* @return void
*
*/
public function setName($value)
{
$this->name = $value;
}
}
我们使用这些来导入大约。100 个产品进入产品数据库。这一切在真机上大约需要 5 秒,但在虚拟机上尝试时,大约需要。25秒做同样的事情。
看起来问题可能是Apache在处理这一切的过程中占用了99% 的负载,但我很难确定到底发生了什么。
任何形式的建议将不胜感激......
更新
这似乎只在写入数据时发生。读取数据似乎没问题。
Webgrind 数据(截图)可用:https ://www.dropbox.com/s/jjlg7ano6epy6t1/webgrind.png?dl=0