In-Memory Databases
- In-Memory Databases for MediaWiki
This article details the use of in-memory databases (IMDBs) with MediaWiki 1.40, focusing on performance improvements and configuration considerations. Using an IMDB can significantly reduce database latency, leading to faster page loads and a more responsive wiki experience, particularly under high load. However, it's crucial to understand the tradeoffs involved, primarily data persistence.
What are In-Memory Databases?
Traditionally, MediaWiki relies on persistent storage (like MySQL/MariaDB or PostgreSQL) to store all its data. In-memory databases, as the name suggests, store data primarily in RAM. This offers dramatically faster read and write speeds because accessing RAM is orders of magnitude quicker than accessing disk. However, data in RAM is volatile; it's lost when the server restarts or crashes unless explicitly saved to persistent storage.
For MediaWiki, IMDBs are often used as a caching layer *in front of* a persistent database. This means frequently accessed data is served from the IMDB, while less frequent data remains in the persistent storage. This hybrid approach delivers performance benefits without the risk of complete data loss.
Popular IMDB Choices for MediaWiki
Several in-memory database systems are suitable for use with MediaWiki. Here's a comparison of some common options:
Database | Description | MediaWiki Compatibility | Complexity |
---|---|---|---|
Redis | An open-source, in-memory data structure store, used as a database, cache and message broker. | Excellent. Requires the Redis extension for MediaWiki. | Medium |
Memcached | A distributed memory object caching system. | Good. Requires the Memcached extension for MediaWiki. | Low |
SQLite (in-memory mode) | A self-contained, serverless, zero-configuration, transactional SQL database engine. Can run entirely in memory. | Limited. Not generally recommended for production environments due to scalability concerns. Useful for testing. | Low |
Configuring MediaWiki with Redis
Redis is generally the preferred choice for an IMDB with MediaWiki due to its versatility and robust feature set. Here's a step-by-step guide to configuring MediaWiki to use Redis:
1. **Install Redis:** Follow the installation instructions for your operating system. See the official Redis documentation for details. 2. **Install the Redis Extension:** Download the Redis extension for MediaWiki and install it according to the instructions on its page. This usually involves copying the extension files to your `extensions/` directory and adding `'Redis'` to your `wfLoadExtensions.php` file. 3. **Configure `LocalSettings.php`:** Add the following lines to your `LocalSettings.php` file, adjusting the host and port as needed:
```php $wgRedis = [
'host' => '127.0.0.1', 'port' => 6379, 'password' => , // Optional, if Redis is password protected 'dbindex' => 0, // Optional, select the Redis database
];
$wgCacheDatabaseRedir = true; // Redirect cache lookups to Redis $wgSessionCacheType = 'redis'; // Use Redis for session caching ``` 4. **Configure Caching:** Adjust your `$wgCacheDirectory` setting to a location that Redis can access if you intend to use Redis for file caching as well. Remember to clear your MediaWiki cache after making changes to `LocalSettings.php`. See Help:Cache for more information.
Configuring MediaWiki with Memcached
Memcached offers a simpler caching solution than Redis. Configuration is equally straightforward:
1. **Install Memcached:** Install Memcached on your server. Refer to the Memcached documentation for installation instructions. 2. **Install the Memcached Extension:** Download the Memcached extension for MediaWiki and install it. 3. **Configure `LocalSettings.php`:** Add the following to your `LocalSettings.php`:
```php $wgMemCachedLocalServers = array(
'127.0.0.1:11211' // Replace with your Memcached server address and port
);
$wgCacheDatabaseRedir = true; // Redirect cache lookups to Memcached ```
Understanding Caching Layers
MediaWiki’s caching system is layered. Here’s a simplified overview:
Cache Layer | Data Stored | Speed | Persistence |
---|---|---|---|
Browser Cache | Static assets (CSS, JavaScript, images) | Fastest | Limited (Browser-dependent) |
Opcode Cache (e.g., APCu, OPcache) | Compiled PHP code | Very Fast | Session-based |
Memcached/Redis | Database query results, parsed templates, rendered HTML fragments | Fast | Volatile (Lost on restart) |
Database Cache (MySQL/PostgreSQL Query Cache) | Database query results | Moderate | Limited (Invalidated frequently) |
Persistent Database | All wiki data | Slowest | Persistent |
It's important to understand where each IMDB fits within this hierarchy. Setting `$wgCacheDatabaseRedir = true` directs MediaWiki to first check the IMDB for cached data *before* querying the persistent database.
Monitoring and Tuning
After implementing an IMDB, it's crucial to monitor its performance. Key metrics include:
- **Hit Ratio:** The percentage of requests served from the IMDB. Higher is better.
- **Memory Usage:** Track memory consumption to ensure the IMDB doesn't exhaust available RAM.
- **Latency:** Monitor the time it takes to retrieve data from the IMDB.
Tools like `redis-cli` (for Redis) and Memcached's built-in statistics can provide valuable insights. Regularly review the Performance logging in MediaWiki to identify potential bottlenecks.
Consider adjusting the IMDB's configuration (e.g., maximum memory allocation, eviction policies) to optimize performance based on your wiki's usage patterns. See Manual:Configuration for advanced settings.
Considerations & Caveats
- **Data Loss:** Remember that IMDBs are volatile. Implement a robust backup strategy for your persistent database.
- **Memory Requirements:** Allocate sufficient RAM to the IMDB to accommodate the cached data. Insufficient memory will lead to performance degradation.
- **Complexity:** Introducing an IMDB adds complexity to your infrastructure. Ensure you have the expertise to manage and maintain it.
- **Session Management:** Using Redis for session caching requires careful consideration of session persistence and failover. See Manual:Sessions for details.
Help:Caching
Manual:Configuration
Manual:Sessions
Extension:Redis
Extension:Memcached
Redis documentation
Memcached documentation
Help:Performance logging
Database performance
Scaling MediaWiki
MediaWiki administration
Manual:Upgrading
Manual:Extensions
Help:Contents
Special:Statistics
Special:Search
API:Main page
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.* ⚠️