Make the ratio of requests getting Priority Hints configurable
authorGilles Dubuc <gilles@wikimedia.org>
Wed, 3 Apr 2019 07:06:38 +0000 (09:06 +0200)
committerGilles Dubuc <gilles@wikimedia.org>
Mon, 22 Apr 2019 19:00:19 +0000 (22:00 +0300)
This will allow to create 2 separate populations in
order to verify the effect of the hint.

It's fine if it's not exactly balanced in practice,
what matters is getting a significant amount of
traffic for both scenarios (origin trial is enabled +
an image is given high prio/origin trial is enabled +
no image is given special treatment).

Bug: T216499
Change-Id: I373960b2bed8437c2e97e6d729d43aff6901046c

includes/DefaultSettings.php
includes/media/ThumbnailImage.php

index af830fd..8b51c59 100644 (file)
@@ -9024,6 +9024,16 @@ $wgOriginTrials = [];
  */
 $wgPriorityHints = false;
 
+/**
+ * Ratio of requests that should get Priority Hints when the feature is enabled.
+ *
+ * @warning EXPERIMENTAL!
+ *
+ * @since 1.34
+ * @var float
+ */
+$wgPriorityHintsRatio = 1.0;
+
 /**
  * Enable Element Timing.
  *
index 36cf422..7ee6dcb 100644 (file)
@@ -110,7 +110,7 @@ class ThumbnailImage extends MediaTransformOutput {
         * @return string
         */
        function toHtml( $options = [] ) {
-               global $wgPriorityHints, $wgElementTiming;
+               global $wgPriorityHints, $wgPriorityHintsRatio, $wgElementTiming;
 
                if ( func_num_args() == 2 ) {
                        throw new MWException( __METHOD__ . ' called in the old style' );
@@ -133,8 +133,16 @@ class ThumbnailImage extends MediaTransformOutput {
                        && $this->width * $this->height > 100 * 100 ) {
                        self::$firstNonIconImageRendered = true;
 
-                       $attribs['importance'] = 'high';
-                       $elementTimingName = 'thumbnail-high';
+                       // Generate a random number between 0.01 and 1.0, included
+                       $random = rand( 1, 100 ) / 100.0;
+
+                       if ( $random <= $wgPriorityHintsRatio ) {
+                               $attribs['importance'] = 'high';
+                               $elementTimingName = 'thumbnail-high';
+                       } else {
+                               // This lets us track that the thumbnail *would* have gotten high priority but didn't.
+                               $elementTimingName = 'thumbnail-top';
+                       }
                }
 
                if ( $wgElementTiming ) {