2016-01-01 14:12:43 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2021-12-26 22:29:28 +00:00
|
|
|
# SPDX-FileCopyrightText: 2021-2022 Ole Tange, http://ole.tange.dk and Free Software and Foundation, Inc.
|
2021-03-22 20:16:35 +00:00
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2016-01-01 14:12:43 +00:00
|
|
|
export SQLITE=sqlite3:///%2Frun%2Fshm%2Fparallel.db
|
2016-07-06 13:58:47 +00:00
|
|
|
export PG=pg://`whoami`:`whoami`@lo/`whoami`
|
|
|
|
export MYSQL=mysql://`whoami`:`whoami`@lo/`whoami`
|
2016-01-01 14:12:43 +00:00
|
|
|
|
2016-07-06 13:58:47 +00:00
|
|
|
export DEBUG=false
|
2016-01-01 14:12:43 +00:00
|
|
|
|
2016-07-06 13:58:47 +00:00
|
|
|
p_showsqlresult() {
|
2020-01-12 08:14:21 +00:00
|
|
|
SERVERURL=$1
|
|
|
|
TABLE=$2
|
|
|
|
# No hostname as it can differ
|
|
|
|
sql $SERVERURL "select Command,V1,V2,Stdout,Stderr from $TABLE order by seq;"
|
2016-07-06 13:58:47 +00:00
|
|
|
}
|
2016-01-01 14:12:43 +00:00
|
|
|
|
2016-07-06 13:58:47 +00:00
|
|
|
p_wrapper() {
|
2020-01-12 08:14:21 +00:00
|
|
|
INNER=$1
|
|
|
|
SERVERURL=$(eval echo $2)
|
|
|
|
TABLE=TBL$RANDOM
|
|
|
|
DBURL=$SERVERURL/$TABLE
|
2022-05-22 08:36:45 +00:00
|
|
|
T1=$(mktemp)
|
|
|
|
T2=$(mktemp)
|
2020-01-12 08:14:21 +00:00
|
|
|
eval "$INNER"
|
|
|
|
echo Exit=$?
|
|
|
|
wait
|
|
|
|
echo Exit=$?
|
|
|
|
$DEBUG && sort -u $T1 $T2;
|
|
|
|
rm $T1 $T2
|
|
|
|
p_showsqlresult $SERVERURL $TABLE
|
|
|
|
$DEBUG || sql $SERVERURL "drop table $TABLE;" >/dev/null 2>/dev/null
|
2016-07-06 13:58:47 +00:00
|
|
|
}
|
2016-01-01 14:12:43 +00:00
|
|
|
|
2016-07-06 17:04:52 +00:00
|
|
|
p_template() {
|
2020-01-12 08:14:21 +00:00
|
|
|
(
|
|
|
|
# Make sure all jobs are inserted before starting a worker
|
|
|
|
sleep 10;
|
|
|
|
parallel --sqlworker $DBURL "$@" sleep .3\;echo >$T1
|
|
|
|
) &
|
|
|
|
parallel --sqlandworker $DBURL "$@" sleep .3\;echo ::: {1..5} ::: {a..e} >$T2;
|
2016-07-06 13:58:47 +00:00
|
|
|
}
|
2016-01-01 14:12:43 +00:00
|
|
|
|
2016-07-06 13:58:47 +00:00
|
|
|
par_sqlandworker() {
|
2020-01-12 08:14:21 +00:00
|
|
|
p_template
|
2016-07-06 13:58:47 +00:00
|
|
|
}
|
2016-01-01 14:12:43 +00:00
|
|
|
|
2016-07-06 13:58:47 +00:00
|
|
|
par_sqlandworker_lo() {
|
2020-01-12 08:14:21 +00:00
|
|
|
p_template -S lo
|
2016-07-06 13:58:47 +00:00
|
|
|
}
|
2016-01-01 14:12:43 +00:00
|
|
|
|
2016-07-06 17:04:52 +00:00
|
|
|
par_sqlandworker_results() {
|
2020-01-12 08:14:21 +00:00
|
|
|
p_template --results /tmp/out--sql
|
2016-07-06 13:58:47 +00:00
|
|
|
}
|
2016-01-01 14:12:43 +00:00
|
|
|
|
2016-07-06 17:04:52 +00:00
|
|
|
par_sqlandworker_tag() {
|
2020-01-12 08:14:21 +00:00
|
|
|
p_template --tag
|
2016-07-06 13:58:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
par_sqlandworker_unbuffer() {
|
2020-01-12 08:14:21 +00:00
|
|
|
p_template -u
|
2016-07-06 13:58:47 +00:00
|
|
|
}
|
|
|
|
|
2016-12-07 12:12:23 +00:00
|
|
|
par_sqlandworker_total_jobs() {
|
2020-01-12 08:14:21 +00:00
|
|
|
p_template echo {#} of '{=1 $_=total_jobs(); =};'
|
2016-12-07 12:12:23 +00:00
|
|
|
}
|
|
|
|
|
2017-01-14 21:57:23 +00:00
|
|
|
par_append_different_cmd() {
|
2020-01-12 08:14:21 +00:00
|
|
|
parallel --sqlmaster $DBURL sleep .3\;echo ::: {1..5} ::: {a..e} >$T2;
|
|
|
|
parallel --sqlmaster +$DBURL sleep .3\;echo {2}-{1} ::: {11..15} ::: {A..E} >>$T2;
|
|
|
|
parallel --sqlworker $DBURL >$T1
|
2016-12-07 13:33:50 +00:00
|
|
|
}
|
2016-07-06 17:04:52 +00:00
|
|
|
|
2016-12-14 07:48:27 +00:00
|
|
|
par_shuf() {
|
2020-01-12 08:14:21 +00:00
|
|
|
MD5=$(echo $SERVERURL | md5sum | perl -pe 's/(...).*/$1/')
|
|
|
|
T=/tmp/parallel-bug49791-$MD5
|
|
|
|
[ -e $T ] && rm -rf $T
|
|
|
|
export PARALLEL="--shuf --result $T"
|
|
|
|
parallel --sqlandworker $DBURL sleep .3\;echo \
|
|
|
|
::: {1..5} ::: {a..e} >$T2;
|
|
|
|
parallel --sqlworker $DBURL >$T2 &
|
|
|
|
parallel --sqlworker $DBURL >$T2 &
|
|
|
|
parallel --sqlworker $DBURL >$T2 &
|
|
|
|
parallel --sqlworker $DBURL >$T2 &
|
|
|
|
unset PARALLEL
|
|
|
|
wait;
|
|
|
|
# Did it compute correctly?
|
|
|
|
cat $T/1/*/*/*/stdout
|
|
|
|
# Did it shuffle
|
|
|
|
SHUF=$(sql $SERVERURL "select Host,Command,V1,V2,Stdout,Stderr from $TABLE order by seq;")
|
|
|
|
export PARALLEL="--result $T"
|
|
|
|
parallel --sqlandworker $DBURL sleep .3\;echo \
|
|
|
|
::: {1..5} ::: {a..e} >$T2;
|
|
|
|
parallel --sqlworker $DBURL >$T2 &
|
|
|
|
parallel --sqlworker $DBURL >$T2 &
|
|
|
|
parallel --sqlworker $DBURL >$T2 &
|
|
|
|
parallel --sqlworker $DBURL >$T2 &
|
|
|
|
unset PARALLEL
|
|
|
|
wait;
|
|
|
|
NOSHUF=$(sql $SERVERURL "select Host,Command,V1,V2,Stdout,Stderr from $TABLE order by seq;")
|
|
|
|
DIFFSIZE=$(diff <(echo "$SHUF") <(echo "$NOSHUF") | wc -c)
|
|
|
|
if [ $DIFFSIZE -gt 2500 ]; then
|
|
|
|
echo OK: Diff bigger than 2500 char
|
|
|
|
fi
|
|
|
|
[ -e $T ] && rm -rf $T
|
|
|
|
touch $T1
|
2016-12-14 07:48:27 +00:00
|
|
|
}
|
|
|
|
|
2016-12-18 10:14:06 +00:00
|
|
|
par_sql_joblog() {
|
2020-01-12 08:14:21 +00:00
|
|
|
echo '### should only give a single --joblog heading'
|
|
|
|
echo '### --sqlmaster/--sqlworker'
|
|
|
|
parallel -k --joblog - --sqlmaster $DBURL --wait sleep .3\;echo ::: {1..5} ::: {a..e} |
|
|
|
|
perl -pe 's/\d+\.\d+/999.999/g' | sort -n &
|
|
|
|
sleep 0.5
|
2022-05-22 08:36:45 +00:00
|
|
|
T=$(mktemp)
|
2020-01-12 08:14:21 +00:00
|
|
|
parallel -k --joblog - --sqlworker $DBURL > $T
|
|
|
|
wait
|
|
|
|
# Needed because of race condition
|
|
|
|
cat $T; rm $T
|
|
|
|
echo '### --sqlandworker'
|
|
|
|
parallel -k --joblog - --sqlandworker $DBURL sleep .3\;echo ::: {1..5} ::: {a..e} |
|
|
|
|
perl -pe 's/\d+\.\d+/999.999/g' | sort -n
|
|
|
|
# TODO --sqlandworker --wait
|
2016-12-18 10:14:06 +00:00
|
|
|
}
|
|
|
|
|
2017-01-14 22:36:59 +00:00
|
|
|
par_no_table() {
|
|
|
|
echo 'bug #50018: --dburl without table dies'
|
|
|
|
parallel --sqlworker $SERVERURL
|
|
|
|
echo $?
|
|
|
|
parallel --sqlandworker $SERVERURL echo ::: no_output
|
|
|
|
echo $?
|
|
|
|
parallel --sqlmaster $SERVERURL echo ::: no_output
|
|
|
|
echo $?
|
|
|
|
# For p_wrapper to remove table
|
|
|
|
parallel --sqlandworker $DBURL true ::: dummy ::: dummy
|
|
|
|
}
|
2016-12-14 07:48:27 +00:00
|
|
|
|
2016-07-06 13:58:47 +00:00
|
|
|
export -f $(compgen -A function | egrep 'p_|par_')
|
|
|
|
# Tested that -j0 in parallel is fastest (up to 15 jobs)
|
2017-01-14 21:57:23 +00:00
|
|
|
# more than 3 jobs: sqlite locks
|
2020-01-12 08:14:21 +00:00
|
|
|
export LC_ALL=C
|
|
|
|
compgen -A function | grep par_ | sort |
|
|
|
|
stdout parallel --timeout 2000 -vj50% -k --tag --joblog /tmp/jl-`basename $0` p_wrapper \
|
2016-07-06 17:04:52 +00:00
|
|
|
:::: - ::: \$MYSQL \$PG \$SQLITE
|