1

次の実行時に奇妙なパフォーマンスの問題が発生しています:

これが 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

4

2 に答える 2

1

これは答えではありませんので、アドバイスを目指します。仮想マシンは言うまでもなく、ローカル マシンで動作が遅くなるのは普通のことです。

役立つかもしれないもの:

  1. これをvagrantファイルに追加することで、仮想マシンのメモリを増やすことができます

config.vm.provider "virtualbox" do |v| v.customize ["modifyvm", :id, "--memory", "1024"] end

  1. zf2 モジュールZendDeveloperToolsも使用してください。これにより、リクエスト、ルーティング、データベース クエリ (doctrine で動作) にかかった時間が表示されます。また、実行速度が遅いものを特定できます。

そして、ただの補足です。12.04 で php 5.5 を実行しているのに、14.04 で実行していないのはなぜですか (信頼性は高いですが、それほど正確ではありません)。設定する方が簡単です。

于 2014-11-11T17:53:52.940 に答える