CProfile
- CProfile: Understanding and Configuring MediaWiki's Profiler
This article details the CProfile extension for MediaWiki, a powerful tool for identifying performance bottlenecks within your wiki’s PHP code. Proper configuration and understanding of CProfile output are crucial for optimizing your MediaWiki installation, especially under heavy load. This guide is aimed at server administrators and developers looking to improve wiki performance.
What is CProfile?
CProfile is a PHP extension that provides detailed profiling information about the execution of PHP scripts. When enabled within MediaWiki, it collects data on function call counts, execution times, and memory usage. This data helps pinpoint the most time-consuming parts of your code, allowing you to focus optimization efforts where they will have the greatest impact. It’s vastly superior to simply guessing at performance issues. It can be used in conjunction with other tools like Xdebug for more in-depth debugging, but CProfile is generally preferred for broad performance analysis due to its lower overhead.
Installation and Requirements
Before configuring CProfile, ensure your server meets the following requirements:
- **PHP Version:** PHP 7.2 or higher is highly recommended. While it may work on older versions, newer PHP versions offer significant performance improvements. See PHP Configuration for details on PHP versions supported by MediaWiki.
- **CProfile Extension:** The `cprofile` PHP extension must be installed and enabled on your server. The installation method varies depending on your operating system. Typically, this involves installing the extension through your system's package manager (e.g., `apt-get`, `yum`) and then enabling it in your `php.ini` file. Consult your operating system's documentation for specific instructions.
- **MediaWiki Version:** This guide is specific to MediaWiki 1.40. Configuration steps may differ in other versions.
Checking CProfile Installation
You can verify that the CProfile extension is installed correctly by creating a simple PHP file (e.g., `phpinfo.php`) containing the following code:
```php <?php phpinfo(); ?> ```
Access this file through your web server. Search the output for "cprofile". If the extension is installed and enabled, you will see detailed information about it.
Configuration within MediaWiki
CProfile is enabled and configured through the `LocalSettings.php` file. Add the following lines to your `LocalSettings.php` file, adjusting the values as needed:
```php $wgCProfile = true; $wgCProfileDir = '$IP/cprofile'; $wgCProfileThreshold = 1000; // Microseconds - functions taking longer than this are profiled $wgCProfileExclude = array(
'wfProfileFlush', // Exclude the profiler's own flushing function 'wfProfileIn', // Exclude profiling functions themselves 'wfProfileOut',
); ```
Here’s a breakdown of each setting:
- `$wgCProfile = true;`: Enables the CProfile extension. Setting this to `false` disables profiling.
- `$wgCProfileDir = '$IP/cprofile';`: Specifies the directory where CProfile data will be stored. `$IP` represents the path to your MediaWiki installation directory. Ensure this directory exists and is writable by the web server user.
- `$wgCProfileThreshold = 1000;`: Sets the threshold (in microseconds) for profiling functions. Functions taking longer than this threshold will be profiled. Adjust this value to control the granularity of the profiling data. Lower values will capture more functions, but increase overhead.
- `$wgCProfileExclude = array(...);`: Defines an array of functions to exclude from profiling. This is useful for excluding internal MediaWiki functions or functions that are already known to be efficient. The example above excludes the profiler’s own functions to avoid self-profiling.
Understanding the CProfile Output
After enabling CProfile and visiting pages on your wiki, CProfile data will be generated and stored in the directory specified by `$wgCProfileDir`. The output consists of several files, the most important of which is a `.cprof` file. This file contains the raw profiling data.
To view and analyze the data, you'll need a CProfile viewer. Several options are available, including:
- **Web-based Viewers:** Tools like KCachegrind (Linux) and QCachegrind (Windows) provide graphical interfaces for visualizing CProfile data.
- **Command-line Tools:** PHP extensions like `xhprof` can be used to parse and analyze `.cprof` files from the command line.
Example Data Table
The following table illustrates a simplified example of CProfile output:
Function Name | Call Count | Total Time (µs) | Average Time (µs) | % of Total Time |
---|---|---|---|---|
ArticlePage::doArticleView | 5 | 12000 | 2400 | 40% |
Database::query | 15 | 8000 | 533 | 26.7% |
Title::newFromText | 10 | 4000 | 400 | 13.3% |
Other Functions | ... | ... | ... | ... |
This table shows that `ArticlePage::doArticleView` is the most time-consuming function, accounting for 40% of the total execution time. `Database::query` is also a significant bottleneck, consuming 26.7% of the time. Analyzing this data would indicate a need to optimize article viewing and database queries.
Best Practices and Troubleshooting
- **Profile in a Realistic Environment:** Ensure you profile your wiki under realistic load conditions. Profiling a lightly loaded wiki may not accurately reflect performance bottlenecks under heavy traffic.
- **Focus on the Hotspots:** Prioritize optimization efforts on the functions that consume the most time, as identified by CProfile.
- **Clear Cache Regularly:** Clear the MediaWiki Cache and other caches (e.g., object cache) before profiling to ensure accurate results.
- **Consider Database Indexes:** Slow database queries are a common performance bottleneck. Ensure you have appropriate indexes defined on your database tables. See Database Administration for more information.
- **Monitor Resource Usage:** Use system monitoring tools (e.g., `top`, `htop`) to monitor CPU usage, memory usage, and disk I/O during profiling.
- **Examine SQL Queries:** Use the Special:SlowQueries special page to identify slow SQL queries.
Configuration Summary
The following table summarizes the important CProfile configuration options:
Setting | Description | Default Value |
---|---|---|
`$wgCProfile` | Enables or disables CProfile. | `false` |
`$wgCProfileDir` | Specifies the directory for CProfile data. | `$IP/cprofile` |
`$wgCProfileThreshold` | Sets the threshold (in µs) for profiling functions. | `1000` |
`$wgCProfileExclude` | An array of functions to exclude from profiling. | `array()` |
Further Reading
- Extension:CProfile - Official MediaWiki Extension Page
- Performance Optimization - General guide to improving MediaWiki performance.
- Database Administration - Information on managing and optimizing your MediaWiki database.
- PHP Configuration - Details on configuring PHP for MediaWiki.
- Caching - Overview of MediaWiki's caching mechanisms.
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.* ⚠️