phpBB: Creating communities twice as fast
Written by: Ladislav Prosek
With all those improvements that we have made to Phalanger v2.0, I was very curious about its performance. Many people suspected us for cheating when we claimed that Phalanger v1.0 can run common web applications twice as fast than if the PHP interpreter is used. That’s why I’m going to publish this article which explains all steps involved in my benchmarking rather than just the results. The procedure described here should be easily reproducible and I encourage you to try it yourself, maybe with different configuration - web server or database - and share your results. The web application of my choice is phpBB, because it is fairly widespread (chances are you have come across it on the Internet) and it is easy to install so even I can do it
I’d like to compare the latest PHP without any accelerators or encoders with Phalanger v1.0 (Final) and the latest Phalanger v2.0 (09-01-2006 Nightly at the time of writing). Obviously PHP is our rival but why do I include Phalanger v1.0? Unlike v2.0, the first version is no longer under development and we consider it quite stable. The Phalanger core has been heavily reworked in v2.0 and the impact on performance is still unknown. Including v1.0 should help us reveal potential issues. In another words, if v2.0 turns out to be slower than v1.0, then we screwed it up.
Ingredients
- My laptop - Pentium M Dothan 1.8 GHz, 1.5 GB RAM, Windows XP Pro SP2, IIS 5.1, .NET Framework v1.1.4322 and v2.0.50727. It would be better to use a real server system, but this is the fastest machine that I currently have.
- PHP 5.1.6 - Downloaded from http://www.php.net/.
- Phalanger - v1.0 downloaded from http://www.php-compiler.net/, v2.0 from CodePlex. In addition, I used the MySQL managed extension, which is available on CodePlex as a separate project.
- MySQL - I already had version 4.1.11 installed so I decided to get along without upgrading. Otherwise http://www.mysql.com/ would be the place to go.
- phpBB - Go to http://www.phpbb.com/ and grab the latest version. Mine is 2.0.21.
- Web Application Stress Tool - We need something to measure the performance. WAST looks a little obsolete but I quite like it. It can be downloaded from MS downloads.
Procedure
Install PHP and both Phalangers. Don’t forget the MySQL managed extension for Phalanger v2.0. Unpack the phpBB archive to a directory of your choice, retaining the subdirectory structure. Now configure IIS. I decided to create three virtual directories _/phpBB _ PHP_, _/phpBB _ Phalanger1_, and _/phpBB _ Phalanger2_ that will all point the same physical directory where phpBB has been unpacked. They will only differ in the handler mapping for .php files.
Configure IIS
Go to the IIS snap-in in Computer Management, and add a new virtual directory to a web site. Make sure you check the Execute (such as ISAPI applications or CGI) checkbox. Now go to the properties dialog and add index.php to the list of default documents on the Documents tab. On the Virtual Directory tab click Configuration and add a new mapping on the Mappings tab of the Application Configuration dialog that will pop up. Enter the following:
Executable: if this is the PHP virtual directory, enter full path to php5isapi.dll if this is the Phalanger v1.0 virtual directory, enter full path to _aspnet _ isapi.dll_, which is located in $WINDIR$\Microsoft.NET\Framework\v1.1.4322 if this is the Phalanger v2.0 virtual directory, enter full path to _aspnet _ isapi.dll_, which is located in $WINDIR$\Microsoft.NET\Framework\v2.0.50727
Extension: .php Close and save everything. Now IIS is properly configured but we still need to configure PHP and Phalangers.
Configure PHP
Copy and rename php.ini-dist to $WINDIR$\php.ini and make the following modifications: set _extension _ dir_ to full path to the ext subdirectory in the PHP installation enable (i.e. uncomment) the php_mysql.dll extension
Configure Phalanger
Phalanger does not use php.ini. Instead, you’ll need to create Web.config file in the directory where you’ve unpacked phpBB. Use Web1.config for v1.0 and Web2.config for v2.0 (do not forget to rename them to Web.config).
Set up DB
Make sure the database server is running and create a database named, say, phpBB. I just went to the MySQL Command Line Client and typed CREATE DATABASE phpBB;
Set up phpBB
Make the config.php file writable for everyone (it is located in the phpBB root directory). Point your browser to either _http://localhost/phpBB _ PHP_, _http://localhost/phpBB _ Phalanger1_, or _http://localhost/phpBB _ Phalanger2_. All three URLs should work at this point. Just remember that both versions of Phalanger use the same name Web.config for their configuration file so make sure you the correct one is in place. Follow the instructions to finish the phpBB installation.
Benchmark
I added one topic to the forum that was created automatically by phpBB during installation. So now I had one user (admin) and one forum with two topic, one post each. A typical visitor will probably come to the main page, then to the forum page, check out both topic, go to member list, pick the one user present there, and find all posts by this user. My stress script therefore looks like this (the Phalanger v2.0 version):
GET /phpBB_Phalanger2/index.php GET /phpBB_Phalanger2/viewforum.php?f=1 GET /phpBB_Phalanger2/viewtopic.php?t=1 GET /phpBB_Phalanger2/viewforum.php?f=1 GET /phpBB_Phalanger2/viewtopic.php?t=2 GET /phpBB_Phalanger2/memberlist.php GET /phpBB_Phalanger2/profile.php?mode=viewprofile?u=2 GET /phpBB_Phalanger2/search.php?search_author=admin
I had Web Application Stress Tool issue these localhost HTTP requests in sequence by one thread for 60 seconds with a 15 second warm-up. I noticed that regardless of the PHP-crunching engine used, there was a serious disk activity going on and the CPU load was not at 100%. Although all these requests are seemingly “read-only”, phpBB keeps information about recently active users etc. so there are probably some updates to the DB. The reason why MySQL performs such a huge amount of blocking I/O is not known to me. Anyway, I decided to compensate by increasing the number of threads that issue requests simultaneously. At a certain number of threads (10 was my limit due to the IIS 5.1 restriction) the CPU looked saturated. It is always a good idea to perform such a concurrency test to check whether there is not too much locking (performance would degrade) or too little locking (the server would eventually crash)
Results
The following graph shows the results of my benchmarking.
Horizontal axis denotes the number of threads used. Vertical axis denotes the number of requests processed by all threads in one second (on average). PHP was able to deliver a maximum performance of 6,9 requests per second when 8 client threads were used. Phalanger v1.0 had its peak also at 8 client threads but the performance was much higher - 11,18 requests per second. And the winner is Phalanger v2.0 with its 13,09 requests per second at 4 client threads.
Conclusion
This particular benchmark has shown that Phalanger v2.0 is almost twice as fast when compared to PHP 5.1.6. However, keep in mind that it was not only the PHP-crunching that ran on the machine during the benchmark. The database server and IIS were also under heavy load, and WAST does not run for free neither. Therefore the time consumed by Phalanger is likely to have been less than 50% of the time needed by PHP.
