r52738 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r52737‎ | r52738 | r52739 >
Date:13:46, 3 July 2009
Author:werdna
Status:deferred
Tags:
Comment:
Add condition limit profiling as well as time profiling to the abuse filter (bug 19256)
Modified paths:
  • /trunk/extensions/AbuseFilter/AbuseFilter.class.php (modified) (history)
  • /trunk/extensions/AbuseFilter/AbuseFilter.i18n.php (modified) (history)
  • /trunk/extensions/AbuseFilter/Views/AbuseFilterViewEdit.php (modified) (history)

Diff [purge]

Index: trunk/extensions/AbuseFilter/Views/AbuseFilterViewEdit.php
@@ -270,13 +270,17 @@
271271
272272 if ($total > 0) {
273273 $matches_percent = sprintf( '%.2f', 100 * $matches_count / $total );
274 - $profile = AbuseFilter::getFilterProfile( $filter );
 274+ list($timeProfile, $condProfile) = AbuseFilter::getFilterProfile( $filter );
 275+
275276 $fields['abusefilter-edit-status-label'] =
276277 wfMsgExt( 'abusefilter-edit-status', array( 'parsemag', 'escape' ),
277 - $wgLang->formatNum($total),
278 - $wgLang->formatNum($matches_count),
279 - $wgLang->formatNum($matches_percent),
280 - $wgLang->formatNum($profile)
 278+ array(
 279+ $wgLang->formatNum($total),
 280+ $wgLang->formatNum($matches_count),
 281+ $wgLang->formatNum($matches_percent),
 282+ $wgLang->formatNum($timeProfile),
 283+ $wgLang->formatNum($condProfile)
 284+ )
281285 );
282286 }
283287 }
Index: trunk/extensions/AbuseFilter/AbuseFilter.class.php
@@ -423,8 +423,10 @@
424424 public static function checkFilter( $row, $vars, $profile = false, $prefix = '' ) {
425425 $filterID = $prefix.$row->af_id;
426426
427 - if ($profile)
 427+ if ($profile) {
 428+ $startConds = self::$condCount;
428429 $startTime = microtime(true);
 430+ }
429431
430432 // Store the row somewhere convenient
431433 self::$filters[$filterID] = $row;
@@ -442,10 +444,12 @@
443445
444446 if ($profile) {
445447 $endTime = microtime(true);
 448+ $endConds = self::$condCount;
446449
447450 $timeTaken = $endTime - $startTime;
 451+ $condsUsed = $endConds - $startConds;
448452
449 - self::recordProfilingResult( $row->af_id, $timeTaken );
 453+ self::recordProfilingResult( $row->af_id, $timeTaken, $condsUsed );
450454 }
451455
452456 return $result;
@@ -460,21 +464,25 @@
461465 $wgMemc->delete( $totalKey );
462466 }
463467
464 - public static function recordProfilingResult( $filter, $time ) {
 468+ public static function recordProfilingResult( $filter, $time, $conds ) {
465469 global $wgMemc;
466470
467471 $countKey = wfMemcKey( 'abusefilter', 'profile', $filter, 'count' );
468472 $totalKey = wfMemcKey( 'abusefilter', 'profile', $filter, 'total' );
 473+ $totalCondKey = wfMemcKey( 'abusefilter', 'profile-conds', 'total' );
469474
470475 $curCount = $wgMemc->get( $countKey );
471476 $curTotal = $wgMemc->get( $totalKey );
 477+ $curTotalConds = $wgMemc->get( $totalCondKey );
472478
473479 if ($curCount) {
 480+ $wgMemc->set( $totalCondKey, $curTotalConds + $conds, 3600 );
474481 $wgMemc->set( $totalKey, $curTotal + $time, 3600 );
475482 $wgMemc->incr( $countKey );
476483 } else {
477484 $wgMemc->set( $countKey, 1, 3600 );
478 - $wgMemc->set( $totalKey, $time, 3600 );
 485+ $wgMemc->set( $totalKey, $time, 3600 );
 486+ $wgMemc->set( $totalCondKey, $conds, 3600 );
479487 }
480488 }
481489
@@ -483,15 +491,22 @@
484492
485493 $countKey = wfMemcKey( 'abusefilter', 'profile', $filter, 'count' );
486494 $totalKey = wfMemcKey( 'abusefilter', 'profile', $filter, 'total' );
 495+ $totalCondKey = wfMemcKey( 'abusefilter', 'profile-conds', 'total' );
487496
488497 $curCount = $wgMemc->get( $countKey );
489498 $curTotal = $wgMemc->get( $totalKey );
 499+ $curTotalConds = $wgMemc->get( $totalCondKey );
490500
491501 if (!$curCount)
492 - return 0;
 502+ return array( 0, 0 );
493503
494 - $profile = ($curTotal / $curCount) * 1000;
495 - return round( $profile, 2); // Return in ms, rounded to 2dp
 504+ $timeProfile = ($curTotal / $curCount) * 1000; // 1000 ms in a sec
 505+ $timeProfile = round( $timeProfile, 2); // Return in ms, rounded to 2dp
 506+
 507+ $condProfile = ($curTotalConds / $curCount);
 508+ $condProfile = round( $condProfile, 0 );
 509+
 510+ return array( $timeProfile, $condProfile );
496511 }
497512
498513 /** Utility function to decode global-$index to $index. Returns false if not global */
Index: trunk/extensions/AbuseFilter/AbuseFilter.i18n.php
@@ -158,7 +158,7 @@
159159 [[Special:AbuseFilter/history/$2|Return to this filter's history]].",
160160 'abusefilter-edit-status-label' => 'Statistics:',
161161 'abusefilter-edit-status' => 'Of the last $1 {{PLURAL:$1|action|actions}}, this filter has matched $2 ($3%).
162 -On average, its run time is $4ms',
 162+On average, its run time is $4ms, and it consumes $5 {{PLURAL:$5|condition|conditions}} of the condition limit.',
163163 'abusefilter-edit-throttled' => "'''Warning''': This filter was automatically disabled as a safety measure.
164164 It reached the limit of matching more than $1% of actions.",
165165 'abusefilter-edit-new' => 'New filter',

Status & tagging log