Home » Forum
NoNumber!

Joomla!® Websites & Extensions
development  -  support  -  consultancy

I try to respond within 48 hours (excluding weekends).
If I haven't responded by then, feel free to post a reminder or bug me via email.

My last reply was: 2 Hours, 6 Minutes ago.

Welcome, Guest
Please Login or Register.    Lost Password?

Performance issue
(1 viewing) (1) Guest
Go to bottomPage: 1
TOPIC: Performance issue
#7104
Performance issue 1 Year, 12 Months ago  
Hi all,

first thing: The content templater is a very, very usefull addon I really like!

I tried to send this posting with the nonumber-contact-form but had no luck. ("you are not allowed to use this form" or similar...)

What I wanted to say: The templater has a major performance problem that would be easy to fix. I patched one model and got no problem any more. I thought, you nonumbers are possibly interested...

Following is written by memory - details may differ, the main thing should be clear.

The model coded in models/item.php utilizes a JParamter object that loads some xml data from a file on disk. Loading the file takes (on my testing system) about 0,03 seconds.

In a site with two jce-editor instances and a lot of templates, I count about 200 file accesses that cumulate to about 6 seconds. Another site takes more than 10 seconds just for opening the same file several hundred times. That's bad.

I patched the model in a simple way: Using a small factory class like the one in [1], and replaced following line in item.php:

$xml = new JParameter($params...)

=>
$xml = ParamFactory::getInstance($params)


After this modification, the templater works fast as hell.

Greets, Clemente

[1]
class ParamFactory {
   static $instance = null;

   static function getInstance($params, ...) {
      if ParamFactory::$instance == null {
            ParamFactory::$instance
      }
      return ParamFactory::$instance;
   }
}
Clemens
Posts: 5
User OfflineClick here to see the profile of this user
The administrator has disabled public write access.
 
#7105
Re: Performance issue 1 Year, 12 Months ago  
class ParamFactory {
   static $instance = null;

   static function getInstance($params, ...) {
      if ParamFactory::$instance == null {
            ParamFactory::$instance = new JParamter($params, ...)
      }
      return ParamFactory::$instance;
   }
}
Clemens
Posts: 5
User OfflineClick here to see the profile of this user
The administrator has disabled public write access.
 
#7112
Re: Performance issue 1 Year, 12 Months ago  
I don't see why this would improve performance.
Every time the $xml is created it is unique (different values).
So I don't understand why creating instances would be beneficial.

I have done some testing with your code and it actually uses up more php memory than the original (page load is a little faster, though).
Peter van Westen
Admin
Posts: 9091
User OfflineClick here to see the profile of this user
The administrator has disabled public write access.
Need to contact me directly? Go to my contact page.
If you use any NoNumber! extensions, please post a rating and a review at the Joomla! Extensions Directory.
Are you happy with the support? Please consider buying a License Code to help me to continue development and support.
 
#7221
Re: Performance issue 1 Year, 11 Months ago  
HI,

Every time the $xml is created it is unique (different values).
This is not what I observe
I just put following line in line 134 of item.php. Just before the $xml = new JParameter... stuff.

print ("File: ".$xmlfile."<br>");

The output generated is here: http://pastie.org/823008.
Every line there opens the following and obviously identical File:

administrator/components/com_contenttemplater/item_params.xml

You can count the lines and multiply your result with about 0.03 seconds...

What I suggest is:
Create only one instance of JParameter and consequently open the file only one time.

If running in debug mode, Joomla says following:
Time until reneered unpatched: About 6 seconds.
Time until rendered patches: 0,8 seconds.

As already written: The issue has only impact with a lot of templates active. In this situation, we use about 40 templates.

and it actually uses up more php memory
I didn't profile this - but I cannot believe that 1 instance can afford more memory than 200 instances of a class. Perhaps you did something wrong? I copy/paste my code below.

Somewhere out of the model class, best below. Starting at line 485:
class ParamFactory {
    
    static $instance = null;
    
    static function getInstance($ini, $xmlfile) {
        if (ParamFactory::$instance == null) {  
            ParamFactory::$instance = new JParameter( $ini, $xmlfile );
        }
        $result = ParamFactory::$instance;
        return $result;
    }
}


