PHP Caching solutions and performance

You can run a MediaWiki wiki with "only" the core functionality on very modest hardware and software and it will be reasonably "fast". Once you start adding the extensions you need your wiki will get a bit slower but depending on the hardware used you probably won't even notice this. There are ways to make your wiki faster and once your there you don't want to go back. This page tries to describe some of the basics on how to make your wiki faster. This page is not the holy grail of "wiki performance" but it will get you going.

A typical SMW wiki could be one that holds tons of data, with lots of templates in combination with a lots of parser functions that drive the "PARSER" nuts. To please your users so they can maintain their data with ease so you are also using SF with multiple instance templates. In such a case you can speed up your Wiki using one of the solutions below. It is wise to try out different configurations and setups on a test server. If you try to setup and test the options below on a "life" server you are asking for trouble.

When using SMW your web server will be configured to use PHP. Because PHP is a scripting language your server needs to compile the PHP code first and then do its magic and show you the page requested. While you may think it does that rather fast in most cases you could increase your servers performance a lot. Most of the PHP code for MW and SMW will not change, it is static so what PHP caching does is storing the compiled PHP code and execute that directly the next time you request that page which holds the code. There are several solutions that all work and have there pros and cons.

XCache
XCache is being developed by the "people" of the lighttpd webserver software.

Pros:
 * Supports object caching in Mediawiki
 * Reliable and stable
 * Well maintained and documented
 * Multi OS support
 * Is fast in combination with object caching.

Cons:
 * Object caching not working when PHP is running in CLI mode.
 * Is relatively "slow" when object caching is not used.

Installing XCache:

How to install and setup php.ini please read the documentation.

php configuration
Below is a working example configuration for php used on a SMW wiki. Depending on how many wiki's you have and/or how many extensions you use you need to tune the memory size used. You can do this via the monitoring page provided.

LocalSettings.php configuration
If you want to make use of the object caching supported by XCache you need to enable this in your localSettings.php file. Because object caching does not work with PHP in CLI mode you could add the code below which checks if PHP is running in CLI mode and when it does it will revert to  instead of using the object caching from XCache. There are probably better solutions but this one works and is simple.

Zend Opcache
Is included in PHP 5.5 and later. For documentation read this. To monitor Zend OPCache performance you could use one of the following solutions, Opcache-Status by Rasmus Lerdorf or opcache-gui by amnuts.

Pros:
 * Part of PHP 5.5
 * Enabled by default. Easy to setup
 * Stable

Cons:
 * You need to update PHP to at least 5.5
 * No object caching

HHVM
HHVM stands for Hip Hop Virtual Machine. When you have your web server running on Linux and especially Ubuntu this is one of the faster solutions. It basically does the same thing as the others but it uses JIT (Just In Time) compiler which compiles the PHP code to machine language. If you are interested in the details on why and how read this on the HHVM webside. When you are using Linux as an OS to run your wiki this is an option you want to take a look at. Also the combination with SMW seems to be working very well.

Pros:
 * Very fast
 * Supports object caching in Mediawiki
 * Easy to setup

Cons:
 * Initial "cold start" is relatively slow
 * It is x86-64 only
 * Runs on Linux only (Ubuntu)
 * Is a magic "black box"
 * HHVM is faster with "optimized" PHP code. Extensions may need an update to take the full advantage
 * Object caching not working when PHP is running in CLI mode.
 * No encrypted email out of the box! (cee bug 1647).

Installing HHVM:

How to install please read the documentation on the HHVM site.

LocalSettings.php configuration
You can make use of the APC object caching when using HHVM you need to enable this in your localSettings.php file. Because object caching does not work with PHP in CLI mode you could add the code below which checks if PHP is running in CLI mode and when it does it will revert to  instead of using the object caching from APC. There are probably better solutions but this one works and is simple.

= Conclusions on measurements below = These "conclusions" are not for "high traffic" wikis that get 1000 hits per second. They are for "low traffic" wikis where you and some other people browse and edit a wiki all at the same time. High traffic Wikis use the same software but there is a lot more tuning to do to be able to serve that many people at the same time. That is not the scope of this document. The measurements taken for this test are done by pressing F5 multiple times until you have a average number that makes sense, rounded to 0.05 s, noting smaller. But fractions of a second do count on high traffic sites. No science just common sense.


 * 1) When you have very powerful hardware which you are the soul user of you will probably not notice the difference between not doing any PHP caching and using PHP caching.
 * 2) When you are not using PHP caching on your current server which is relatively "old" you can make it as fast or faster with PHP caching compared to a new server without PHP caching.
 * 3) When navigating trough a PHP cached wiki there is no real noticeable difference between the Intel i7 and the AMD A8 systems tested in this document. This is because of browser caching and other magic happening.
 * 4) PHP caching has more noticeable impact on "older" (slower) hardware.
 * 5) HHVM with object caching enabled is by far the fastest solution.
 * 6) There is almost no performance penalty for a SMW wiki with HHVM with enabled object caching.
 * 7) Editing really shines on HHVM with object caching.
 * 8) When using XCache with object caching enabled you can even run your SMW wiki on a Raspberry PI. It will become as fast as your really "old" server that does not use any PHP caching. It is a shame HHVM is 64 bits only.

= Measurements = Browser used to measure the times was Chromium, Version 39.0.2171.65 on Ubuntu Desktop 14.04 (64-bit). The browser cache was enabled and pages where refreshed with F5. All times are average load times. The measurements where done on 4 different configurations. On all wikis the WikiEditor was enabled and used.