run the test for the specified location first (makes it run faster, does not
change outcome)
bestcount=
bestmirror_benchmark()
{
bestcount=
bestmirror_benchmark()
{
+ bmb_curloc=$1
+ bmb_proto=$2
+ bmb_loc=$3
+ bmb_url=$4
+ bmb_fudge=$5
+
+ if [ -z "$bmb_loc" ]; then
# empty location is not allowed
return
fi
# empty location is not allowed
return
fi
*" "*)
# no protocol requested? all match
;;
*" "*)
# no protocol requested? all match
;;
# prefer location match
case " $newlocation " in
# prefer location match
case " $newlocation " in
+ *" $bmb_loc "*)
+ # bmb_curloc is true in first run, false in second
+ # so first run gets all matching locations
+ # so second run gets all non-matching locations
+ if ! $bmb_curloc; then
+ return
+ fi
+ if $bmb_curloc; then
+ return
+ fi
case " $newlocation " in
*" $bestlocation "*)
# worse
case " $newlocation " in
*" $bestlocation "*)
# worse
esac
case " $newlocation " in
esac
case " $newlocation " in
- msg "Testing speed of $3..."
+ msg "Testing speed of $bmb_url..."
- if ! thistime=`mirrorspeed "$3$testrepo"`; then
+ if ! thistime=`mirrorspeed "$bmb_url$testrepo"`; then
msg "-> FAILED"
return
fi
msg "-> FAILED"
return
fi
- thistime=$(($thistime $4))
+ thistime=$(($thistime $bmb_fudge))
msg "-> $thistime"
# anything is better than nothing
if [ -z "$besttime" ]; then
msg "-> $thistime"
# anything is better than nothing
if [ -z "$besttime" ]; then
- besturl=$3
- bestlocation=$2
+ besturl=$bmb_url
+ bestlocation=$bmb_loc
besttime=$thistime
bestcount=1
return
besttime=$thistime
bestcount=1
return
# prefer location match
case " $newlocation " in
# prefer location match
case " $newlocation " in
case " $newlocation " in
*" $bestlocation "*)
# equality
;;
*)
# better
case " $newlocation " in
*" $bestlocation "*)
# equality
;;
*)
# better
- besturl=$3
- bestlocation=$2
+ besturl=$bmb_url
+ bestlocation=$bmb_loc
besttime=$thistime
bestcount=1
return
besttime=$thistime
bestcount=1
return
if [ $thistime -gt $besttime ]; then
return
elif [ $thistime -lt $besttime ]; then
if [ $thistime -gt $besttime ]; then
return
elif [ $thistime -lt $besttime ]; then
+ besturl=$bmb_url
+ bestlocation=$bmb_loc
besttime=$thistime
bestcount=1
return
besttime=$thistime
bestcount=1
return
# both location and time match. Random decision.
bestcount=$(($bestcount + 1))
if [ $((($RANDOM + 0) % $bestcount)) -eq 0 ]; then
# both location and time match. Random decision.
bestcount=$(($bestcount + 1))
if [ $((($RANDOM + 0) % $bestcount)) -eq 0 ]; then
+ besturl=$bmb_url
+ bestlocation=$bmb_loc
- allmirrors bestmirror_benchmark
+ allmirrors bestmirror_benchmark true
+ allmirrors bestmirror_benchmark false