LSCache + MediaWiki Configuration

LSCache, similar to Varnish cache, is a simpler and more efficient page-caching solution built in to LiteSpeed Web Server. When used in conjunction with MediaWiki, you can expect significant performance gains and a quick and easy setup. Cache management is also made significantly easier and more flexible with the ability to use rewrite rules to customize cache behavior.

Below are some recommended configurations to enable LSCache and get it working with your MediaWiki site(s).

MediaWiki is a free software open source wiki package written in PHP, originally for use on Wikipedia (the free encyclopedia). It is a feature-rich wiki implementation, that uses PHP to process and display data stored in its MySQL database. It is fairly popular wiki application on the web.

With its complexity, page rendering usually takes time. To mitigate these costs, many caching solutions have been brought up and implemented. This page (http://www.mediawiki.org/wiki/Manual:Cache) gives a good overview of caching in mediawiki. Among them, page caching is the one with the most performance gain. Varnish/Squid + Mediawiki is good combination. This page (http://www.mediawiki.org/wiki/Manual:Varnish_caching) talks setup varnish with Mediawiki in details.

LiteSpeed Cache + MediaWiki

We here in LiteSpeed have implemented a very simple page caching solution using LiteSpeed built-in cache for MediaWiki. Below we will outline the implementation in details and provide benchmarks with Varnish cache in the end.

As everyone may know, LiteSpeed webserver (LSWS) cache bypasses php invocation and serves cached page directly from LSWS cache. Hence a much bigger performance improvement can be achieved. The general guideline of using LSWS cache is available at http://www.litespeedtech.com/support/forum/showthread.php?t=4719. Unlike Varnish, it is built into LiteSpeed web server, eliminating one layer of reverse proxy. Hence more efficient for static contents.

In MediaWiki, everything going through index.php for processing. Using the guideline “A general way to enable LiteSpeed Cache through rewrite rules is to designate a signature token (such as cookie) in a page (or any page) in most cases to tell LSWS that cache can be enabled and TTL(Time To Live) of the cache freshness however acceptable. ”, we find out that, for anonymous visitors (people who don’t log in to the site), any page with no query string in URL is cacheable using LiteSpeed cache.

That said, we come up with a simple set of rewrite rules in .htaccess for page caching as follows:

RewriteEngine On

RewriteCond %{REQUEST_METHOD} ^HEAD|GET$
RewriteCond %{HTTP_COOKIE} !wikidbUserID
RewriteCond %{QUERY_STRING} ^$
RewriteRule .* - [E=Cache-Control:max-age=300,L]

Explanation:

  1. Cache HEAD and GET requests
  2. For cookie that does NOT contain “wikidbUserID”. (anonymous visitors)
  3. Request does NOT contain query string
  4. Cache TTL is set to 300 seconds (5mins).

If a resource is served from LSWS cache, the server response header contains 'X-LiteSpeed-Cache: Hit'.

GET /mediawiki/index.php/Main_Page HTTP/1.1
Host: 192.168.0.56:8088
User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Cookie: wikidb_session=ef3itaapmrdiqenjq9am4e8qv0;
X-lori-time-1: 1298698098105

HTTP/1.1 200 OK
Content-Encoding: gzip
Vary: Accept-Encoding, Accept-Encoding, Cookie
Date: Sat, 26 Feb 2011 05:28:18 GMT
Server: LiteSpeed/4.0.20 Enterprise
Connection: Keep-Alive
Keep-Alive: timeout=5, max=100
X-LiteSpeed-Cache: hit
Content-Length: 3993
X-Powered-By: PHP/5.2.17
Content-Type: text/html; charset=UTF-8
Content-Language: en
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Cache-Control: private, must-revalidate, max-age=0
Last-Modified: Thu, 10 Feb 2011 05:14:38 GMT
  • Admin
  • Last modified: 2017/10/10 17:38
  • by Johathan Kagan