【发布时间】:2015-01-08 06:51:18
【问题描述】:
我们在运行时遇到了奇怪的性能问题:
- Zend Framework 2.3.3 PHP 5.5.18-1
- Doctrine MongoDB ODM 模块 (https://github.com/doctrine/mongodb, https://github.com/doctrine/DoctrineMongoODMModule)
- 通过Vagrant (https://vagrantcloud.com/hashicorp/boxes/precise64) 在 VirtualBox 上运行 Ubuntu 12.04
我们确定这不是数据库问题(用真正的 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 秒,但在 虚拟机 上尝试时,大约需要 5 秒。 25 秒 做同样的事情。
看起来问题可能出在 Apache,它在处理这一切时占用了 99% 的负载,但我很难确定到底发生了什么。
任何建议都将不胜感激......
更新
这似乎只在写入数据时发生。读取数据好像没问题。
Webgrind 数据(截图)可用:https://www.dropbox.com/s/jjlg7ano6epy6t1/webgrind.png?dl=0
【问题讨论】:
标签: php doctrine-orm zend-framework2 virtualbox doctrine-mongodb