r81444 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81443‎ | r81444 | r81445 >
Date:11:58, 3 February 2011
Author:catrope
Status:ok (Comments)
Tags:
Comment:
1.17: Back out r71412 (adaptive message cache) and its followups r71418, r74177, r74179
Modified paths:
  • /branches/REL1_17/phase3/includes/DefaultSettings.php (modified) (history)
  • /branches/REL1_17/phase3/includes/MessageCache.php (modified) (history)
  • /branches/REL1_17/phase3/includes/Wiki.php (modified) (history)

Diff [purge]

Index: branches/REL1_17/phase3/includes/MessageCache.php
@@ -42,26 +42,6 @@
4343 /// Variable for tracking which variables are already loaded
4444 protected $mLoadedLanguages = array();
4545
46 - /**
47 - * Used for automatic detection of most used messages.
48 - */
49 - protected $mRequestedMessages = array();
50 -
51 - /**
52 - * How long the message request counts are stored. Longer period gives
53 - * better sample, but also takes longer to adapt changes. The counts
54 - * are aggregrated per day, regardless of the value of this variable.
55 - */
56 - protected static $mAdaptiveDataAge = 604800; // Is 7*24*3600
57 -
58 - /**
59 - * Filter the tail of less used messages that are requested more seldom
60 - * than this factor times the number of request of most requested message.
61 - * These messages are not loaded in the default set, but are still cached
62 - * individually on demand with the normal cache expiry time.
63 - */
64 - protected static $mAdaptiveInclusionThreshold = 0.05;
65 -
6646 function __construct( $memCached, $useDB, $expiry ) {
6747 if ( !$memCached ) {
6848 $memCached = wfGetCache( CACHE_NONE );
@@ -329,12 +309,12 @@
330310 * $wgMaxMsgCacheEntrySize are assigned a special value, and are loaded
331311 * on-demand from the database later.
332312 *
333 - * @param $code \string Language code.
334 - * @return \array Loaded messages for storing in caches.
 313+ * @param $code Optional language code, see documenation of load().
 314+ * @return Array: Loaded messages for storing in caches.
335315 */
336 - function loadFromDB( $code ) {
 316+ function loadFromDB( $code = false ) {
337317 wfProfileIn( __METHOD__ );
338 - global $wgMaxMsgCacheEntrySize, $wgLanguageCode, $wgAdaptiveMessageCache;
 318+ global $wgMaxMsgCacheEntrySize, $wgContLanguageCode;
339319 $dbr = wfGetDB( DB_SLAVE );
340320 $cache = array();
341321
@@ -344,24 +324,19 @@
345325 'page_namespace' => NS_MEDIAWIKI,
346326 );
347327
348 - $mostused = array();
349 - if ( $wgAdaptiveMessageCache ) {
350 - $mostused = $this->getMostUsedMessages();
 328+ if ( $code ) {
 329+ # Is this fast enough. Should not matter if the filtering is done in the
 330+ # database or in code.
351331 if ( $code !== $wgLanguageCode ) {
352 - foreach ( $mostused as $key => $value ) $mostused[$key] = "$value/$code";
 332+ # Messages for particular language
 333+ $conds[] = 'page_title' . $dbr->buildLike( $dbr->anyString(), "/$code" );
 334+ } else {
 335+ # Effectively disallows use of '/' character in NS_MEDIAWIKI for uses
 336+ # other than language code.
 337+ $conds[] = 'page_title NOT' . $dbr->buildLike( $dbr->anyString(), '/', $dbr->anyString() );
353338 }
354339 }
355340
356 - if ( count( $mostused ) ) {
357 - $conds['page_title'] = $mostused;
358 - } elseif ( $code !== $wgLanguageCode ) {
359 - $conds[] = 'page_title' . $dbr->buildLike( $dbr->anyString(), "/$code" );
360 - } else {
361 - # Effectively disallows use of '/' character in NS_MEDIAWIKI for uses
362 - # other than language code.
363 - $conds[] = 'page_title NOT' . $dbr->buildLike( $dbr->anyString(), '/', $dbr->anyString() );
364 - }
365 -
366341 # Conditions to fetch oversized pages to ignore them
367342 $bigConds = $conds;
368343 $bigConds[] = 'page_len > ' . intval( $wgMaxMsgCacheEntrySize );
@@ -386,12 +361,6 @@
387362 $cache[$row->page_title] = ' ' . Revision::getRevisionText( $row );
388363 }
389364
390 - foreach ( $mostused as $key ) {
391 - if ( !isset( $cache[$key] ) ) {
392 - $cache[$key] = '!NONEXISTENT';
393 - }
394 - }
395 -
396365 $cache['VERSION'] = MSG_CACHE_VERSION;
397366 wfProfileOut( __METHOD__ );
398367 return $cache;
@@ -566,11 +535,6 @@
567536 $uckey = $wgContLang->ucfirst( $lckey );
568537 }
569538
570 - /* Record each message request, but only once per request.
571 - * This information is not used unless $wgAdaptiveMessageCache
572 - * is enabled. */
573 - $this->mRequestedMessages[$uckey] = true;
574 -
575539 # Try the MediaWiki namespace
576540 if( !$this->mDisable && $useDB ) {
577541 $title = $uckey;
@@ -635,7 +599,8 @@
636600 * @param $code String: code denoting the language to try.
637601 */
638602 function getMsgFromNamespace( $title, $code ) {
639 - global $wgAdaptiveMessageCache;
 603+ $type = false;
 604+ $message = false;
640605
641606 $this->load( $code );
642607 if ( isset( $this->mCache[$code][$title] ) ) {
@@ -644,28 +609,15 @@
645610 return substr( $entry, 1 );
646611 } elseif ( $entry === '!NONEXISTENT' ) {
647612 return false;
648 - } elseif( $entry === '!TOO BIG' ) {
649 - // Fall through and try invididual message cache below
650 -
651 - } else {
652 - // XXX: This is not cached in process cache, should it?
653 - $message = false;
654 - wfRunHooks('MessagesPreLoad', array( $title, &$message ) );
655 - if ( $message !== false ) {
656 - return $message;
657 - }
658 -
659 - /* If message cache is in normal mode, it is guaranteed
660 - * (except bugs) that there is always entry (or placeholder)
661 - * in the cache if message exists. Thus we can do minor
662 - * performance improvement and return false early.
663 - */
664 - if ( !$wgAdaptiveMessageCache ) {
665 - return false;
666 - }
667613 }
668614 }
669615
 616+ # Call message hooks, in case they are defined
 617+ wfRunHooks('MessagesPreLoad', array( $title, &$message ) );
 618+ if ( $message !== false ) {
 619+ return $message;
 620+ }
 621+
670622 # Try the individual message cache
671623 $titleKey = wfMemcKey( 'messages', 'individual', $title );
672624 $entry = $this->mMemc->get( $titleKey );
@@ -689,7 +641,6 @@
690642 $this->mCache[$code][$title] = ' ' . $message;
691643 $this->mMemc->set( $titleKey, ' ' . $message, $this->mExpiry );
692644 } else {
693 - $message = false;
694645 $this->mCache[$code][$title] = '!NONEXISTENT';
695646 $this->mMemc->set( $titleKey, '!NONEXISTENT', $this->mExpiry );
696647 }
@@ -832,59 +783,4 @@
833784 return array( $message, $lang );
834785 }
835786
836 - public static function logMessages() {
837 - global $wgMessageCache, $wgAdaptiveMessageCache;
838 - if ( !$wgAdaptiveMessageCache || !$wgMessageCache instanceof MessageCache ) {
839 - return;
840 - }
841 -
842 - $cachekey = wfMemckey( 'message-profiling' );
843 - $cache = wfGetCache( CACHE_DB );
844 - $data = $cache->get( $cachekey );
845 -
846 - if ( !$data ) $data = array();
847 -
848 - $age = self::$mAdaptiveDataAge;
849 - $filterDate = substr( wfTimestamp( TS_MW, time()-$age ), 0, 8 );
850 - foreach ( array_keys( $data ) as $key ) {
851 - if ( $key < $filterDate ) unset( $data[$key] );
852 - }
853 -
854 - $index = substr( wfTimestampNow(), 0, 8 );
855 - if ( !isset( $data[$index] ) ) $data[$index] = array();
856 -
857 - foreach ( $wgMessageCache->mRequestedMessages as $message => $_ ) {
858 - if ( !isset( $data[$index][$message] ) ) $data[$index][$message] = 0;
859 - $data[$index][$message]++;
860 - }
861 -
862 - $cache->set( $cachekey, $data );
863 - }
864 -
865 - public function getMostUsedMessages() {
866 - $cachekey = wfMemckey( 'message-profiling' );
867 - $cache = wfGetCache( CACHE_DB );
868 - $data = $cache->get( $cachekey );
869 - if ( !$data ) return array();
870 -
871 - $list = array();
872 -
873 - foreach( $data as $messages ) {
874 - foreach( $messages as $message => $count ) {
875 - $key = $message;
876 - if ( !isset( $list[$key] ) ) $list[$key] = 0;
877 - $list[$key] += $count;
878 - }
879 - }
880 -
881 - $max = max( $list );
882 - foreach ( $list as $message => $count ) {
883 - if ( $count < intval( $max * self::$mAdaptiveInclusionThreshold ) ) {
884 - unset( $list[$message] );
885 - }
886 - }
887 -
888 - return array_keys( $list );
889 - }
890 -
891787 }
Index: branches/REL1_17/phase3/includes/Wiki.php
@@ -416,7 +416,6 @@
417417 * Ends this task peacefully
418418 */
419419 function restInPeace() {
420 - MessageCache::logMessages();
421420 wfLogProfilingData();
422421 // Commit and close up!
423422 $factory = wfGetLBFactory();
Index: branches/REL1_17/phase3/includes/DefaultSettings.php
@@ -1542,13 +1542,6 @@
15431543 $wgLocalMessageCacheSerialized = true;
15441544
15451545 /**
1546 - * Instead of caching everything, keep track which messages are requested and
1547 - * load only most used messages. This only makes sense if there is lots of
1548 - * interface messages customised in the wiki (like hundreds in many languages).
1549 - */
1550 -$wgAdaptiveMessageCache = false;
1551 -
1552 -/**
15531546 * Localisation cache configuration. Associative array with keys:
15541547 * class: The class to use. May be overridden by extensions.
15551548 *

Follow-up revisions

RevisionCommit summaryAuthorDate
r925491.18: Back out adaptive message cache (r71412, r71418, r74177, r74179) by mer...catrope18:35, 19 July 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r71412Added $wgAdaptiveMessageCache to avoid caching huge pile of never used messag...nikerabbit16:41, 21 August 2010
r71418Follow up r71412. $wgContLang is not used.platonides20:47, 21 August 2010
r74177Use 7*24*3600 instead of 604800....siebrand23:23, 2 October 2010
r74179Fix broken r74177 because it needs a constant and address CR comment on r7141...siebrand23:34, 2 October 2010

Comments

#Comment by Siebrand (talk | contribs)   14:16, 3 February 2011

Reason?

#Comment by Catrope (talk | contribs)   14:18, 3 February 2011

Niklas asked me to and tagged it as revert1.17

Status & tagging log