Performance is am extremely important topic on web applications. No visitor is likely to wait longer than 10 seconds to see a web page. For this reason a benchmark component was introduced to this framework. With the BenchmarkTimer component is is easy to controll the performance of an application or just a single module during development. The component measures all relevant parts by setting mesuring points within application parts and contains methods to display the process tree of the applications performance values. The page and front controller implementations already have included a lot of important measuring points to guarantee accurate performance tracking out-of-the-box. In example, the performance of each document controller is recorded by default.

1. Benchmarker practice

Benchmarking applications or parts of an application is quite easy. To measure a particural part of the code, the follwoing code must be introduced to the program:
PHP code
// start timer $t = &Singleton::getInstance('BenchmarkTimer'); $t->start('MyEvent'); // // code to be benchmark'ed // // stop timer $t->stop('MyEvent');
Please note, that the BenchmarkTimer must always be instanciated singleton style, because all timing information have to be stored in a single instance of the BenchmarkTimer to generate a proper process tree. If this is fact is not kept in mind, benchmark information might be lost. Further, the scope of applications must be considered. This means, that breakpoints throughout functions or classes determine, that the instance of the BenchmarkTimer must be fetched by using the Singleton class every time start() or stop() is called. In such situations, the following code can be used:
PHP code
// start timer $t = &Singleton::getInstance('BenchmarkTimer'); $t->start('MyEvent'); // // code to be benachmarked // // stop timer $t = &Singleton::getInstance('BenchmarkTimer'); $t->stop('MyEvent');
In most situations, this case is not necessary.

2. Benchmark reports

Due to the fact, that the present framework is written to operate in the so called post-back mode, the developer is able to easily integrate benchmark reporting in the central bootstrap file (mostly index.php). In the majority of cases it is adequate to place
PHP code
$t = &Singleton::getInstance('BenchmarkTimer'); echo $t->createReport();
at the end of the index.php file. If it is desired to not display benchmark information in the live system you might place the following code at the bottom of the index.php file:
PHP code
if(isset($_REQUEST['benchmarkreport']) && $_REQUEST['benchmarkreport'] == 'true'){ $t = &Singleton::getInstance('BenchmarkTimer'); echo $t->createReport(); }
This makes it possible to display benchmark information on demand by adding the parameter benchmarkreport=true to the current URL. In case of URL rewriting, the parameter must be rewrited to /benchmarkreport/true or /~/benchmarkreport/true for use in frontcontroller applications. If this parameter is present the following report will be displayed at the end of the HTML page:

benchmark report process tree
To view a live benchmark please click here.

3. Performance tweak

As of release 1.11 it is possible to deactivate the benchmarker. This can be used to reduce the time needed for request processing. Experimental tests proof, the request processing can be boosted on 25% with the benchmarker being deactivated. Because the benchmarker fulfils no necessary function in production environments, switching off the tool is not combined with any disadvantages.

Switching off the benchmarker can be done using the subsequent code snippet:

PHP code
$bench = &Singleton::getInstance('BenchmarkTimer'); $bench->disable();
In order to guarantee efficient disabling, the above presented lines of code should be directly placed after the inclusion of the page controller.


Do you want to add a comment to the article above, or do you want to post additional hints? So please click here. Comments already posted can be found below.
« 1   »
Entries/Page: | 5 | 10 | 15 | 20 |