User:Aaron Schulz/How to make MediaWiki fast
Appearance
- Use cache.
- To LocalSettings.php, add (replace paths as needed):
# Shared memory settings $wgMainCacheType = CACHE_ACCEL; $wgMessageCacheType = CACHE_ACCEL; $wgCacheDirectory = '<SOME DIRECTORY>'; $wgUseLocalMessageCache = true; $wgParserCacheType = CACHE_DB; $wgMemCachedServers = []; $wgUseGzip = true; $wgEnableSidebarCache = true; # NO DB HITS! $wgDisableCounters = true; $wgMiserMode = true; # Text cache $wgCompressRevisions = true; // use with care (see talk page) $wgRevisionCacheExpiry = 3*24*3600; $wgParserCacheExpireTime = 14*24*3600; # Diffs (defaults seem ok for Ubuntu and others) $wgDiff = 'C:/Server/xampp/htdocs/MW/bin/GnuWin32/bin/diff.exe'; $wgDiff3 = 'C:/Server/xampp/htdocs/MW/bin/GnuWin32/bin/diff3.exe';
- Set $wgCacheDirectory (above) for use with interface message caching. Make sure that the webserver has permission to make files there.
- Set up squid servers if possible. Otherwise, at least enable file caching.
- Set up Memcached if possible. If you do, set $wgMainCacheType and $wgParserCacheType to CACHE_MEMCACHED in LocalSettings.php instead. This is recommended if you have a cluster of servers.
- Run if you use file caching (not squids).
php maintenance/rebuildFileCache.php
- Set $wgJobRunRate to 0 and set up a crontab or shell script to run jobs (like this with this for example). With $wgJobRunRate at 0 and the above changes, you should be able to avoid db hits on many requests.
- Set $wgDiff and $wgDiff3 to gnu diff utility (download as needed). This is recommended. The default PHP diff code is slow and crashy.
- Edit the MediaWiki:Aboutsite and MediaWiki:Pagetitle system messages by changing {{SITENAME}} into your site name. This avoids extra parsing on each hit.
- If you really need hitcounters, use $wgHitcounterUpdateFreq instead of the $wgDisableCounters setting above.
- Set up a 404 handler for $wgLocalFileRepo. If not, then at least set $wgShowArchiveThumbnails = false.
- In the webserver's php.ini file. Make sure realpath_cache_size is set, perhaps to 512k or more.
- Consider enabling EnableMMAP and EnableSendfile in httpd.conf (for Apache). Please read the Apache docs for NFS and compatibility issues first.
- [MySQL] Set your mysql server config files to only use server modes corresponding to $wgSQLMode (default is "" for no modes). Restart the mysql server, and then set $wgSQLMode = null.
- If using SQLite, there are going to be many editors working at a time, and you are willing to sacrifice SERIALIZABLE atomic transactions (key parts of MediaWiki will still use them), you can add this to the bottom of LocalSettings.php:
$wgDBservers = array( array( // master 'host' => 'localhost', 'dbname' => $wgDBname, 'user' => $wgDBuser, 'password' => $wgDBpassword, 'type' => 'sqlite', 'load' => 0, 'flags' => 0 // no DBO_TRX (high write concurrency) ), array( // emulated replica 'host' => 'localhost', 'dbname' => $wgDBname, 'user' => $wgDBuser, 'password' => $wgDBpassword, 'type' => 'sqlite', 'load' => 100, 'flags' => DBO_TRX // REPEATABLE-READ for consistency ) );
- If using SQLite, run
php maintenance/sql.php
and executePRAGMA journal_mode=WAL;
. - If using SQLite with the default database job queue, move the
job
table to another sqlite database.- Open the current database via the
sqlite3
command line utility, run.schema job
, copy SQL the output, and quit (use ".quit"). - Make a new empty <YOUR MEDIAWIKI SQLITE DATA DIRECTORY>/job/<YOUR DB NAME>.sqlite file and open it in
sqlite3
. Paste in theCREATE TABLE
output from above and quit. This should create a new empty job table. - In LocalSettings.php, set:
$wgJobTypeConf['default']['cluster'] = 'job'; $wgExternalServers['job'] = [ [ 'type' => 'sqlite', 'dbname' => $wgDBname, 'dbDirectory' => '<YOUR MEDIAWIKI SQLITE DATA DIRECTORY>/job', 'load' => 1 ] ];
- Note: Schema updates will have to be manually applied if the main
job
table changes, asupdate.php
will not see this special database.
- Open the current database via the