Hack to fix job log links (because crunch still produces identifiers with +K@qr1hi)
[arvados.git] / doc / user / tutorials / tutorial-job1.html.textile.liquid
1 ---
2 layout: default
3 navsection: userguide
4 navmenu: Tutorials
5 title: "Running a Crunch job"
6
7 ...
8
9 h1. Running a crunch job
10
11 This tutorial introduces the concepts and use of the Crunch job system using the @arv@ command line tool and Arvados Workbench.
12
13 *This tutorial assumes that you are "logged into an Arvados VM instance":{{site.basedoc}}/user/getting_started/ssh-access.html#login, and have a "working environment.":{{site.basedoc}}/user/getting_started/check-environment.html*
14
15 In "retrieving data using Keep,":tutorial-keep.html we downloaded a file from Keep and did some computation with it (specifically, computing the md5 hash of the complete file).  While a straightforward way to accomplish a computational task, there are several obvious drawbacks to this approach:
16 * Large files require significant time to download.
17 * Very large files may exceed the scratch space of the local disk.
18 * We are only able to use the local CPU to process the file.
19
20 The Arvados "Crunch" framework is designed to support processing very large data batches (gigabytes to terabytes) efficiently, and provides the following benefits:
21 * Increase concurrency by running tasks asynchronously, using many CPUs and network interfaces at once (especially beneficial for CPU-bound and I/O-bound tasks respectively).
22 * Track inputs, outputs, and settings so you can verify that the inputs, settings, and sequence of programs you used to arrive at an output is really what you think it was.
23 * Ensure that your programs and workflows are repeatable with different versions of your code, OS updates, etc.
24 * Interrupt and resume long-running jobs consisting of many short tasks.
25 * Maintain timing statistics automatically, so they're there when you want them.
26
27 For your first job, you will run the "hash" crunch script using the Arvados system.  The "hash" script computes the md5 hash of each file in a collection.
28
29 Crunch jobs are described using JSON objects.  For example:
30
31 <notextile>
32 <pre><code>$ <span class="userinput">cat &gt;the_job &lt;&lt;EOF
33 {
34  "script": "hash",
35  "script_version": "arvados:master",
36  "script_parameters":
37  {
38   "input": "c1bad4b39ca5a924e481008009d94e32+210"
39  }
40 }
41 EOF
42 </code></pre>
43 </notextile>
44
45 * @cat@ is a standard Unix utility that simply copies standard input to standard output
46 * @<<EOF@ tells the shell to direct the following lines into the standard input for @cat@ up until it sees the line @EOF@
47 * @>the_job@ redirects standard output to a file called @the_job@
48 * @"script"@ specifies the name of the script to run.  The script is searched for in the "crunch_scripts/" subdirectory of the @git@ checkout specified by @"script_version"@.
49 * @"script_version"@ specifies the version of the script that you wish to run.  This can be in the form of an explicit @git@ revision hash, or in the form "repository:branch" (in which case it will take the HEAD of the specified branch).  Arvados logs the script version that was used in the run, enabling you to go back and re-run any past job with the guarantee that the exact same code will be used as was used in the previous run.  You can access a list of available @git@ repositories on the Arvados workbench through _Access %(rarr)&rarr;% Repositories_.
50 * @"script_parameters"@ are provided to the script.  In this case, the input is the locator for the collection that we inspected in the previous section.
51
52 Use @arv job create@ to actually submit the job.  It should print out a JSON object which describes the newly created job:
53
54 <notextile>
55 <pre><code>$ <span class="userinput">arv -h job create --job "$(cat the_job)"</span>
56 {
57  "href":"https://qr1hi.arvadosapi.com/arvados/v1/jobs/qr1hi-8i9sb-1pm1t02dezhupss",
58  "kind":"arvados#job",
59  "etag":"ax3cn7w9whq2hdh983yxvq09p",
60  "uuid":"qr1hi-8i9sb-1pm1t02dezhupss",
61  "owner_uuid":"qr1hi-tpzed-9zdpkpni2yddge6",
62  "created_at":"2013-12-16T20:44:32Z",
63  "modified_by_client_uuid":"qr1hi-ozdt8-obw7foaks3qjyej",
64  "modified_by_user_uuid":"qr1hi-tpzed-9zdpkpni2yddge6",
65  "modified_at":"2013-12-16T20:44:32Z",
66  "updated_at":"2013-12-16T20:44:33Z",
67  "submit_id":null,
68  "priority":null,
69  "script":"hash",
70  "script_parameters":{
71   "input":"c1bad4b39ca5a924e481008009d94e32+210"
72  },
73  "script_version":"d9cd657b733d578ac0d2167dd75967aa4f22e0ac",
74  "cancelled_at":null,
75  "cancelled_by_client_uuid":null,
76  "cancelled_by_user_uuid":null,
77  "started_at":null,
78  "finished_at":null,
79  "output":null,
80  "success":null,
81  "running":null,
82  "is_locked_by_uuid":null,
83  "log":null,
84  "runtime_constraints":{},
85  "tasks_summary":{},
86  "dependencies":[
87   "c1bad4b39ca5a924e481008009d94e32+210"
88  ],
89  "log_stream_href":"https://qr1hi.arvadosapi.com/arvados/v1/jobs/qr1hi-8i9sb-1pm1t02dezhupss/log_tail_follow"
90 }
91 </code></pre>
92 </notextile>
93
94 The job is new queued and will start running as soon as it reaches the front of the queue.  Fields to pay attention to include:
95
96  * @"uuid"@ is the unique identifier for this specific job
97  * @"script_version"@ is the actual revision of the script used.  This is useful if the version was described using the "repository:branch" format.
98
99 h2. Monitor job progress
100
101 Go to Workbench, and use the menu to navigate to _Compute %(rarr)&rarr;% Jobs_. The job you submitted can be identified by the *uuid* row, which will match the "uuid" field of the JSON object returned when the job was created.
102
103 Hit "Refresh" until it finishes.  Successful completion is indicated by a green check mark in the *status* column.
104
105 You can access log messages while the job runs using @arv job log_tail_follow@:
106
107 notextile. <pre><code>$ <span class="userinput">arv job log_tail_follow --uuid qr1hi-8i9sb-xxxxxxxxxxxxxxx</span></code></pre>
108
109 This will print out the last several lines of the log for that job.
110
111 h2. Inspect the job output
112
113 You can access the job output under the *output* column of the _Compute %(rarr)&rarr;% Jobs_ page.  Alternately, you can use @arv job get@ to access a JSON object describing the output:
114
115 <notextile>
116 <pre><code>$ <span class="userinput">arv -h job get --uuid qr1hi-8i9sb-xxxxxxxxxxxxxxx</span>
117 {
118  "href":"https://qr1hi.arvadosapi.com/arvados/v1/jobs/qr1hi-8i9sb-1pm1t02dezhupss",
119  "kind":"arvados#job",
120  "etag":"1bk98tdj0qipjy0rvrj03ta5r",
121  "uuid":"qr1hi-8i9sb-1pm1t02dezhupss",
122  "owner_uuid":"qr1hi-tpzed-9zdpkpni2yddge6",
123  "created_at":"2013-12-16T20:44:32Z",
124  "modified_by_client_uuid":null,
125  "modified_by_user_uuid":"qr1hi-tpzed-9zdpkpni2yddge6",
126  "modified_at":"2013-12-16T20:44:55Z",
127  "updated_at":"2013-12-16T20:44:55Z",
128  "submit_id":null,
129  "priority":null,
130  "script":"hash",
131  "script_parameters":{
132   "input":"c1bad4b39ca5a924e481008009d94e32+210"
133  },
134  "script_version":"d9cd657b733d578ac0d2167dd75967aa4f22e0ac",
135  "cancelled_at":null,
136  "cancelled_by_client_uuid":null,
137  "cancelled_by_user_uuid":null,
138  "started_at":"2013-12-16T20:44:36Z",
139  "finished_at":"2013-12-16T20:44:53Z",
140  "output":"880b55fb4470b148a447ff38cacdd952+54",
141  "success":true,
142  "running":false,
143  "is_locked_by_uuid":"qr1hi-tpzed-9zdpkpni2yddge6",
144  "log":"2afdc6c8b67372ffd22d8ce89d35411f+91",
145  "runtime_constraints":{},
146  "tasks_summary":{
147   "done":2,
148   "running":0,
149   "failed":0,
150   "todo":0
151  },
152  "dependencies":[
153   "c1bad4b39ca5a924e481008009d94e32+210"
154  ],
155  "log_stream_href":null
156 }
157 </code></pre>
158 </notextile>
159
160 * @"output"@ is the unique identifier for this specific job's output.  This is a Keep collection.  Because the output of Arvados jobs should be deterministic, the known expected output is <code>880b55fb4470b148a447ff38cacdd952+54</code>.
161
162 Now you can list the files in the collection:
163
164 <notextile>
165 <pre><code>$ <span class="userinput">arv keep get 880b55fb4470b148a447ff38cacdd952+54</span>
166 . 78b268d1e03d87f8270bdee9d5d427c5+61 0:61:md5sum.txt
167 </code></pre>
168 </notextile>
169
170 This collection consists of the @md5sum.txt@ file.  Use @arv keep get@ to show the contents of the @md5sum.txt@ file:
171
172 <notextile>
173 <pre><code>$ <span class="userinput">arv keep get 880b55fb4470b148a447ff38cacdd952+54/md5sum.txt</span>
174 44b8ae3fde7a8a88d2f7ebd237625b4f var-GS000016015-ASM.tsv.bz2
175 </code></pre>
176 </notextile>
177
178 This md5 hash matches the md5 hash which we computed earlier.
179
180 h2. The job log
181
182 When the job completes, you can access the job log.  The keep identifier listed in the @"log"@ field from @arv job get@ specifies a collection.  You can list the files in the collection:
183
184 <notextile>
185 <pre><code>$ <span class="userinput">arv keep ls xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx+91</span>
186 qr1hi-8i9sb-xxxxxxxxxxxxxxx.log.txt
187 </code></pre>
188 </notextile>
189
190 The log collection consists of one log file named with the job id.  You can access it using @arv keep get@:
191
192 <notextile>
193 <pre><code>$ <span class="userinput">arv keep get xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx+91/qr1hi-8i9sb-xxxxxxxxxxxxxxx.log.txt</span>
194 2013-12-16_20:44:35 qr1hi-8i9sb-1pm1t02dezhupss 7575  check slurm allocation
195 2013-12-16_20:44:35 qr1hi-8i9sb-1pm1t02dezhupss 7575  node compute13 - 8 slots
196 2013-12-16_20:44:36 qr1hi-8i9sb-1pm1t02dezhupss 7575  start
197 2013-12-16_20:44:36 qr1hi-8i9sb-1pm1t02dezhupss 7575  Install revision d9cd657b733d578ac0d2167dd75967aa4f22e0ac
198 2013-12-16_20:44:37 qr1hi-8i9sb-1pm1t02dezhupss 7575  Clean-work-dir exited 0
199 2013-12-16_20:44:37 qr1hi-8i9sb-1pm1t02dezhupss 7575  Install exited 0
200 2013-12-16_20:44:37 qr1hi-8i9sb-1pm1t02dezhupss 7575  script hash
201 2013-12-16_20:44:37 qr1hi-8i9sb-1pm1t02dezhupss 7575  script_version d9cd657b733d578ac0d2167dd75967aa4f22e0ac
202 2013-12-16_20:44:37 qr1hi-8i9sb-1pm1t02dezhupss 7575  script_parameters {"input":"c1bad4b39ca5a924e481008009d94e32+210"}
203 2013-12-16_20:44:37 qr1hi-8i9sb-1pm1t02dezhupss 7575  runtime_constraints {"max_tasks_per_node":0}
204 2013-12-16_20:44:37 qr1hi-8i9sb-1pm1t02dezhupss 7575  start level 0
205 2013-12-16_20:44:37 qr1hi-8i9sb-1pm1t02dezhupss 7575  status: 0 done, 0 running, 1 todo
206 2013-12-16_20:44:38 qr1hi-8i9sb-1pm1t02dezhupss 7575 0 job_task qr1hi-ot0gb-23c1k3kwrf8da62
207 2013-12-16_20:44:38 qr1hi-8i9sb-1pm1t02dezhupss 7575 0 child 7681 started on compute13.1
208
209 2013-12-16_20:44:38 qr1hi-8i9sb-1pm1t02dezhupss 7575  status: 0 done, 1 running, 0 todo
210 2013-12-16_20:44:39 qr1hi-8i9sb-1pm1t02dezhupss 7575 0 child 7681 on compute13.1 exit 0 signal 0 success=true
211 2013-12-16_20:44:39 qr1hi-8i9sb-1pm1t02dezhupss 7575 0 success in 1 seconds
212 2013-12-16_20:44:39 qr1hi-8i9sb-1pm1t02dezhupss 7575 0 output 
213 2013-12-16_20:44:39 qr1hi-8i9sb-1pm1t02dezhupss 7575  wait for last 0 children to finish
214 2013-12-16_20:44:39 qr1hi-8i9sb-1pm1t02dezhupss 7575  status: 1 done, 0 running, 1 todo
215 2013-12-16_20:44:39 qr1hi-8i9sb-1pm1t02dezhupss 7575  start level 1
216 2013-12-16_20:44:39 qr1hi-8i9sb-1pm1t02dezhupss 7575  status: 1 done, 0 running, 1 todo
217 2013-12-16_20:44:39 qr1hi-8i9sb-1pm1t02dezhupss 7575 1 job_task qr1hi-ot0gb-iwr0o3unqothg28
218 2013-12-16_20:44:39 qr1hi-8i9sb-1pm1t02dezhupss 7575 1 child 7716 started on compute13.1
219 2013-12-16_20:44:39 qr1hi-8i9sb-1pm1t02dezhupss 7575  status: 1 done, 1 running, 0 todo
220 2013-12-16_20:44:52 qr1hi-8i9sb-1pm1t02dezhupss 7575 1 child 7716 on compute13.1 exit 0 signal 0 success=true
221 2013-12-16_20:44:52 qr1hi-8i9sb-1pm1t02dezhupss 7575 1 success in 13 seconds
222 2013-12-16_20:44:52 qr1hi-8i9sb-1pm1t02dezhupss 7575 1 output 880b55fb4470b148a447ff38cacdd952+54
223 2013-12-16_20:44:52 qr1hi-8i9sb-1pm1t02dezhupss 7575  wait for last 0 children to finish
224 2013-12-16_20:44:52 qr1hi-8i9sb-1pm1t02dezhupss 7575  status: 2 done, 0 running, 0 todo
225 2013-12-16_20:44:52 qr1hi-8i9sb-1pm1t02dezhupss 7575  release job allocation
226 2013-12-16_20:44:52 qr1hi-8i9sb-1pm1t02dezhupss 7575  Freeze not implemented
227 2013-12-16_20:44:52 qr1hi-8i9sb-1pm1t02dezhupss 7575  collate
228 2013-12-16_20:44:53 qr1hi-8i9sb-1pm1t02dezhupss 7575  output 880b55fb4470b148a447ff38cacdd952+54
229 2013-12-16_20:44:53 qr1hi-8i9sb-1pm1t02dezhupss 7575  finish
230 </code></pre>
231 </notextile>
232
233 This concludes the first tutorial.  In the next tutorial, we will "write a script to compute the hash.":tutorial-firstscript.html