wiki.techinc.nl/includes/libs/stats/IBufferingStatsdDataFactory.php
Timo Tijhof 1a558181b4 stats: Defer BufferingStatsdDataFactory::normalizeMetricKey to send phase
Avoid the time cost of normalizeMetricKey (and other effects of
produceStatsdData, such as holding on to StatsdData during the request),
by deferring it until we are about to send the data to the StatsD server.

As of this commit, the sending of data still happens pre-send which
means this change does not remove its delay from the HTTP response time.
But, it does have two other effects:

* It makes the cost of calling $stats->timing() and ->increment()
  much lower, which helps reduce the time attributed to calling
  `WANObjectCache->getWithSetCallback`.

* It prepares the code for moving this to post-send in a future patch.

* It moves the scattered cost to a centralised place in the flame graph.
  WMF's flame graphs are configued to crop the top of flames that are
  smaller than 1px. This is important for making the flame graphs render
  in a reasonable amount of time, but means that functions that have
  many unique paths to them hidden from view. Centralising this will
  make it easier to quantify how much time is spent here, which will
  be of use even after it becomes post-send, since we have flame graphs
  for post-send as well.

Also:

* Improve documentation.
* Add tests for normalizeMetricKey().

Bug: T288702
Change-Id: I1c57104590e48222b3e972589d49891b71afaee7
2021-09-10 19:39:20 +00:00

45 lines
972 B
PHP

<?php
use Liuggio\StatsdClient\Entity\StatsdData;
use Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface;
/**
* MediaWiki adaptation of StatsdDataFactory that provides buffering functionality.
*
* @stable to implement
* @since 1.30
* @see BufferingStatsdDataFactory
*/
interface IBufferingStatsdDataFactory extends StatsdDataFactoryInterface {
/**
* Check whether this data factory has any buffered data.
* @return bool
*/
public function hasData();
/**
* Return the buffered data from the factory.
* @return StatsdData[]
*/
public function getData();
/**
* Clear all buffered data from the factory
* @since 1.31
*/
public function clearData();
/**
* Return the number of buffered statsd data entries
* @return int
* @since 1.31
*/
public function getDataCount();
/**
* Set collection enable status.
* @param bool $enabled Will collection be enabled?
* @return void
*/
public function setEnabled( $enabled );
}