Caching Strategies
- Caching Strategies for MediaWiki 1.40
This article details various caching strategies employed to optimize the performance of a MediaWiki 1.40 installation. Efficient caching is crucial for handling high traffic and reducing server load. This guide is aimed at newcomers to server administration of MediaWiki sites.
Understanding Caching in MediaWiki
Caching, in the context of MediaWiki, involves storing frequently accessed data in a temporary storage location (the “cache”) so that future requests for that data can be served faster. Without caching, the server would need to regenerate the requested content for every single request, which can be resource-intensive. MediaWiki utilizes several layers of caching, each addressing different aspects of performance. We will cover the most important ones. See Configuration settings for a full list of configurable settings.
1. Parser Cache
The parser cache stores the output of the parser after it has processed a page. This is arguably the most significant cache for performance. When a user requests a page, MediaWiki first checks if a recent version of the parsed output is available in the parser cache. If so, it serves the cached version, bypassing the potentially expensive parsing process.
Technical Specifications:
Parameter | Description | Default Value | Recommended Value |
---|---|---|---|
`$wgParserCacheType` | Specifies the type of parser cache to use. | 'redis' | 'redis' (highly recommended) |
`$wgParserCacheTTL` | Time-to-live (TTL) for parser cache entries, in seconds. | 3600 (1 hour) | 86400 (24 hours) - adjust based on update frequency. |
`$wgCachePages` | Enables or disables caching of pages. | true | true |
Consider using a robust caching backend like Redis or Memcached for the parser cache. The default file-based cache is suitable for very small sites only. See Caching for more details.
2. Output Cache
The output cache stores the complete HTML output of a page after it has been rendered. This includes the parsed content, the site’s styling and layout, and any other dynamic elements. The output cache is checked *after* the parser cache. If a cached version exists, it is delivered directly to the user.
Technical Specifications:
Parameter | Description | Default Value | Recommended Value |
---|---|---|---|
`$wgMainCacheType` | Specifies the type of output cache to use. | 'redis' | 'redis' (highly recommended) |
`$wgUseCommaForEffectMarker` | Determines how effects are marked for output caching. | true | true |
`$wgCacheDirectory` | Directory where the output cache is stored (if using file-based caching). | $wgUploadDirectory . '/cache' | N/A (if using Redis or Memcached) |
3. Database Caching
MediaWiki frequently queries the database. Database caching reduces the load on the database server by storing the results of common queries. This is often handled by the underlying database system itself (e.g., MySQL's query cache), but MediaWiki also provides some additional database caching mechanisms.
Technical Specifications:
Parameter | Description | Default Value | Recommended Value |
---|---|---|---|
`$wgDBcacheSearch` | Enables caching of search results. | false | true (if search is heavily used) |
`$wgDBcacheTransforms` | Enables caching of transform results (e.g., title normalization). | false | true |
`$wgDBcacheExpiry` | Expiry time for database cache entries, in seconds. | 3600 (1 hour) | 86400 (24 hours) |
Consider optimizing your database queries through proper indexing and careful schema design. See Database access for more information.
4. Other Caching Mechanisms
- Object Cache: Used for caching various internal objects, such as user preferences and category members. Configured via `$wgObjectCacheType`.
- Message Cache: Caches system messages to reduce database lookups. Enabled by default.
- Action Cache: Caches the results of API actions. Requires specific configuration.
Choosing a Caching Backend
The choice of caching backend significantly impacts performance. Here’s a comparison:
- File-based Caching: Simple to set up, but slow and not scalable. Suitable only for very small sites.
- Memcached: A popular in-memory object caching system. Relatively easy to set up and provides good performance.
- Redis: A more advanced in-memory data structure store. Offers more features than Memcached, including persistence and more complex data structures. Generally preferred for larger MediaWiki installations. See Redis for more details.
Monitoring and Tuning
Regular monitoring of cache hit rates is essential. Tools like Statistics page and server monitoring solutions can provide insights into cache performance. Adjust cache TTL values based on the frequency of content updates. Longer TTLs reduce server load but may result in stale content being served. Shorter TTLs ensure content freshness but increase server load. See Performance tuning for advanced techniques.
Related Pages
- Manual:Configuration settings
- Manual:Caching
- Redis
- Memcached
- Database access
- Manual:Performance tuning
- Configuration checklist
- Scaling up
- Advanced configuration
- Server requirements
- Security
- Extension:CacheHitCount
- MediaWiki:Statistics page
- Manual:Load balancer configuration
- Troubleshooting
- Site configuration
Intel-Based Server Configurations
Configuration | Specifications | Benchmark |
---|---|---|
Core i7-6700K/7700 Server | 64 GB DDR4, NVMe SSD 2 x 512 GB | CPU Benchmark: 8046 |
Core i7-8700 Server | 64 GB DDR4, NVMe SSD 2x1 TB | CPU Benchmark: 13124 |
Core i9-9900K Server | 128 GB DDR4, NVMe SSD 2 x 1 TB | CPU Benchmark: 49969 |
Core i9-13900 Server (64GB) | 64 GB RAM, 2x2 TB NVMe SSD | |
Core i9-13900 Server (128GB) | 128 GB RAM, 2x2 TB NVMe SSD | |
Core i5-13500 Server (64GB) | 64 GB RAM, 2x500 GB NVMe SSD | |
Core i5-13500 Server (128GB) | 128 GB RAM, 2x500 GB NVMe SSD | |
Core i5-13500 Workstation | 64 GB DDR5 RAM, 2 NVMe SSD, NVIDIA RTX 4000 |
AMD-Based Server Configurations
Configuration | Specifications | Benchmark |
---|---|---|
Ryzen 5 3600 Server | 64 GB RAM, 2x480 GB NVMe | CPU Benchmark: 17849 |
Ryzen 7 7700 Server | 64 GB DDR5 RAM, 2x1 TB NVMe | CPU Benchmark: 35224 |
Ryzen 9 5950X Server | 128 GB RAM, 2x4 TB NVMe | CPU Benchmark: 46045 |
Ryzen 9 7950X Server | 128 GB DDR5 ECC, 2x2 TB NVMe | CPU Benchmark: 63561 |
EPYC 7502P Server (128GB/1TB) | 128 GB RAM, 1 TB NVMe | CPU Benchmark: 48021 |
EPYC 7502P Server (128GB/2TB) | 128 GB RAM, 2 TB NVMe | CPU Benchmark: 48021 |
EPYC 7502P Server (128GB/4TB) | 128 GB RAM, 2x2 TB NVMe | CPU Benchmark: 48021 |
EPYC 7502P Server (256GB/1TB) | 256 GB RAM, 1 TB NVMe | CPU Benchmark: 48021 |
EPYC 7502P Server (256GB/4TB) | 256 GB RAM, 2x2 TB NVMe | CPU Benchmark: 48021 |
EPYC 9454P Server | 256 GB RAM, 2x2 TB NVMe |
Order Your Dedicated Server
Configure and order your ideal server configuration
Need Assistance?
- Telegram: @powervps Servers at a discounted price
⚠️ *Note: All benchmark scores are approximate and may vary based on configuration. Server availability subject to stock.* ⚠️