Mercurial > hg > cc > azure
annotate workers/bin/test1.sh @ 55:c49b169339b1
use bindWorkerVars.sh
author | Henry S. Thompson <ht@markup.co.uk> |
---|---|
date | Fri, 08 Feb 2019 17:55:48 +0000 |
parents | bba589cab837 |
children |
rev | line source |
---|---|
8
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
1 #!/bin/bash |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
2 # Test script to split CC WAT files across threads |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
3 # to count http: vs. https: |
10 | 4 # Usage: [echo file file_id] | test1.sh id home [-t] numWorkerProcesses |
5 # If -t, no random wait, just id seconds | |
8
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
6 # remove >>errs once tested |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
7 #set -e -o pipefail |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
8 echo $$ > test1.pid |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
9 proc=$1 |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
10 res=res$proc |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
11 home=$2 |
10 | 12 shift 2 |
13
bba589cab837
shrinkJSON.sh: minimise "jq ." output
Henry S. Thompson <ht@markup.co.uk>
parents:
11
diff
changeset
|
13 function lrand { |
bba589cab837
shrinkJSON.sh: minimise "jq ." output
Henry S. Thompson <ht@markup.co.uk>
parents:
11
diff
changeset
|
14 # cheap bad little random number generator |
bba589cab837
shrinkJSON.sh: minimise "jq ." output
Henry S. Thompson <ht@markup.co.uk>
parents:
11
diff
changeset
|
15 echo $(( 1 + ($(openssl rand 1 | od -d | head -1 | tr -s ' ' | cut -f 2 -d ' ') % $1))) |
bba589cab837
shrinkJSON.sh: minimise "jq ." output
Henry S. Thompson <ht@markup.co.uk>
parents:
11
diff
changeset
|
16 } |
10 | 17 if [ "$1" = "-t" ] |
18 then | |
19 shift | |
20 pause=$proc | |
21 else | |
22 pause=$(lrand 60) | |
23 fi | |
24 wp=$1 | |
8
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
25 touch .running |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
26 function tryRead { |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
27 m=0 |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
28 set -o pipefail |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
29 until if [ $((m+=1)) -gt 5 ]; then echo "tried to read $1 5 times w/o success, giving up" 1>&2; return 1; fi && \ |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
30 curl -s --insecure -o - "$1"| zcat | fgrep msgtype=response | \ |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
31 { egrep -i '"WARC-Target-URI":"https?:' || : ;} > $2 |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
32 do |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
33 # try to avoid lockstep retries |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
34 echo ${PIPESTATUS[@]} 1>&2 |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
35 sleep $(lrand 10) |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
36 echo $(date) $2 retry number $m 1>&2 |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
37 done |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
38 set +o pipefail |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
39 } |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
40 trap "{ |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
41 #set -e -o pipefail |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
42 cd $res |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
43 ln -s ../nohup.cc . |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
44 tar -czhf - * | \ |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
45 ssh -o StrictHostKeyChecking=no -q $home \"{ cd data/jobs/ |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
46 mkdir -p test1.$proc |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
47 cd test1.$proc |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
48 tar -xzf - ; } 2>>errs.1\" |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
49 cd |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
50 rm -rf $res |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
51 ( sleep 5 ; rm nohup.cc ) & |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
52 }" EXIT |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
53 mkdir -p $res |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
54 log=$res/log |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
55 # Don't all start at once |
10 | 56 sleep $pause |
8
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
57 echo \# $(date) > $log |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
58 pRes=0 |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
59 while read s id |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
60 do |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
61 url="https://commoncrawl.s3.amazonaws.com/$s" |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
62 export ID=$id |
11 | 63 echo \# $(date) "running |$proc|$home|$pause|$wp|$id|" >> $log |
8
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
64 # Experimental retry loop |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
65 tryRead "$url" crawl$id |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
66 if [ -s crawl$id ] |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
67 then |
11 | 68 echo \# $(date) $id $(wc -l crawl$id) >> $log |
69 parallel --round-robin --pipe -j $wp "count1.sh {#} >> $res/{#} 2>>$res/errs{#}" < crawl$id || echo "ppfailed $? ${PIPESTATUS[@]}" 1>&2 | |
8
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
70 else |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
71 echo "crawl$id empty" 1>&2 |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
72 fi |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
73 rm crawl$id |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
74 done < ifile.txt 2>> $res/errs || pRes=$? |
10 | 75 ( cd $res && fgrep -h -v \# [1-9]* ) | tr -d \" > $res/tots |
8
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
76 echo \# $(date) main loop exit code=$pRes >> $log |
5db6015689a2
slightly updated, 4 W only, versions of old test4.sh and subcount.sh
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
77 rm .running |
10 | 78 |