2016-01-01 14:12:43 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
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() {
|
|
|
|
SERVERURL=$1
|
|
|
|
TABLE=$2
|
|
|
|
sql $SERVERURL "select Host,Command,V1,V2,Stdout,Stderr from $TABLE order by seq;"
|
|
|
|
}
|
2016-01-01 14:12:43 +00:00
|
|
|
|
2016-07-06 13:58:47 +00:00
|
|
|
p_wrapper() {
|
|
|
|
INNER=$1
|
2016-07-06 17:04:52 +00:00
|
|
|
SERVERURL=$(eval echo $2)
|
2016-07-06 13:58:47 +00:00
|
|
|
TABLE=TBL$RANDOM
|
|
|
|
DBURL=$SERVERURL/$TABLE
|
|
|
|
T1=$(tempfile)
|
|
|
|
T2=$(tempfile)
|
|
|
|
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
|
|
|
|
}
|
2016-01-01 14:12:43 +00:00
|
|
|
|
2016-07-06 17:04:52 +00:00
|
|
|
p_template() {
|
|
|
|
(sleep 2; 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-07-06 17:04:52 +00:00
|
|
|
export -f p_template
|
2016-01-01 14:12:43 +00:00
|
|
|
|
2016-07-06 13:58:47 +00:00
|
|
|
par_sqlandworker() {
|
2016-07-06 17:04:52 +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() {
|
2016-07-06 17:04:52 +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() {
|
|
|
|
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_linebuffer() {
|
|
|
|
p_template --linebuffer
|
2016-07-06 13:58:47 +00:00
|
|
|
}
|
|
|
|
|
2016-07-06 17:04:52 +00:00
|
|
|
par_sqlandworker_tag() {
|
|
|
|
p_template --tag
|
2016-07-06 13:58:47 +00:00
|
|
|
}
|
|
|
|
|
2016-07-06 17:04:52 +00:00
|
|
|
par_sqlandworker_linebuffer_tag() {
|
|
|
|
p_template --linebuffer --tag
|
2016-07-06 13:58:47 +00:00
|
|
|
}
|
|
|
|
|
2016-07-06 17:04:52 +00:00
|
|
|
par_sqlandworker_compress_linebuffer_tag() {
|
|
|
|
p_template --compress --linebuffer --tag
|
2016-07-06 13:58:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
par_sqlandworker_unbuffer() {
|
2016-07-06 17:04:52 +00:00
|
|
|
p_template -u
|
2016-07-06 13:58:47 +00:00
|
|
|
}
|
|
|
|
|
2016-07-06 17:04:52 +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)
|
|
|
|
compgen -A function | grep par_ | sort |
|
2016-07-06 17:04:52 +00:00
|
|
|
stdout parallel -vj5 -k --tag --joblog /tmp/jl-`basename $0` p_wrapper \
|
|
|
|
:::: - ::: \$MYSQL \$PG \$SQLITE
|