summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Kuzmenko <dmitry.a.kuzmenko@gmail.com>2022-07-27 11:15:57 +0000
committerDaniel M. Capella <polyzen@archlinux.org>2022-09-07 01:28:04 -0400
commit6614285be9846158a67eb410c21f4f1100773b08 (patch)
treec08e28b92fd63b7ef531b8f9d988e0b7f25de628
parent5ced8d0b5b0543c4fdbc23f8cc077b01f2fe0934 (diff)
Allow parallel time check
Adds an onptional ability to run each mirror test in parallel. This could possibly produce inaccurate results but speeds up the process for a number of mirrors. Thiw uses GNU parallel for parallel checks. Signed-off-by: Dmitry Kuzmenko <dmitry.kuzmenko@dsr-corporation.com>
-rw-r--r--src/rankmirrors.sh.in54
1 files changed, 41 insertions, 13 deletions
diff --git a/src/rankmirrors.sh.in b/src/rankmirrors.sh.in
index 9f728ee..fe4b885 100644
--- a/src/rankmirrors.sh.in
+++ b/src/rankmirrors.sh.in
@@ -42,6 +42,7 @@ usage() {
echo " -u, --url test a specific URL"
echo " -v, --verbose be verbose in output"
echo " -r, --repo specify a repository name instead of guessing"
+ echo " -p, --parallel run tests in parallel for all servers (may be inaccurate, depends on GNU parallel)"
exit 0
}
@@ -98,6 +99,11 @@ getfetchurl() {
# This exists to remove the need for a separate interrupt function
finaloutput() {
+ local -a timesarray=()
+ if [[ -f "$tmpfile" ]]; then
+ readarray -t timesarray <$tmpfile
+ rm $tmpfile
+ fi
IFS=$'\n' read -r -d '' -a sortedarray < \
<(printf '%s\n' "${timesarray[@]}" | LC_COLLATE=C sort)
@@ -144,6 +150,7 @@ while [[ $1 ]]; do
[[ $2 ]] || err "Must specify repository name.";
TARGETREPO="$2";
shift 2;;
+ parallel) PARALLEL=1 ; shift ;;
*) err "'$1' is an invalid argument."
esac
elif [[ ${1:0:1} = - ]]; then
@@ -177,6 +184,7 @@ while [[ $1 ]]; do
[[ $2 ]] || err "Must specify number.";
NUM="$2";
snum=2;;
+ p) PARALLEL=1 ;;
*) err "'$1' is an invalid argument." ;;
esac
done
@@ -197,6 +205,7 @@ done
[[ $MAX_TIME ]] || MAX_TIME=10
[[ $FILE && $CHECKURL ]] && err "Cannot specify a URL and mirrorfile."
[[ $FILE || $CHECKURL || $STDIN ]] || err "Must specify URL, mirrorfile, or stdin."
+[[ $PARALLEL ]] && ! command -v parallel >/dev/null 2>&1 && err "GNU parallel is not installed."
# Single URL handling
if [[ $CHECKURL ]]; then
@@ -215,7 +224,30 @@ elif [[ $FILE ]]; then
echo "# Server list generated by rankmirrors on $(date +%Y-%m-%d)"
fi
-timesarray=()
+get_url_time() {
+ server=$1
+ url="$(getfetchurl "$server")"
+ [[ $url = fail ]] && err "URL '$server' is malformed."
+ time=$(gettime "$url")
+ echo "$time $server" >>$tmpfile
+
+ # Output
+ if [[ $VERBOSE && $TIMESONLY ]]; then
+ echo "$server ... $time"
+ elif [[ $VERBOSE ]]; then
+ echo "# $server ... $time"
+ elif [[ $TIMESONLY ]]; then
+ echo -n " *"
+ fi
+}
+
+tmpfile=$(mktemp)
+if [[ $PARALLEL ]]; then
+ servers=()
+ # Exports for GNU parallel
+ export MAX_TIME ARCH TARGETREPO VERBOSE TIMESONLY tmpfile
+ export -f getfetchurl gettime get_url_time
+fi
for line in "${linearray[@]}"; do
if [[ $line =~ ^[[:space:]]*# ]]; then
[[ $TIMESONLY ]] || echo $line
@@ -224,19 +256,15 @@ for line in "${linearray[@]}"; do
# Getting values and times and such
server="${line#*= }"
server="${server%%#*}"
- url="$(getfetchurl "$server")"
- [[ $url = fail ]] && err "URL '$URL' is malformed."
- time=$(gettime "$url")
- timesarray+=("$time $server")
-
- # Output
- if [[ $VERBOSE && $TIMESONLY ]]; then
- echo "$server ... $time"
- elif [[ $VERBOSE ]]; then
- echo "# $server ... $time"
- elif [[ $TIMESONLY ]]; then
- echo -n " *"
+
+ if [[ $PARALLEL ]]; then
+ servers+=($server)
+ else
+ get_url_time $server
fi
fi
done
+if [[ $PARALLEL ]]; then
+ parallel get_url_time ::: "${servers[@]}"
+fi
finaloutput