jenkins-bot has submitted this change and it was merged.

Change subject: Collect timing information about pool counter usage
......................................................................


Collect timing information about pool counter usage

We realized we don't have any good information about how pool
counters are utilized. This still doesn't get us what we want, meaning
the size of queue's throughout the day, but it should at least give
partial insight into how long requests are waiting which gives hints
at the size of the backlog.

Change-Id: I7a63da0ec1c53ef5a3ec7e89f23196149e8ca65e
---
M includes/Util.php
1 file changed, 37 insertions(+), 0 deletions(-)

Approvals:
  Gehel: Looks good to me, but someone else must approve
  Cindy-the-browser-test-bot: Looks good to me, but someone else must approve
  DCausse: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/Util.php b/includes/Util.php
index 2861b32..abe1887 100644
--- a/includes/Util.php
+++ b/includes/Util.php
@@ -99,6 +99,38 @@
        }
 
        /**
+        * @param string $type The pool counter type, such as 
CirrusSearch-Search
+        * @param bool $isSuccess If the pool counter gave a success, or failed 
the request
+        * @return string The key used for collecting timing stats about this 
pool counter request
+        */
+       private static function getPoolStatsKey( $type, $isSuccess ) {
+               $pos = strpos( $type, '-' );
+               if ( $pos !== false ) {
+                       $type = substr( $type, $pos + 1 );
+               }
+               $postfix = $isSuccess ? 'successMs' : 'failureMs';
+               return "CirrusSearch.poolCounter.$type.$postfix";
+       }
+
+       /**
+        * @param float $startPoolWork The time this pool request started, from 
microtime( true )
+        * @param string $type The pool counter type, such as 
CirrusSearch-Search
+        * @param bool $isSuccess If the pool counter gave a success, or failed 
the request
+        * @param callable $callback The function to wrap
+        * @return callable The original callback wrapped to collect pool 
counter stats
+        */
+       private static function wrapWithPoolStats( $startPoolWork, $type, 
$isSuccess, $callback ) {
+               return function () use ( $type, $isSuccess, $callback, 
$startPoolWork ) {
+                       RequestContext::getMain()->getStats()->timing(
+                               self::getPoolStatsKey( $type, $isSuccess ),
+                               intval( 1000 * (microtime( true ) - 
$startPoolWork) )
+                       );
+
+                       return call_user_func_array( $callback, func_get_args() 
);
+               };
+       }
+
+       /**
         * Wraps the complex pool counter interface to force the single call 
pattern
         * that Cirrus always uses.
         * @param string $type same as type parameter on PoolCounter::factory
@@ -134,6 +166,11 @@
                                return Status::newFatal( 
'cirrussearch-backend-error' );
                        };
                }
+               // wrap some stats collection on the success/failure handlers
+               $startPoolWork = microtime( true );
+               $workCallback = self::wrapWithPoolStats( $startPoolWork, $type, 
true, $workCallback );
+               $errorCallback = self::wrapWithPoolStats( $startPoolWork, 
$type, false, $errorCallback );
+
                $errorHandler = function( $key ) use ( $errorCallback, $user ) {
                        return function( Status $status ) use ( $errorCallback, 
$key, $user ) {
                                $status = $status->getErrorsArray();

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I7a63da0ec1c53ef5a3ec7e89f23196149e8ca65e
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/CirrusSearch
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <[email protected]>
Gerrit-Reviewer: Cindy-the-browser-test-bot <[email protected]>
Gerrit-Reviewer: DCausse <[email protected]>
Gerrit-Reviewer: EBernhardson <[email protected]>
Gerrit-Reviewer: Gehel <[email protected]>
Gerrit-Reviewer: Manybubbles <[email protected]>
Gerrit-Reviewer: Smalyshev <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to