Your premium source for custom modification services for phpBB


HomeForumsBlogMOD ManagerFAQSearchRegisterLogin

Comments March 1, 2008

Performance Tuning: Setting Up to Test Template Engines in phpBB2

Filed under: Performance Tuning, phpBB — Dave Rathbun @ 10:38 am Comments Off 

Our story so far…

I have a board with nearly 400K posts and 30K users. This board has paying sponsors which means I am able to afford a nice server to run it on. However, I am always looking for ways to tweak the code and get every tiny bit of performance that I can. My background is in databases, so naturally I started with the query logic and index structures and so on. I have a couple of posts so far (see Related Links) that show how I tested the performance impact of those tweaks. It was during that process that I discovered that my queries are not the problem.

It’s the parsing engine.

So what did I do next? I did what comes naturally, I started looking for options and trying to determine which was the best. Now “best” is normally a subjective matter. What is best for me might not be best for anyone else. So I will do my best :lol: to present the numbers and my testing methods and let the reader make their own conclusions. I will, of course, include my own opinions as well.

Parsing Engines for phpBB2

I have obtained four different parsing engines for phpBB2. (This series will focus on phpBB2 since I am still using that for my big board mentioned above. There is a slim chance that I will try to back-port the phpBB3 engine and see if I can include it in the next round of tests.) They are:

  • phpBB2 Standard
    This is the stock out-of-the-box template parsing system that comes with phpBB2. It provides the core functionality required to run your board.
  • phpBB2 Standard + Cache
    There is a caching version of the template engine available in the /contrib folder. That is not what I am using for my testing right now. What I am using is something offered to me for testing by a member of another board that I belong to. The idea behind the cache is that if the template layout doesn’t change from one page to the next, it doesn’t need to be regenerated. The only thing that needs to happen is to plug in the new page values. This engine does not add any features other than caching.
  • eXtreme Styles
    This is a very popular MOD by author CyberAlien. This MOD accelerates the parsing process but also provides quite a few other extensions to the standard template engine. It offers the ability to use php code within the template file. If offers a robust set of template / style management tools that are available via the Admin Control Panel (ACP). It also uses a cache.
  • Categories Hierarchy
    The template engine for Categories Hierarchy (CH) is not directly compatible with a standard phpBB2 installation. However, I was able to make a few changes and initially get it to work. The author of CH was also kind enough to do the same thing and provide his version of the files to me. I assumed that he knows how to do it properly (as opposed to my hacks) so I have used the version that he provided for the main testing. The CH template engine also uses a cache.

Of all of these different template engines, only the eXtreme Styles (XS) MOD requires that the filename be exactly template.php. In order to make the testing easy I renamed the other three files and placed all four template engines in the /includes folder. The files are phpbb_template.php, cache_template.php, and ch_template.php.

The Testing Environment

I thought for a while about how to best test these different template engines. My first test was done on my “live” server. I copied one of the template engines into the /includes folder and collected statistics using a process I will outline below. But this was done using one template engine at a time. That meant that the results were indicative of how well a template engine might perform, but could not be compared directly with each other. Why not? The server load (being a production system) would change from hour to hour. So my first decision was to offload my board and all of my test code to my home server.

My home server specs:
Dell Poweredge 800 Server
1 GB of RAM
P4 (single core) CPU
Mandriva Linux

I deactivated all background cron jobs on this server for the duration of the testing. Both the php and MySQL installations are sadly out of date, but also unfortunately they match what I currently have on my production server. Yes, I plan to upgrade. Soon. :)

I downloaded the most current version of my phpBB2 board. It contains all of the customizations that I have done over the years to optimize my queries. I took a database backup from my main board, and then deleted all of the posts except for one of the larger forums. That leaves me a test board with 24 forums with 10K topics and nearly 55K posts. It’s a decent amount of data, in my opinion.

The Testing Process

