Skip to content

Commit beeca38

Browse files
committed
Script to submit jobs to work-loop.sh. Initial version does lots of sanity checks
and will loop over a simple DATASIZE progression. FossilOrigin-Name: c8dcb7d0e8769e37e3b77329b345b7983dfb6859cc850523871175c4306410b4
1 parent 5df7409 commit beeca38

File tree

1 file changed

+260
-0
lines changed

1 file changed

+260
-0
lines changed

kbench/submit-work.sh

Lines changed: 260 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,260 @@
1+
#!/bin/bash
2+
#
3+
# Submit LumoSQL benchmark / test runs to a cluster
4+
#
5+
# LumoSQL: https://lumosql.org/
6+
# Cluster scripts: https://lumosql.org/src/lumosql/dir?ci=tip&name=kbench
7+
#
8+
9+
# Set defaults
10+
11+
PROGNAME=`basename $0`
12+
LOCKFILE="/tmp/$PROGNAME" # trivial mkdir(1) locking good enough for this use case
13+
OUTMAKEFRAG="/tmp/$PROGNAME.Makefile.include"
14+
MAKEFRAG="./Makefile.include"
15+
LOGFILE="./"$PROGNAME".log"
16+
DEBUG=""
17+
DRYRUN=""
18+
19+
PrintHelp() {
20+
21+
echo " "
22+
echo "$PROGNAME"
23+
echo " "
24+
echo " Submit a LumoSQL benchmarking/test job to a cluster. The input Makefile fragment (which must exist)"
25+
echo " contains variables which can be overridden by the commandline or calculated by this tool, and then a new"
26+
echo " Makefile fragment is generated and submitted. Basic concurrency checking is done but this tool"
27+
echo " is easy to abuse. A simple logfile is created. It is best to omit references to DATASIZE in JOBNAME because"
28+
echo " this script adds the name."
29+
echo " "
30+
echo " mandatory options:"
31+
echo " none yet."
32+
echo " "
33+
echo " optional options:"
34+
echo " -j specify job name, eg \"bench-ds-inteli7-sqlite-all\". Default is \$JOBNAME."
35+
echo " -c cluster address, eg \"tovenaar.example.org\". Default is \$CLUSTER."
36+
echo " -m filename of an input Makefile fragment, eg \"ClusterVars.txt\". Default is \"$MAKEFRAG\"."
37+
echo " -l logfile name to append to. Default is \"$PROGNAME.log\"."
38+
echo " -b beginning datasize."
39+
echo " -e ending datasize. Required if -b specified."
40+
echo " -d debug."
41+
echo " -f fake dry run. Makes it easy to test jobs without actually submitting."
42+
echo " -h this help text."
43+
echo " "
44+
echo " example: "
45+
echo " "
46+
echo " ./$PROGNAME -b 2 -e 20 -c tovenaar.example.org"
47+
exit 1
48+
}
49+
50+
ErrorExit() {
51+
52+
echo "Error: $1."
53+
echo "See \"$PROGNAME -h\" for help"
54+
exit 1
55+
}
56+
57+
58+
ExecCommand() {
59+
60+
local thecommand=$1
61+
local return_output=$2 # if set, caller expects to catch the output
62+
local output
63+
64+
if [[ ! -z $DEBUG ]]; then echo "about to run: $thecommand" ; fi
65+
66+
echo $thecommand
67+
68+
output=$(eval $thecommand) # eval can go wrong in so many ways...
69+
70+
if [[ ( $? != 0 ) ]]; then ErrorExit "Failed: $thecommand" ; fi
71+
72+
if [[ ! -z $return_output ]]; then
73+
echo $output
74+
fi
75+
76+
}
77+
78+
Cleanup() {
79+
80+
if [[ -d $LOCKFILE ]]; then /usr/bin/rm -d $LOCKFILE ; fi
81+
if [[ -f $OUTMAKEFRAG ]]; then /usr/bin/rm $OUTMAKEFRAG ; fi
82+
echo "$(date +%Y-%m-%d) $PROGNAME finished" >> $LOGFILE
83+
84+
}
85+
86+
GenerateOutMakefile() {
87+
88+
# We have already sourced the Makefile fragment, if one exists, setting the DATASIZE variable
89+
local line
90+
local size=$1
91+
92+
echo "# Output Makefile fragment from $PROGNAME" > $OUTMAKEFRAG
93+
if [[ ! -z $MAKEFRAG ]]; then
94+
while read line; do
95+
if [[ ! $line =~ .*"DATASIZE".* ]]; then
96+
echo $line >> $OUTMAKEFRAG
97+
fi
98+
done < $MAKEFRAG
99+
fi
100+
echo "DATASIZE="$size >> $OUTMAKEFRAG
101+
# eval "cat $OUTMAKEFRAG"
102+
}
103+
104+
SubmitOneJob() {
105+
106+
local cmd
107+
local output
108+
local summary
109+
local x
110+
local size=$1
111+
local myjobname
112+
113+
myjobname=$JOBNAME-$size
114+
GenerateOutMakefile $size
115+
# break this string up because quoting in Bash related to eval() is fragile
116+
x="\"Authorization: Bearer $TOKEN\""
117+
cmd="curl -vv -L -H "$x" -X PUT $CLUSTER/job/$myjobname --data-binary $OUTMAKEFRAG 2>&1"
118+
119+
if [[ $DRYRUN == "yes" ]]; then
120+
echo "DRY RUN"
121+
echo "Would have executed: "$cmd
122+
echo "Would have submitted: "$myjobname
123+
else
124+
output=$(ExecCommand "$cmd" yes)
125+
if [[ $output =~ .*"HTTP/2 403".* ]]; then
126+
summary="$(date +%Y-%m-%d) Authorisation error from cluster "
127+
else
128+
summary="$(date +%Y-%m-%d) Submitted $myjobname " # check actual return codes here
129+
fi
130+
echo $summary >> $LOGFILE
131+
echo $summary
132+
fi
133+
}
134+
135+
#### Script starts here
136+
137+
mkdir $LOCKFILE || ErrorExit "Another instance of $PROGNAME is running"
138+
trap Cleanup EXIT
139+
140+
while getopts ":j:c:m:l:b:e:dfh" flag; do
141+
case $flag in
142+
j) JOBNAME=$OPTARG;;
143+
c) CLUSTER=$OPTARG;;
144+
m) CMDMAKEFRAG=$OPTARG;;
145+
l) LOGFILE=$OPTARG;;
146+
b) BEGINSIZE=$OPTARG;;
147+
e) ENDSIZE=$OPTARG;;
148+
d) DEBUG="yes";;
149+
f) DRYRUN="yes";;
150+
h) HELPHELP="help";;
151+
\?) ErrorExit "Unknown option -$OPTARG" ;;
152+
:) ErrorExit "Missing option argument for -$OPTARG" ;;
153+
*) ErrorExit "Unimplemented option: -$OPTARG" ;;
154+
esac
155+
done
156+
157+
if [[ $DEBUG == "yes" ]]; then
158+
echo "JOBNAME=$JOBNAME"
159+
echo "CLUSTER=$CLUSTER"
160+
echo "MAKEFRAG=$MAKEFRAG"
161+
echo "CMDMAKEFRAG=$MAKEFRAG"
162+
echo "LOGFILE=$LOGFILE"
163+
echo "BEGINSIZE=$BEGINSIZE"
164+
echo "ENDSIZE=$ENDSIZE"
165+
echo "DRYRUN=$DRYRUN"
166+
echo "DEBUG=yes"
167+
echo "HELPHELP=help"
168+
169+
echo "TOKEN=$TOKEN" # never set by this script
170+
fi
171+
172+
if [[ ( $OPTIND -lt 2) || (! -z $HELPHELP) ]]; #change OPTIND when there are mandator parameters
173+
then
174+
PrintHelp ;
175+
fi
176+
177+
if [[ -z $TOKEN ]];
178+
then
179+
ErrorExit "Need to set \$TOKEN outside $PROGNAME"
180+
fi
181+
182+
if [[ -z $JOBNAME ]];
183+
then
184+
ErrorExit "Need to set \$JOBNAME either outside $PROGNAME or on the commandline"
185+
fi
186+
187+
if [[ ! -z $CMDMAKEFRAG ]]; then
188+
if [[ ! -f $CMDMAKEFRAG ]]; then
189+
ErrorExit "Makefile fragment $CMDMAKEFRAG specified with -m but does not exist"
190+
else
191+
MAKEFRAG=$CMDMAKEFRAG
192+
fi
193+
else
194+
if [[ ! -f $MAKEFRAG ]]; then
195+
# No input Makefile fragment available
196+
# Insist on having one for now; in future this script can generate one
197+
ErrorExit "Makefile fragment $MAKEFRAG does not exist"
198+
fi
199+
fi
200+
201+
if [[ ! `which nmap` ]];
202+
then
203+
ErrorExit "nmap needs to be in path"
204+
fi
205+
206+
if [[ ( -z $JOBNAME ) ]]; then
207+
ErrorExit "\$JOBNAME must be set either by -j or outside $PROGNAME"
208+
fi
209+
210+
if [[ ( -z $CLUSTER ) ]]; then
211+
ErrorExit "\$CLUSTER must be set either by -c or outside $PROGNAME"
212+
else
213+
output=$(ExecCommand "nmap -p 443 $CLUSTER" yes)
214+
if [[ ! $output =~ .*"443/tcp open".* ]]; then
215+
ErrorExit "$CLUSTER is not reachable, according to nmap"
216+
fi
217+
fi
218+
219+
if [[ ( ! -z $BEGINSIZE) && ( -z $ENDSIZE) ]]; then
220+
ErrorExit "If -b specified then -e is also required" ;
221+
fi
222+
223+
if [[ ( ! -z $ENDSIZE) && ( -z $BEGINSIZE) ]]; then
224+
ErrorExit "If -e specified then -b is also required" ;
225+
fi
226+
227+
228+
if [[ ($EUID -eq 0) ]]; then
229+
ErrorExit "Unaudited script running as root." ;
230+
fi
231+
232+
if [[ ( ! -z $BEGINSIZE ) ]]; then
233+
# The following tests if $BEGINSIZE is an integer, and also proves that bash is mad.
234+
# It works because bash throws an error if you pass strings to an integer comparison.
235+
[ -n "$BEGINSIZE" ] && [ "$BEGINSIZE" -eq "$BEGINSIZE" ] 2>/dev/null
236+
if [ $? -ne 0 ]; then
237+
ErrorExit "-b $BEGINSIZE not an integer" ;
238+
fi
239+
[ -n "$ENDSIZE" ] && [ "$ENDSIZE" -eq "$ENDSIZE" ] 2>/dev/null
240+
if [ $? -ne 0 ]; then
241+
ErrorExit "-e $ENDSIZE not an integer" ;
242+
fi
243+
fi
244+
245+
echo "$(date +%Y-%m-%d) $PROGNAME started" >> $LOGFILE || ErrorExit "Cannot write to logfile $LOGFILE"
246+
247+
if [[ (-z $BEGINSIZE) ]]; then
248+
SubmitOneJob "1,1"
249+
else
250+
i=$BEGINSIZE
251+
while [ $i -lt $ENDSIZE ];
252+
do
253+
DATASIZE="$i,$ENDSIZE"
254+
SubmitOneJob $DATASIZE
255+
DATASIZE="$ENDSIZE,$i"
256+
SubmitOneJob $DATASIZE
257+
i=$(( i += 2 ))
258+
done
259+
fi
260+

0 commit comments

Comments
 (0)