[TYPO3-mvc] DataMapper performance issue.

Braulio J. Solano-Rojas braulio at solsoft.biz
Fri Mar 30 01:55:58 CEST 2012


Hi!

El 27/03/2012 07:33 a.m., Bastian Waidelich escribió:
> Braulio José Solano Rojas wrote:
>
> Hi Braulio José Solano Rojas (wow, I love that name!),

Hey, thank you very much!  I love it too!  (Not just because it is my 
name. Braulio Carillo Colina is usually called by our historians the 
architect of the costarican State and my parents decided to give me the 
first name Braulio in his honor, it is not a very common first name).

>> I've been having performance issues with one app made on extbase.
>> [...] The call tree is incredibly deep.
>
> Thanks for the detailed report!
> It would be interesting to see your domain model and/or the queries you
> call.

Of course.  In fact, I was thinking that my report was not descriptive 
enough and I was going to send another email.

The action that does that is a randomArticles action in an articles 
controller:

     public function randomArticlesAction() {
         $lastEdition = $this->editionRepository->findLast();
         if ($lastEdition) {
             $lastEditionArticles = $lastEdition->getArticles()->toArray();
             shuffle($lastEditionArticles);
             $randomArticles = array();
             for ($i=0; ($i<$this->settings['randomArticles']) && 
($i<count($lastEditionArticles)); $i++) {
                 $randomArticles[] = $lastEditionArticles[$i];
             }
             $this->view->assign('edition', $lastEdition);
             $this->view->assign('randomArticles', $randomArticles);
             $this->view->assign('contentPageUid', 
$this->settings['contentPageUid']);
         }
     }

There is an edition repository that has the method findLast above:

     public function findLast() {
         $query = $this->createQuery();
         $editions = $query->matching($query->equals('lastEdition', 1))
             ->setOrderings(array('crdate' => 
Tx_Extbase_Persistence_QueryInterface::ORDER_DESCENDING))
             ->setLimit(1)
             ->execute();
         return (count($editions) == 0) ? NULL : $editions->getFirst();
     }

getArticles is just a method of the edition model:

     public function getArticles() {
         return $this->articles;
     }

The edition model has the following properties:

     /**
      * Creation date
      * @var integer
      */
     protected $crdate;

     /**
      * Editorial
      * @var string
      * @validate NotEmpty
      */
     protected $editorial;

     /**
      * Volume
      * @var integer
      * @validate NotEmpty
      */
     protected $volume;

     /**
      * Number
      * @var string
      * @validate NotEmpty
      */
     protected $number;

     /**
      * Month
      * @var string
      * @validate NotEmpty
      */
     protected $month;

     /**
      * Year
      * @var integer
      * @validate NotEmpty
      */
     protected $year;

     /**
      * Is this the last edition?
      * @var boolean
      * @validate NotEmpty
      */
     protected $lastEdition;

     /**
      * Articles
      * @var 
Tx_Extbase_Persistence_ObjectStorage<Tx_Magazine_Domain_Model_Article>
      */
     protected $articles;

The article model has the following properties:

     /**
      * Article title.
      * @var string
      * @validate NotEmpty
      */
     protected $title;

     /**
      * Subjects
      * @var 
Tx_Extbase_Persistence_ObjectStorage<Tx_Magazine_Domain_Model_Subject>
      * @lazy
      */
     protected $subjects;

     /**
      * Abstract
      * @var string
      */
     protected $abstract;

     /**
      * English abstract
      * @var string
      */
     protected $englishAbstract;

     /**
      * Article PDF
      * @var string
      * @validate NotEmpty
      */
     protected $file;

     /**
      * Edition
      * @var Tx_Magazine_Domain_Model_Edition
      */
     protected $edition;

     /**
      * Category
      * @var Tx_Magazine_Domain_Model_Category
      */
     protected $category;

     /**
      * Authors
      * @var 
Tx_Extbase_Persistence_ObjectStorage<Tx_Magazine_Domain_Model_Person>
      */
     protected $authors;

> Did you try using @lazy annotations in your models? Otherwise Extbase
> will always fetch all related objects.

I did not.  I am going to be more @lazy.  :-D

> Apart from that: Can't you cache the output of your extension? (And I
> know that this can't be the solution to everything, but I've seen a lot
> of uncached Extbase plugins where it wasn't needed)

I can.  In fact I am using the Netcreators Static Cache extension. 
However, for that specific action I can't because it is the front page 
of a magazine and the user requirements were that this page had to have 
four random article headers.  I forbade to cache that action in my 
extension's localconf.  You can see the effect at 
http://revista.inie.ucr.ac.cr/.

Still, my analysis shows that the call nesting is huge.  Those methods I 
sent in the data table are being called too much from my point of view. 
  I do not understand why.  It is like it was a recursive solving... but 
very deep.  I am guessing extbase recalculates things it already has 
calculated.  Is it because edition is a property of each article and 
articles are a property of each edition?  By the way, the numbers are 
from running the action in my laptop.  In the server the times are less 
but proportional.  It is still a slow loading for a web page.

I am going to use @lazy in properties that are objects or object 
collections to see if it solves the performance impact.

In a related subject, what is the effect of using the caching framework? 
  Will it cache only objects from queries or will it cache output too?

Thanks in advance.

Bests,

B.




-- 
Director General
Solsoft de Costa Rica
Inteligencia Artificial... en su Negocio
http://solsoft.biz/
http://www.facebook.com/solsoft
http://www.linkedin.com/company/solsoft-de-costa-rica-s.a./

"The two parties which divide the State, the party of Conservatism and 
that of Innovation are very old, and have disputed the possession of the 
world ever since it was made ... Now one, now the other gets the day, 
and still the fight renews itself as if for the first time, under new 
names and hot personalities ... Innovation is the salient energy; 
Conservatism the pause on the last movement."

Ralph Waldo Emerson


More information about the TYPO3-project-typo3v4mvc mailing list