Lines 133 and 134:
//$xml = new JParameter( $ini, $xmlfile );
$xml = ParamFactory::getInstance($ini, $xmlfile);
Clemens
Posts: 5
User OfflineClick here to see the profile of this user
The administrator has disabled public write access.
 
#7222
Re: Performance issue 1 Year, 11 Months ago  
Hi again,

I just opened the same site unpatched and patched to see the memory usage. Joomla was in debug mode, results are copy/pasted direct from the html ouput.
Those number sprek for themselves - little less memory usage and less than 10% rendering time after patching...

Unpatched:
Profil zum Laufzeitverhalten
Application afterLoad: 0.002 seconds, 0.42 MB
Application afterInitialise: 0.135 seconds, 3.55 MB
Application afterRoute: 0.135 seconds, 3.55 MB
Application afterDispatch: 11.366 seconds, 7.87 MB
Application afterRender: 11.471 seconds, 8.88 MB
Speichernutzung
9358720


Patched:
Profil zum Laufzeitverhalten
Application afterLoad: 0.002 seconds, 0.43 MB
Application afterInitialise: 0.099 seconds, 3.55 MB
Application afterRoute: 0.099 seconds, 3.55 MB
Application afterDispatch: 0.812 seconds, 7.72 MB
Application afterRender: 0.924 seconds, 8.72 MB
Speichernutzung
9186620
Clemens
Posts: 5
User OfflineClick here to see the profile of this user
The administrator has disabled public write access.
 
#7234
Re: Performance issue 1 Year, 11 Months ago  
I didn't say the xml file is unique. I said the $xml var is unique.
The params is unique (in your function, the $ini). So what is returned to the $xml var is unique.

I'll do some more testing.
Peter van Westen
Admin
Posts: 9091
User OfflineClick here to see the profile of this user
The administrator has disabled public write access.
Need to contact me directly? Go to my contact page.
If you use any NoNumber! extensions, please post a rating and a review at the Joomla! Extensions Directory.
Are you happy with the support? Please consider buying a License Code to help me to continue development and support.
 
#7252
Re: Performance issue 1 Year, 11 Months ago  
PS: I am not trying to deny your advise.
Just trying to understand why it would make a difference.
My in depth knowledge on usage of classes is still flaky!
Peter van Westen
Admin
Posts: 9091
User OfflineClick here to see the profile of this user
The administrator has disabled public write access.
Need to contact me directly? Go to my contact page.
If you use any NoNumber! extensions, please post a rating and a review at the Joomla! Extensions Directory.
Are you happy with the support? Please consider buying a License Code to help me to continue development and support.
 
#7301
Re: Performance issue 1 Year, 11 Months ago  
Hi,

as written, the model in templater's ContentTemplaterModelItem uses its getXML() method very often while iterating over all templates (if I remember correctly)

If tracing what happens while constructing the JParameter instance, you see following:

- JParameter constructs a SimpleXML-object (class JParameter, line 351)
- JParameter then uses the SimpleXML to load a file and prepares its content for further work (class JParameter line 353)
- SimpleXML loads the content in class SimpleXML, line 177)

These steps are done every time, the templater constructs a JParameter-object. In my situation (40 templates, 4 editors) this is more than 200 times.
Point here is, that file system operations are very slow. No problem if loading one or two files, but if loading and parsing 200 files, latency is cumulating.

If you don't need different objects, or in other words, if you can do the work with one instance of of JParameter, you easily can reduce the discribed overhead by any mechanism that ensures that you only create one instance and use it whenever you need it.

This is a scenario for the factory-designpattern. And in fact the small factory I proposed uses a JParameter as singelton.

Greets, Clemente
Clemens
Posts: 5
User OfflineClick here to see the profile of this user
The administrator has disabled public write access.
 
#7303
Re: Performance issue 1 Year, 11 Months ago  
I sent you an email wth more questions...
Peter van Westen
Admin
Posts: 9091
User OfflineClick here to see the profile of this user
The administrator has disabled public write access.
Need to contact me directly? Go to my contact page.
If you use any NoNumber! extensions, please post a rating and a review at the Joomla! Extensions Directory.
Are you happy with the support? Please consider buying a License Code to help me to continue development and support.
 
Go to topPage: 1
Moderators: Peter van Westen
Open Source Training | Online Joomla! Training and Support
hosting joomla
MaxCDN | Content Delivery Network | Accelerate your site to the max