* Add a $count argument to wfIncrStats(), to allow it to increase the count by more...
authorTim Starling <tstarling@users.mediawiki.org>
Thu, 10 Mar 2011 00:00:34 +0000 (00:00 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Thu, 10 Mar 2011 00:00:34 +0000 (00:00 +0000)
* Added stats to job insert and pop.
* Formalised live patch for UDP stats aggregation, adding $wgAggregateStatsID.

RELEASE-NOTES
includes/DefaultSettings.php
includes/GlobalFunctions.php
includes/job/JobQueue.php

index 1153ff4..f2cbf0a 100644 (file)
@@ -94,6 +94,8 @@ PHP if you have not done so prior to upgrading MediaWiki.
 * Added UserGetLanguageObject hook to change the language used in $wgLang
 * (bug 14645) When $wgMiserMode is on, expensive special pages are styled
   differently (italicized by default) on Special:SpecialPages
+* Added $wgAggregateStatsID, which allows UDP stats to be aggregated over
+  several wikis.
 
 === Bug fixes in 1.18 ===
 * (bug 23119) WikiError class and subclasses are now marked as deprecated
index 339dc03..889fa99 100644 (file)
@@ -3940,6 +3940,14 @@ $wgDebugFunctionEntry = 0;
  */
 $wgStatsMethod = 'cache';
 
+/**
+ * When $wgStatsMethod is 'udp', setting this to a string allows statistics to 
+ * be aggregated over more than one wiki. The string will be used in place of
+ * the DB name in outgoing UDP packets. If this is set to false, the DB name
+ * will be used.
+ */
+$wgAggregateStatsID = false;
+
 /** Whereas to count the number of time an article is viewed.
  * Does not work if pages are cached (for example with squid).
  */
index cd6beee..bdb18b8 100644 (file)
@@ -2071,15 +2071,20 @@ function wfMkdirParents( $dir, $mode = null, $caller = null ) {
 /**
  * Increment a statistics counter
  */
-function wfIncrStats( $key ) {
+function wfIncrStats( $key, $count = 1 ) {
        global $wgStatsMethod;
 
+       $count = intval( $count );
+
        if( $wgStatsMethod == 'udp' ) {
-               global $wgUDPProfilerHost, $wgUDPProfilerPort, $wgDBname;
+               global $wgUDPProfilerHost, $wgUDPProfilerPort, $wgDBname, $wgAggregateStatsID;
                static $socket;
+
+               $id = $wgAggregateStatsID !== false ? $wgAggregateStatsID : $wgDBname;
+
                if ( !$socket ) {
                        $socket = socket_create( AF_INET, SOCK_DGRAM, SOL_UDP );
-                       $statline = "stats/{$wgDBname} - 1 1 1 1 1 -total\n";
+                       $statline = "stats/{$id} - {$count} 1 1 1 1 -total\n";
                        socket_sendto(
                                $socket,
                                $statline,
@@ -2089,7 +2094,7 @@ function wfIncrStats( $key ) {
                                $wgUDPProfilerPort
                        );
                }
-               $statline = "stats/{$wgDBname} - 1 1 1 1 1 {$key}\n";
+               $statline = "stats/{$id} - {$count} 1 1 1 1 {$key}\n";
                wfSuppressWarnings();
                socket_sendto(
                        $socket,
@@ -2103,8 +2108,8 @@ function wfIncrStats( $key ) {
        } elseif( $wgStatsMethod == 'cache' ) {
                global $wgMemc;
                $key = wfMemcKey( 'stats', $key );
-               if ( is_null( $wgMemc->incr( $key ) ) ) {
-                       $wgMemc->add( $key, 1 );
+               if ( is_null( $wgMemc->incr( $key, $count ) ) ) {
+                       $wgMemc->add( $key, $count );
                }
        } else {
                // Disabled
index 7cc339e..95f9c77 100644 (file)
@@ -74,6 +74,7 @@ abstract class Job {
                        return false;
                }
 
+               wfIncrStats( 'job-pop' );
                $namespace = $row->job_namespace;
                $dbkey = $row->job_title;
                $title = Title::makeTitleSafe( $namespace, $dbkey );
@@ -163,6 +164,7 @@ abstract class Job {
 
                // If execution got to here, there's a row in $row that has been deleted from the database
                // by this thread. Hence the concurrent pop was successful.
+               wfIncrStats( 'job-pop' );
                $namespace = $row->job_namespace;
                $dbkey = $row->job_title;
                $title = Title::makeTitleSafe( $namespace, $dbkey );
@@ -238,6 +240,7 @@ abstract class Job {
                        }
                }
                if ( $rows ) {
+                       wfIncrStats( 'job-insert', count( $rows ) );
                        $dbw->begin();
                        $dbw->insert( 'job', $rows, __METHOD__, 'IGNORE' );
                        $dbw->commit();
@@ -280,6 +283,7 @@ abstract class Job {
                                return;
                        }
                }
+               wfIncrStats( 'job-insert' );
                return $dbw->insert( 'job', $fields, __METHOD__ );
        }