Server rental store

Performance Optimization

# Performance Optimization

This article details server configuration options for improving the performance of a MediaWiki 1.40 installation. Optimizing performance is crucial for a positive user experience, especially as your wiki grows. We’ll cover database optimization, caching strategies, and web server tuning. This guide is aimed at system administrators and those familiar with server configuration.

1. Database Optimization

The database is often the biggest bottleneck in a MediaWiki installation. Choosing the right database and configuring it correctly are vital. We will focus on MySQL/MariaDB, as they are the most common choices.

1.1 Database Engine

InnoDB is the recommended storage engine for MediaWiki. It provides transaction support and better data integrity than MyISAM.

1.2 Key Configuration Variables

Here are some key MySQL/MariaDB variables to tune:

Variable Description Recommended Value
`innodb_buffer_pool_size` The size of the buffer pool, which caches data and indexes in memory. 50-80% of available RAM
`innodb_log_file_size` The size of each InnoDB log file. Larger files reduce checkpointing frequency. 256M - 1G (depending on write load)
`query_cache_size` (Deprecated in MySQL 8.0, MariaDB still supports it) The size of the query cache. 0 (Generally disabled in modern setups. Use alternative caching layers)
`max_connections` The maximum number of simultaneous client connections. 150-300 (Adjust based on user load)
`key_buffer_size` (MyISAM only, if still in use) The size of the key buffer. 16M - 64M (if MyISAM tables exist)

1.3 Indexing

Proper indexing is crucial for query performance. Ensure indexes are created on frequently queried columns, such as `page_title`, `page_id`, and `user_id`. Use `EXPLAIN` to analyze query performance and identify missing indexes. See Manual:Database for more information.

2. Caching Strategies

Caching reduces the load on the database by storing frequently accessed data in memory. MediaWiki provides several caching mechanisms.

2.1 Memcached/Redis

Using an external caching system like Memcached or Redis is highly recommended. These systems can cache query results, parser output, and other frequently accessed data. Configure MediaWiki to use these caches via the `wgMemCachedServers` and `wgRedisServers` settings in `LocalSettings.php`.

2.2 Opcode Cache

An [opcode cache](https://en.wikipedia.org/wiki/Opcode_cache) (e.g., APCu, OPcache) caches the compiled PHP code, reducing the time it takes to execute scripts. Ensure an opcode cache is enabled and configured on your web server.

2.3 MediaWiki Caching

MediaWiki has built-in caching mechanisms. These include:

Cache Type Description Configuration
Parser Cache Caches the output of the parser. `$wgParserCacheType = 'redis';` or `$wgParserCacheType = 'memcached';`
Query Cache (Partially replaced by external caches) Caches database query results. `$wgCachePages['query'] = true;`
Output Cache Caches rendered pages. `$wgCachePages['all'] = true;`

3. Web Server Tuning

The web server (e.g., Apache, Nginx) also plays a crucial role in performance.

3.1 Apache Configuration

If using Apache, consider using `mod_php` with a persistent PHP process manager like `mod_fcgid` or `mod_proxy_fcgi`. Disable unnecessary modules. Increase the `MaxRequestWorkers` setting to handle more concurrent requests. See Manual:Configuration for details.

3.2 Nginx Configuration

Nginx is often a better choice for high-traffic MediaWiki installations. Configure Nginx to serve static files directly and use PHP-FPM for PHP processing. Adjust worker processes and connection limits. Ensure proper caching headers are set for static assets. See Manual:Nginx for guidance.

3.3 PHP Configuration

Optimize the `php.ini` file. Key settings include:

Setting Description Recommended Value
`memory_limit` The maximum amount of memory a PHP script can allocate. 256M - 512M (depending on wiki size)
`max_execution_time` The maximum time a PHP script can run. 30 - 60 seconds
`post_max_size` The maximum size of POST data. 8M - 16M
`upload_max_filesize` The maximum size of uploaded files. 8M - 16M

4. Monitoring and Analysis

Regular monitoring is essential to identify performance bottlenecks. Use tools like:

⚠️ *Note: All benchmark scores are approximate and may vary based on configuration. Server availability subject to stock.* ⚠️