Daniel Kinzler has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/58464


Change subject: Add overview of dispatch states to DispatchStats.
......................................................................

Add overview of dispatch states to DispatchStats.

This provides an overview of how many client wikis are in which
dispatch state (complete, locked, fresh, or pending).

Change-Id: Id1ee5634764589b7155989dab78dc73bb9c59b7d
---
M repo/Wikibase.i18n.php
M repo/includes/specials/SpecialDispatchStats.php
M repo/includes/store/sql/DispatchStats.php
3 files changed, 91 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/64/58464/1

diff --git a/repo/Wikibase.i18n.php b/repo/Wikibase.i18n.php
index f6c025b..e68b125 100644
--- a/repo/Wikibase.i18n.php
+++ b/repo/Wikibase.i18n.php
@@ -188,6 +188,13 @@
        'wikibase-dispatchstats-stalest' => 'Stalest',
        'wikibase-dispatchstats-median'  => 'Median',
        'wikibase-dispatchstats-average' => 'Average',
+       'wikibase-dispatchstats-state' => 'Status',
+       'wikibase-dispatchstats-count' => 'Number',
+       'wikibase-dispatchstats-total' => 'Total',
+       'wikibase-dispatchstats-state-pending' => 'pending',
+       'wikibase-dispatchstats-state-locked' => 'locked',
+       'wikibase-dispatchstats-state-complete' => 'complete',
+       'wikibase-dispatchstats-state-fresh' => 'fresh',
        'special-listdatatypes' => 'List of all datatypes available',
        'wikibase-listdatatypes-intro' => 'This is a list of all datatypes 
currently in use on this installation:',
        'wikibase-history-title-with-label' => 'Revision history of "$2" ($1)',
@@ -755,6 +762,13 @@
        'wikibase-dispatchstats-median' => "Row header for the median client 
wiki, such that half of the client wikis are fresher and half are staler than 
this one, so it's differ from {{msg-mw|Wikibase-dispatchstats-average}}.",
        'wikibase-dispatchstats-average' => 'Row header for average lag values
 {{Identical|Average}}',
+       'wikibase-dispatchstats-state' => 'Column header for the column showing 
the client state',
+       'wikibase-dispatchstats-count' => 'Column header for the column showing 
the number of clients',
+       'wikibase-dispatchstats-total' => 'Row with the total number of 
clients',
+       'wikibase-dispatchstats-state-pending' => 'Row with the number of 
clients that are awaiting processing by a dispatcher',
+       'wikibase-dispatchstats-state-locked' => 'Row with the number of 
clients that are currently being processed by a dispatcher',
+       'wikibase-dispatchstats-state-complete' => 'Row with the number of 
clients that are up to date',
+       'wikibase-dispatchstats-state-fresh' => 'Row with the number of clients 
that have recently been processed',
        'special-listdatatypes' => '{{doc-special|ListDataTypes}}
 This special page returns a list of available datatypes (such as 
commonsMedia)',
        'wikibase-listdatatypes-intro' => 'Intro text for the ListDatatypes 
special page.',
diff --git a/repo/includes/specials/SpecialDispatchStats.php 
b/repo/includes/specials/SpecialDispatchStats.php
index 3273d3c..9737118 100644
--- a/repo/includes/specials/SpecialDispatchStats.php
+++ b/repo/includes/specials/SpecialDispatchStats.php
@@ -114,6 +114,8 @@
                        $lang->timeanddate( $stats->getMaxChangeTimestamp() ),
                ) );
 
+               //TODO: calculate changes/minute over the last hour. Cache it 
for a minute or so.
+
                $this->getOutput()->addHTML( Html::closeElement( 'table' ));
 
                // dispatch stats ------
@@ -151,5 +153,27 @@
                );
 
                $this->getOutput()->addHTML( Html::closeElement( 'table' ));
