次の実行時に奇妙なパフォーマンスの問題が発生しています:
- 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 )
これが DB の問題ではないことは確かです(実際の 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秒かかりますが、仮想マシンで試すと、約2秒かかります。同じことをするのに25秒。
問題は、これがすべて処理されている間に99% の負荷がかかっているApacheにあるように見えますが、実際に何が起こっているのかを特定するのは困難です。
どんな種類のアドバイスもいただければ幸いです...
アップデート
これは、データの書き込み時にのみ発生するようです。データの読み込みは問題ないようです。
Webgrind データ (スクリーンショット) が利用可能: https://www.dropbox.com/s/jjlg7ano6epy6t1/webgrind.png?dl=0