I certainly didn’t want to sit around and click “refresh” for several thousand pages. I also didn’t have access to any automated testing software packages. So what I did to run the test was make a few changes to the phpBB2 code, which I will detail here. I wanted to cycle through the template engines fairly quickly so that all of them would have the same amount of server load to contend with. Since I had four engines to test, I decided to run each of them for 15 seconds out of each minute. Since the template engine is included in common.php, here is the code that I added to that file.

$second = date('s', time());
if ($second <= 14)
        $tpl = 1;
        $tpl_name = 'phpbb';
        include($phpbb_root_path . 'includes/phpbb_template.'.$phpEx);
elseif ($second <= 29)
        $tpl = 2;
        $tpl_name = 'cache';
        include($phpbb_root_path . 'includes/cache_template.'.$phpEx);
elseif ($second <= 44)
        $tpl = 3;
        $tpl_name = 'xs';
        include($phpbb_root_path . 'includes/template.'.$phpEx);
        $tpl = 4;
        $tpl_name = 'ch';
        include($phpbb_root_path . 'includes/ch_template.'.$phpEx);
        include($phpbb_root_path . 'includes/class_template_compiler.'.$phpEx);

The $tpl code and the $tpl_name were used to tag the results when the time values were logged to a database table. As it turned out, I didn't use the $tpl number, only the $tpl_name value. I also had to remove (comment out) the line that is already in common.php to include the template engine.

Next, I added the following code to includes/page_header.php. This sets up a new template variable called {NEW_PAGE} and it is used to send my testing through a cycle of different pages. In my preliminary testing I found that some template engines performed better on some pages as compared to others. So I wanted to include four different pages in my test cycle. The pages I selected were index.php, viewforum.php, viewtopic.php, and memberlist.php. Here is what the code looks like:

$current_page_info = pathinfo($HTTP_SERVER_VARS['SCRIPT_NAME']);
$this_page_name = $current_page_info['basename'];

switch ($this_page_name)
        case 'index.php':
                        $next_page = 'viewforum.php?f=36';
        case 'viewforum.php':
                        $next_page = 'viewtopic.php?t=94705';
        case 'viewtopic.php':
                        $next_page = 'memberlist.php';
        default:        $next_page = 'index.php';

The $next_page variable is passed into the template along with the rest of the variables stored by this page.

        'NEXT_PAGE' => $next_page,
        'SITENAME' => $board_config['sitename'],
        'SITE_DESCRIPTION' => $board_config['site_desc'],
        'PAGE_TITLE' => $page_title,

So at this point I have set up an include that will load a different template engine every 15 seconds. I have set up a list of pages that I will cycle through. The final piece to make this work is setting up the automatic refresh, and that was done by editing the overall_header.tpl. I included this line:

<meta http-equiv="refresh" content="2;url={NEXT_PAGE}" />

That's all it took. Now when I point a browser to any page on my test server, the automatic refresh kicks in and send me to the {NEXT_PAGE}. The next page is changed each time I get to a new page using the code in includes/page_header.php. And every 15 seconds the template engine changes based on the code in common.php.

The final piece is logging the results. I created a table to store the values, and added an insert statement to includes/page_tail.php to store the values. I capture the total page time, the total SQL time (using techniques outlined in prior posts), and the total parse time. The parse time is captured using these lines of code for each of my pages:

$page_parse_start_microtime = microtime();
$page_parse_time = microtime_duration($page_parse_start_microtime, microtime());

The insert statement from includes/page_tail.php:

$sql = "INSERT INTO cache_test (row_id, tpl, trial_number, pagename, sql_time, parse_time, page_time) values (NULL, '$tpl_name', 5, '$this_page_name', $sql_time, $page_parse_time, $page_generation_time)";


The number "5" is updated each time I run a new set of time trials. So far, as you can see, I have run 5 trials. :-) Once I have all of these code changes made all I have to do to test is start a browser and it will sit there and refresh pages until I either close the browser or change the template header to remove the meta refresh directive. This has worked very well.

Plus it's really fun to watch 20 different browser windows refreshing pages automatically. :lol:

The next step is to set up different trials and capture the statistics and see what sort of conclusion I can draw from the numbers. But that's a topic for another post.

Related Links

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Powered by WordPress