self._log.debug("Artifact cache server ping times: {}"
.format(", ".join(["{}: {:.6f} secs".format(*p) for p in pingtimes])))
argmin = min(range(len(pingtimes)), key=lambda i: pingtimes[i][1])
best_url = urls[argmin]
if pingtimes[argmin][1] == Pinger.UNREACHABLE:
return None // No reachable artifact caches.
self._log.debug("Best artifact cache is {0}".format(best_url))
return best_url
After Change
def select_best_url(self, remote_spec):
urls = remote_spec.split("|")
netloc_to_url = {urlparse.urlparse(url).netloc: url for url in urls}
pingtimes = self._pinger.pings(netloc_to_url.keys()) // List of pairs (host, time in ms).
self._log.debug("Artifact cache server ping times: {}"
.format(", ".join(["{}: {:.6f} secs".format(*p) for p in pingtimes])))