+
+               // client states ------
+               $this->getOutput()->addHTML( Html::openElement( 'table', array( 
'class' => 'wikitable' ) ));
+
+               $this->outputRow( array(
+                       $this->msg( 'wikibase-dispatchstats-state' )->text(),
+                       $this->msg( 'wikibase-dispatchstats-count' )->text(),
+               ), 'th' );
+
+               $this->outputRow( array(
+                       $this->msg( 'wikibase-dispatchstats-total' )->text(),
+                       $stats->getClientCount()
+               ) );
+
+               foreach ( \Wikibase\DispatchStats::$states as $state ) {
+                       $this->outputRow( array(
+                               $this->msg( 'wikibase-dispatchstats-state-' . 
$state )->text(),
+                               $stats->getStateCount( $state )
+                       ) );
+               }
+
+               $this->getOutput()->addHTML( Html::closeElement( 'table' ));
        }
 }
diff --git a/repo/includes/store/sql/DispatchStats.php 
b/repo/includes/store/sql/DispatchStats.php
index 036fb1c..6cadccc 100644
--- a/repo/includes/store/sql/DispatchStats.php
+++ b/repo/includes/store/sql/DispatchStats.php
@@ -29,6 +29,13 @@
  */
 class DispatchStats {
 
+       public static $states = array(
+               'complete',
+               'locked',
+               'fresh',
+               'pending'
+       );
+
        /**
         * @var string
         */
@@ -53,6 +60,19 @@
         * @var null|object
         */
        protected $average;
+
+       /**
+        * @var int: Number of seconds to wait before dispatching to the same 
wiki again.
+        *           This affects the effective batch size, and this influences 
how changes
+        *           can be coalesced.
+        */
+       protected $dispatchInterval = 60; //XXX: keep default synced with 
dispatchChanges.php
+
+       /**
+        * @var int: Number of seconds to wait before testing a lock. Any 
target with a lock
+        *           timestamp newer than this will not be considered for 
selection.
+        */
+       protected $lockGraceInterval = 60; //XXX: keep default synced with 
dispatchChanges.php
 
        /**
         * creates a new DispatchStats instance.
@@ -128,6 +148,8 @@
 
                while ( $row = $res->fetchObject() ) {
                        if ( $this->changeStats ) {
+                               $time = (int)wfTimestamp( TS_UNIX, 
$row->change_time );
+
                                // time between last dispatch and now
                                $row->chd_untouched = max( 0, $now
                                        - (int)wfTimestamp( TS_UNIX, 
$row->chd_touched ) );
@@ -138,16 +160,27 @@
                                        $row->chd_lag = null;
                                } else {
                                        $row->chd_lag = max( 0, 
(int)wfTimestamp( TS_UNIX, $this->changeStats->max_time )
-                                               - (int)wfTimestamp( TS_UNIX, 
$row->change_time ) );
+                                               - $time );
                                }
 
                                // number of changes that have not been 
processed yet
                                $row->chd_pending = 
(int)$this->changeStats->max_id - $row->chd_seen;
+
+                               if ( $row->chd_pending === 0 ) {
+                                       $row->chd_state = "complete";
+                               } else if ( ( $time + $this->dispatchInterval ) 
> $now ) {
+                                       $row->chd_state = "fresh";
+                               } else if ( $row->chd_lock && ( ( $time + 
$this->lockGraceInterval ) > $now ) ) {
+                                       $row->chd_state = "locked";
+                               } else {
+                                       $row->chd_state = "pending";
+                               }
                        } else {
                                // if there are no changes, there is no lag
                                $row->chd_untouched = 0;
                                $row->chd_pending = 0;
                                $row->chd_lag = 0;
+                               $row->chd_state = "complete";
                        }
 
                        $this->average->chd_untouched += $row->chd_untouched;
@@ -322,5 +355,24 @@
                return $this->changeStats->min_time;
        }
 
+       /**
+        * returns the number of clients with the given dispatch state.
+        *
+        * @param string $state one of "complete", "locked", "fresh" or 
"pending".
+        *
+        * @return string
+        */
+       public function getStateCount( $state ) {
+               $c = 0;
+
+               foreach ( $this->clientStates as $row ) {
+                       if ( $row->chd_state === $state ) {
+                               $c++;
+                       }
+               }
+
+               return $c;
+       }
+
 }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/58464
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id1ee5634764589b7155989dab78dc73bb9c59b7d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to