LiteSpeed Cache + Mediawiki

webizen

Well-Known Member
#1
MediaWiki

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.

MediaWiki Cache

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).

Verification

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
Benchmarks

Follow the guide (http://www.mediawiki.org/wiki/Manual:Varnish_caching), we have Varnish set up on port 2080 in front of LSWS which serves MediaWiki.

AB test results are as follows:

LSWS (cache disabled) + MediaWiki

Server Software: LiteSpeed/4.0.20
Server Hostname: 192.168.0.56
Server Port: 8088

Document Path: /mediawiki/index.php/Main_Page
Document Length: 11184 bytes

Concurrency Level: 10
Time taken for tests: 0.910418 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 1152000 bytes
HTML transferred: 1118400 bytes
Requests per second: 109.84 [#/sec] (mean)
Time per request: 91.042 [ms] (mean)
Time per request: 9.104 [ms] (mean, across all concurrent requests)
Transfer rate: 1235.70 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.5 0 3
Processing: 9 85 41.5 76 188
Waiting: 6 68 33.8 60 148
Total: 9 85 41.4 76 188

Percentage of the requests served within a certain time (ms)
50% 76
66% 98
75% 119
80% 131
90% 151
95% 161
98% 180
99% 188
100% 188 (longest request)
Varnish + LSWS (cache disabled) + MediaWiki

Benchmarking 192.168.0.56 (be patient).....done


Server Software: LiteSpeed/4.0.20
Server Hostname: 192.168.0.56
Server Port: 2080

Document Path: /mediawiki/index.php/Main_Page
Document Length: 11184 bytes

Concurrency Level: 10
Time taken for tests: 0.164568 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 1168144 bytes
HTML transferred: 1122290 bytes
Requests per second: 607.65 [#/sec] (mean)
Time per request: 16.457 [ms] (mean)
Time per request: 1.646 [ms] (mean, across all concurrent requests)
Transfer rate: 6927.23 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 4 1.5 4 9
Processing: 7 10 2.4 10 19
Waiting: 1 4 1.4 4 9
Total: 8 14 3.1 15 25

Percentage of the requests served within a certain time (ms)
50% 15
66% 16
75% 16
80% 16
90% 18
95% 21
98% 25
99% 25
100% 25 (longest request)
LSWS Cache + Mediawiki

Server Software: LiteSpeed/4.0.20
Server Hostname: 192.168.0.56
Server Port: 8088

Document Path: /mediawiki/index.php/Main_Page
Document Length: 11184 bytes

Concurrency Level: 10
Time taken for tests: 0.67117 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 1168267 bytes
HTML transferred: 1129584 bytes
Requests per second: 1489.94 [#/sec] (mean)
Time per request: 6.712 [ms] (mean)
Time per request: 0.671 [ms] (mean, across all concurrent requests)
Transfer rate: 16985.27 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 1.6 1 7
Processing: 0 4 2.2 4 10
Waiting: 0 1 1.2 1 4
Total: 0 5 2.7 5 15

Percentage of the requests served within a certain time (ms)
50% 5
66% 6
75% 7
80% 7
90% 9
95% 11
98% 12
99% 15
100% 15 (longest request)
As shown, LSWS Cache + MediaWiki is ~150% faster than Varnish + MediaWiki.
 
Last edited:
Top