Segment stash edit cache stats by basis for hit/miss
authorOri Livneh <ori@wikimedia.org>
Tue, 19 Apr 2016 01:13:08 +0000 (18:13 -0700)
committerOri.livneh <ori@wikimedia.org>
Tue, 19 Apr 2016 01:31:39 +0000 (01:31 +0000)
Instead of just counting cache hits and misses, segment the counts by reason,
so we can differentiate (for example) timestamp-based cache hits from
staleness-check-survivor cache hits. I want this data so I can determine
whether increasing the cutoff for timestamp-based hits from 3 to 5 seconds has
a substantial enough impact to warrant the slightly weaker consistency.

Also changed 'cache-hit' to 'cache_hit'. MediaWiki normalizes the dash to an
underscore anyway, but the normalization is there for dynamically-constructed
key names (or name segments). In the case of hard-coded values, it is desirable
for the code to be as close as possible to the final form of the metric name,
to simplify metric lookup.

Change-Id: I0cd61da9746e3ca3695e23200f698b8b1371798c

includes/api/ApiStashEdit.php

index 3c02c9c..cc8e390 100644 (file)
@@ -272,18 +272,18 @@ class ApiStashEdit extends ApiBase {
                        }
 
                        $timeMs = 1000 * max( 0, microtime( true ) - $start );
-                       $stats->timing( 'editstash.lock-wait-time', $timeMs );
+                       $stats->timing( 'editstash.lock_wait_time', $timeMs );
                }
 
                if ( !is_object( $editInfo ) || !$editInfo->output ) {
-                       $stats->increment( 'editstash.cache-misses' );
+                       $stats->increment( 'editstash.cache_misses.no_stash' );
                        $logger->debug( "No cache value for key '$key'." );
                        return false;
                }
 
                $time = wfTimestamp( TS_UNIX, $editInfo->output->getTimestamp() );
                if ( ( time() - $time ) <= 3 ) {
-                       $stats->increment( 'editstash.cache-hits' );
+                       $stats->increment( 'editstash.cache_hits.presumed_fresh' );
                        $logger->debug( "Timestamp-based cache hit for key '$key'." );
                        return $editInfo; // assume nothing changed
                }
@@ -312,7 +312,7 @@ class ApiStashEdit extends ApiBase {
                        }
 
                        if ( $changed || $res->numRows() != $templateUses ) {
-                               $stats->increment( 'editstash.cache-misses' );
+                               $stats->increment( 'editstash.cache_misses.proven_stale' );
                                $logger->info( "Stale cache for key '$key'; template changed." );
                                return false;
                        }
@@ -336,13 +336,13 @@ class ApiStashEdit extends ApiBase {
                        }
 
                        if ( $changed || $res->numRows() != count( $files ) ) {
-                               $stats->increment( 'editstash.cache-misses' );
+                               $stats->increment( 'editstash.cache_misses.proven_stale' );
                                $logger->info( "Stale cache for key '$key'; file changed." );
                                return false;
                        }
                }
 
-               $stats->increment( 'editstash.cache-hits' );
+               $stats->increment( 'editstash.cache_hits.proven_fresh' );
                $logger->debug( "Cache hit for key '$key'." );
 
                return $editInfo;