Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Last revision Both sides next revision
litespeed_wiki:cache:no-plugin-mediawiki [2017/09/13 14:16]
Usman Nasir created
litespeed_wiki:cache:no-plugin-mediawiki [2017/10/10 16:53]
Usman Nasir
Line 5: Line 5:
 Below are some recommended configurations to enable LSCache and get it working with your MediaWiki site(s). Below are some recommended configurations to enable LSCache and get it working with your MediaWiki site(s).
  
-===== Configure Server/​Virtual-Host-Level Cache Root And Cache Policy ​=====+===== MediaWiki ​=====
  
-Server/​Virtual-Host-level cache storage needs to be configured properly for your environmentSelect your server setup from the **Web Server Configuration** section of our [[litespeed_wiki:​cache:​common_installation#​web_server_configuration|LiteSpeed Cache Installation Guide]] and follow the instructions to set the server/​virtual-host-level cache root and cache policy.+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 databaseIt is fairly popular wiki application on the web.
  
-===== Rewrite rules =====+===== MediaWiki Cache =====
  
-At the ''​.htaccess''​ file in the document root of your website after +With its complexity, page rendering usually takes timeTo 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
-  # Various rewrite rules+  ​ 
-  ​<​IfModule mod_rewrite.c>​+====LiteSpeed Cache + MediaWiki====
  
-Add the following rewrite rules:+ 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.
  
-  ########## Begin - Litespeed cache +As everyone may know, LiteSpeed ​webserver (LSWS) cache bypasses php invocation and serves cached page directly from LSWS cacheHence 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.
-  <​IfModule LiteSpeed>​ +
-    <​IfModule ​LiteSpeed+
-     ​RewriteEngine On +
-     ​CacheDisable public / +
-     ​RewriteCond %{HTTP_COOKIE} !mediawiki_wiki__session +
-     ​RewriteCond %{HTTP_COOKIE} !mediawiki_wiki_UserID +
-     ​RewriteRule ​.* - [E=cache-control:max-age=120] +
-</IfModule>​ +
-  </IfModule>​ +
-  ########## End - Litespeed cache +
-   +
-====Notes====+
  
-  * The ''​CacheDisable public /''​ directive is used to help protect against globally-enabled caching and is optionalIf this directive is not used, the server'​s global cache settings should be checked ​to ensure that cache is not enabled globally. **Do NOT** use ''​CacheEnable public /''​ here as it will enable caching for all URLs belonging ​to this virtual host, including admin pages.  +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.
-  * We recommend using a different domain for your backend so that you can add/​edit/​preview a website'​s content through the admin domain without worrying about these changes being cached ​and seen by visitors. +
-  * To get the non-cached version of a pageadd the ''?​nocache'' ​query string ​to a URL.+
  
-For example:+That said, we come up with a simple set of rewrite rules in .htaccess for page caching as follows:
  
 <​code>​ <​code>​
-https://​www.your_domain_name.com/​about?​nocache ​ +RewriteEngine On 
-https://www.your_domain_name.com/​about?​some_other_query_string&​nocache+ 
 +RewriteCond %{REQUEST_METHOD} ^HEAD|GET$ 
 +RewriteCond %{HTTP_COOKIE} !wikidbUserID 
 +RewriteCond %{QUERY_STRING} ^$ 
 +RewriteRule ​.* - [E=Cache-Control:​max-age=300,​L]
 </​code>​ </​code>​
 +
 +**
 +Explanation:​**
 +
 +  - Cache HEAD and GET requests
 +  -     For cookie that does NOT contain "​wikidbUserID"​. (anonymous visitors)
 +  -     ​Request does NOT contain query string
 +  -     Cache TTL is set to 300 seconds (5mins).
 +
 +
 ===== Verify Cache Setup ===== ===== Verify Cache Setup =====
  
-Look for ''​X-LiteSpeed-Cache: ​hit'' in the reply headers as shown below[[litespeed_wiki:cache:no-plugin-setup-guidline#​verify_that_pages_are_served_from_the_cache|See more detailed directions here]].  +If a resource is served from LSWS cache, the server response header contains ​'​X-LiteSpeed-Cache: ​Hit'. 
-===== Deleting Outdated ​Cache Files Using A Cron Job =====+ 
 +<​code>​ 
 +GET /​mediawiki/​index.php/​Main_Page HTTP/1.1 
 +Host192.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=
 +Last-Modified:​ Thu, 10 Feb 2011 05:14:38 GMT 
 +</​code>​ 
 + 
 +===== 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** 
 + 
 +<​code>​ 
 +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) 
 +</​code>​ 
 +** 
 +Varnish + LSWS (cache disabled) + MediaWiki** 
 + 
 +<​code>​ 
 +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) 
 +</​code>​ 
 + 
 +**LSWS Cache + Mediawiki** 
 + 
 +<​code>​ 
 +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) 
 +</​code>​
  
-Please refer to [[litespeed_wiki:​cache:​no-plugin-setup-guidline#​deleting_outdated_cache_files_using_a_cron_job|this wiki]] to learn how to clean up outdated cache files.+As shown, LSWS Cache + MediaWiki is ~150% faster than Varnish + MediaWiki.
  • Admin
  • Last modified: 2017/10/10 17:38
  • by Johathan Kagan