Add configurable delay between purgeChangedPages batches
authorBryan Davis <bd808@wikimedia.org>
Fri, 11 Oct 2013 19:42:10 +0000 (13:42 -0600)
committerOri.livneh <ori@wikimedia.org>
Tue, 15 Oct 2013 15:38:52 +0000 (15:38 +0000)
UDP flooding is possible when purging large numbers of files. This
change adds a command line switch to the purgeChangedPages.php
maintenance script to insert an artificial delay between purge batches.
The intent is to allow the network time to process the batch that was
just sent before flooding with a second batch.

`--sleep-per-batch` can be used in combination with `--batch-size` to
manage network and to some extent query load. A suggested starting point
would be to use `--sleep-per-batch=500` in concert with the default
batch size of 100 to target a maximum rate of 200 packets/second.

Bug: 55632
Change-Id: Ibfc54b1767f145098465404a2b23cd92852e41fd

maintenance/purgeChangedPages.php

index e1c6ab6..071ac09 100644 (file)
@@ -41,6 +41,7 @@ class PurgeChangedPages extends Maintenance {
                $this->addOption( 'starttime', 'Starting timestamp', true, true );
                $this->addOption( 'endtime', 'Ending timestamp', true, true );
                $this->addOption( 'htcp-dest', 'HTCP announcement destination (IP:port)', false, true );
+               $this->addOption( 'sleep-per-batch', 'Milliseconds to sleep between batches', false, true );
                $this->addOption( 'dry-run', 'Do not send purge requests' );
                $this->addOption( 'verbose', 'Show more output', false, false, 'v' );
                $this->setBatchSize( 100 );
@@ -135,8 +136,13 @@ class PurgeChangedPages extends Maintenance {
                        }
 
                        // Send batch of purge requests out to squids
-                       $squid = new SquidUpdate( $urls );
+                       $squid = new SquidUpdate( $urls, count( $urls ) );
                        $squid->doUpdate();
+
+                       if ( $this->hasOption( 'sleep-per-batch' ) ) {
+                               // sleep-per-batch is milliseconds, usleep wants micro seconds.
+                               usleep( 1000 * (int)$this->getOption( 'sleep-per-batch' ) );
+                       }
                }
 
                $this->output( "Done!\n" );