I recently tried to do some benchmarks of our MediaWiki setup. I used Apache jMeter and all worked well enough. My test was made of several simulated users accessing pages randomly from a pool of 1000 pages. I made sure to let the test run long enough before measurement to be certain that all pages had been touched once, and the MediaWiki parser caches were “hot”.

Then I wanted to try different caching strategies like without cache, with cache accel, etc. I would remeasure for each strategy to see which we would benefit of most. And there was the next MediaWiki pitfall luring behind the next corner, waiting to hit me:

Whenever I tried a new cache strategy, the response time went through the roof. The cause was soon found, all parser caches were suddenly empty and every page had to be reparsed.

It took me a while and looking at the caching source code, to eventually find the culprit in LocalSettings.php. By default it contains these lines:

# When you make changes to this configuration file, this will make
# sure that cached pages are cleared.
$configdate = gmdate( ‘YmdHis’, @filemtime( __FILE__ ) );
$wgCacheEpoch = max( $wgCacheEpoch, $configdate );

There. That was it. DUH!! MediaWiki invalidates all caches whenever you update any tiny little detail in your LocalSettings.php. Now this is not only a problem for benchmarks, it’s more of a problem for a live site.

As a matter of fact, we recently had quite serious performance issues, and looking back now it may have well been this anti-feature of MediaWiki. Invalidating caches is a sane and common concept. However to invalidate all caches at once – esp. with a parser that’s as slow as MediaWiki’s – this can quickly become a home made DoS attack on your own server. Suddenly every access to a page fires up the parser and takes considerably more CPU power than before. Do that with enough users simultaneously and an already strained server and you soon have a dead server.

It becomes worse if you are about to despair and think you could do something about the speed issue by tweaking things in your LocalSettings.php, because by doing that you reset the cache YET AGAIN.

I commented out that reset code from my settings file, and I know I will look more carefully in the future what software with a track record similar to MediaWiki’s uses as “sane defaults”.

One Response to “MediaWiki Cache reset”

  1. rajan says:

    when i add header and footer then cache is not working.
    please give me the code and demo of caching if i add some new content in mediawiki.

Leave a Reply