[yum-commits] urlgrabber/mirror.py

zpavlas at osuosl.org zpavlas at osuosl.org
Thu Oct 11 11:15:57 UTC 2012


 urlgrabber/mirror.py |   12 ++++++++++++
 1 file changed, 12 insertions(+)

New commits:
commit 5ea2711d22431aaf89ae01a6791b58313739d92c
Author: Zdeněk Pavlas <zpavlas at redhat.com>
Date:   Tue Oct 9 14:42:48 2012 +0200

    Sort mirrors using TH statistics.
    
    The main use case for this is when mirror #1 is down.  Parallel
    downloader avoids such mirror, but legacy mirror group code does not.
    This patch brings these in line.
    
    Legacy users that don't set the 'timedhosts' option are not affected
    (all mirrors evaluate to default speed and sorting is stable)
    
    caveats: This runs after the fastestmirror plugin (if enabled) has
    sorted the mirror list.  When TH file is used and contains enough
    host stats, FM order is mostly ignored.

diff --git a/urlgrabber/mirror.py b/urlgrabber/mirror.py
index eeeb5d0..7975f1b 100644
--- a/urlgrabber/mirror.py
+++ b/urlgrabber/mirror.py
@@ -97,6 +97,7 @@ import thread  # needed for locking to make this threadsafe
 from grabber import URLGrabError, CallbackObject, DEBUG, _to_utf8
 from grabber import _run_callback, _do_raise
 from grabber import exception2msg
+from grabber import _TH
 
 def _(st): 
     return st
@@ -261,6 +262,17 @@ class MirrorGroup:
         self.default_action = None
         self._process_kwargs(kwargs)
 
+        # use the same algorithm as parallel downloader to initially sort
+        # the mirror list (sort by speed, but prefer live private mirrors)
+        def estimate(m):
+            speed, fail = _TH.estimate(m['mirror'])
+            private = not fail and m.get('kwargs', {}).get('private', False)
+            return private, speed
+
+        # update the initial order.  since sorting is stable, the relative
+        # order of unknown (not used yet) hosts is retained.
+        self.mirrors.sort(key=estimate, reverse=True)
+
     # if these values are found in **kwargs passed to one of the urlXXX
     # methods, they will be stripped before getting passed on to the
     # grabber


More information about the Yum-commits mailing list