Giuseppe Lavagetto has uploaded a new change for review.

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

Change subject: Add support for connect_timeout
......................................................................

Add support for connect_timeout

Since we have had a series of outages related to one of the poolcounter
servers being unreachable (more properly, not responding to SYNs), we
implement here what we already do for mysql connections: if we set a
connection timeout to a very small value (in the order of magnitude of
twice the RTT to the poolcounter server) and retry twice, we can have
very fast failures in case one server goes down, and the failover to the
other active servers would happen almost harmlessly (some latency in
acquiring the poolcounter lock) or at least not killing any high-traffic
deployment.

Bug: T105378
Change-Id: I3f11728088dbe740062808cb04723da099200e17
---
M PoolCounterClient_body.php
1 file changed, 24 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/PoolCounter 
refs/changes/96/231996/1

diff --git a/PoolCounterClient_body.php b/PoolCounterClient_body.php
index aebf82a..733d9c6 100644
--- a/PoolCounterClient_body.php
+++ b/PoolCounterClient_body.php
@@ -8,6 +8,8 @@
        function __construct( $conf ) {
                $this->hostNames = $conf['servers'];
                $this->timeout = isset( $conf['timeout'] ) ? $conf['timeout'] : 
0.1;
+               $this->connect_timeout = isset( $conf['connect_timeout'] ) ?
+                       $conf['connect_timeout'] : 0;
                if ( !count( $this->hostNames ) ) {
                        throw new MWException( __METHOD__ . ': no servers 
configured' );
                }
@@ -53,7 +55,28 @@
         * Open a socket. Just a wrapper for fsockopen()
         */
        private function open( $host, $port, &$errno, &$errstr ) {
-               return fsockopen( $host, $port, $errno, $errstr, $this->timeout 
);
+               # If connect_timeout is set, we try twice to open the socket.
+               # You usually want to set the connection timeout to a very
+               # small value so that in case of failure of a server the
+               # connection to poolcounter is not a SPOF.
+               if ( $this->connect_timeout > 0 ) {
+                       $retries = 2;
+                       $timeout = $this->connect_timeout;
+               } else {
+                       $retries = 1;
+                       $timeout = $this->timeout;
+               }
+
+               for ($i=0; $i < $retries; $i++) {
+                       if ($i > 0) {
+                               usleep(1000);
+                       }
+                       $s = fsockopen( $host, $port, $errno, $errstr, $timeout 
);
+                       if ($s) {
+                               return $s;
+                       }
+               }
+               return false;
        }
 
        /**

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3f11728088dbe740062808cb04723da099200e17
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/PoolCounter
Gerrit-Branch: master
Gerrit-Owner: Giuseppe Lavagetto <glavage...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to