Merge branch '1608-api-documentation' of git.clinicalfuture.com:arvados into 1608...
[arvados.git] / doc / user / tutorials / tutorial-job1.textile
1 ---
2 layout: default
3 navsection: userguide
4 title: "Running a Crunch job"
5 navorder: 112
6 ---
7
8 h1. Tutorial: Running a crunch job
9
10 This tutorial introduces the concepts and use of the Crunch job system using the @arv@ command line tool and Arvados Workbench.
11
12 *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*
13
14 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:
15 * Large files require significant time to download.
16 * Very large files may exceed the scratch space of the local disk.
17 * We are only able to use the local CPU to process the file.
18
19 The Arvados "Crunch" framework is designed to support processing very large data batches (gigabytes to terabytes) efficiently, and provides the following benefits:
20 * 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).
21 * 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.
22 * Ensure that your programs and workflows are repeatable with different versions of your code, OS updates, etc.
23 * Interrupt and resume long-running jobs consisting of many short tasks.
24 * Maintain timing statistics automatically, so they're there when you want them.
25
26 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.
27
28 Crunch jobs are described using JSON objects.  For example:
29
30 <notextile>
31 <pre><code>$ <span class="userinput">cat &gt;the_job &lt;&lt;EOF
32 {
33  "script": "hash",
34  "script_version": "arvados:master",
35  "script_parameters":
36  {
37   "input": "33a9f3842b01ea3fdf27cc582f5ea2af"
38  }
39 }
40 EOF
41 </code></pre>
42 </notextile>
43
44 * @cat@ is a standard Unix utility that simply copies standard input to standard output
45 * @<<EOF@ tells the shell to direct the following lines into the standard input for @cat@ up until it sees the line @EOF@
46 * @>the_job@ redirects standard output to a file called @the_job@
47 * @"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"@.
48 * @"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_.
49 * @"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.
50
51 Use @arv job create@ to actually submit the job.  It should print out a JSON object which describes the newly created job:
52
53 <notextile>
54 <pre><code>$ <span class="userinput">arv -h job create --job "$(cat the_job)"</span>
55 {
56  "href":"https://qr1hi.arvadosapi.com/arvados/v1/jobs/qr1hi-8i9sb-1pm1t02dezhupss",
57  "kind":"arvados#job",
58  "etag":"ax3cn7w9whq2hdh983yxvq09p",
59  "uuid":"qr1hi-8i9sb-1pm1t02dezhupss",
60  "owner_uuid":"qr1hi-tpzed-9zdpkpni2yddge6",
61  "created_at":"2013-12-16T20:44:32Z",
62  "modified_by_client_uuid":"qr1hi-ozdt8-obw7foaks3qjyej",
63  "modified_by_user_uuid":"qr1hi-tpzed-9zdpkpni2yddge6",
64  "modified_at":"2013-12-16T20:44:32Z",
65  "updated_at":"2013-12-16T20:44:33Z",
66  "submit_id":null,
67  "priority":null,
68  "script":"hash",
69  "script_parameters":{
70   "input":"33a9f3842b01ea3fdf27cc582f5ea2af"
71  },
72  "script_version":"d9cd657b733d578ac0d2167dd75967aa4f22e0ac",
73  "cancelled_at":null,
74  "cancelled_by_client_uuid":null,
75  "cancelled_by_user_uuid":null,
76  "started_at":null,
77  "finished_at":null,
78  "output":null,
79  "success":null,
80  "running":null,
81  "is_locked_by_uuid":null,
82  "log":null,
83  "runtime_constraints":{},
84  "tasks_summary":{},
85  "dependencies":[
86   "33a9f3842b01ea3fdf27cc582f5ea2af"
87  ],
88  "log_stream_href":"https://qr1hi.arvadosapi.com/arvados/v1/jobs/qr1hi-8i9sb-1pm1t02dezhupss/log_tail_follow"
89 }
90 </code></pre>
91 </notextile>
92
93 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:
94
95  * @"uuid"@ is the unique identifier for this specific job
96  * @"script_version"@ is the actual revision of the script used.  This is useful if the version was described using the "repository:branch" format.
97
98 h2. Monitor job progress
99
100 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.
101
102 Hit "Refresh" until it finishes.  Successful completion is indicated by a green check mark in the *status* column.
103
104 You can access log messages while the job runs using @arv job log_tail_follow@:
105
106 notextile. <pre><code>$ <span class="userinput">arv job log_tail_follow --uuid qr1hi-8i9sb-xxxxxxxxxxxxxxx</span></code></pre>
107
108 This will print out the last several lines of the log for that job.
109
110 h2. Inspect the job output
111
112 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:
113
114 <notextile>
115 <pre><code>$ <span class="userinput">arv -h job get --uuid qr1hi-8i9sb-xxxxxxxxxxxxxxx</span>
116 {
117  "href":"https://qr1hi.arvadosapi.com/arvados/v1/jobs/qr1hi-8i9sb-1pm1t02dezhupss",
118  "kind":"arvados#job",
119  "etag":"1bk98tdj0qipjy0rvrj03ta5r",
120  "uuid":"qr1hi-8i9sb-1pm1t02dezhupss",
121  "owner_uuid":"qr1hi-tpzed-9zdpkpni2yddge6",
122  "created_at":"2013-12-16T20:44:32Z",
123  "modified_by_client_uuid":null,
124  "modified_by_user_uuid":"qr1hi-tpzed-9zdpkpni2yddge6",
125  "modified_at":"2013-12-16T20:44:55Z",
126  "updated_at":"2013-12-16T20:44:55Z",
127  "submit_id":null,
128  "priority":null,
129  "script":"hash",
130  "script_parameters":{
131   "input":"33a9f3842b01ea3fdf27cc582f5ea2af"
132  },
133  "script_version":"d9cd657b733d578ac0d2167dd75967aa4f22e0ac",
134  "cancelled_at":null,
135  "cancelled_by_client_uuid":null,
136  "cancelled_by_user_uuid":null,
137  "started_at":"2013-12-16T20:44:36Z",
138  "finished_at":"2013-12-16T20:44:53Z",
139  "output":"880b55fb4470b148a447ff38cacdd952+54+K@qr1hi",
140  "success":true,
141  "running":false,
142  "is_locked_by_uuid":"qr1hi-tpzed-9zdpkpni2yddge6",
143  "log":"2afdc6c8b67372ffd22d8ce89d35411f+91+K@qr1hi",
144  "runtime_constraints":{},
145  "tasks_summary":{
146   "done":2,
147   "running":0,
148   "failed":0,
149   "todo":0
150  },
151  "dependencies":[
152   "33a9f3842b01ea3fdf27cc582f5ea2af"
153  ],
154  "log_stream_href":null
155 }
156 </code></pre>
157 </notextile>
158
159 * @"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+K@qr1hi</code>.
160
161 Now you can list the files in the collection:
162
163 <notextile>
164 <pre><code>$ <span class="userinput">arv keep get 880b55fb4470b148a447ff38cacdd952+54+K@qr1hi</span>
165 . 78b268d1e03d87f8270bdee9d5d427c5+61 0:61:md5sum.txt
166 </code></pre>
167 </notextile>
168
169 This collection consists of the @md5sum.txt@ file.  Use @arv keep get@ to show the contents of the @md5sum.txt@ file:
170
171 <notextile>
172 <pre><code>$ <span class="userinput">arv keep get 880b55fb4470b148a447ff38cacdd952+54+K@qr1hi/md5sum.txt</span>
173 44b8ae3fde7a8a88d2f7ebd237625b4f var-GS000016015-ASM.tsv.bz2
174 </code></pre>
175 </notextile>
176
177 This md5 hash matches the md5 hash which we computed earlier.
178
179 h2. The job log
180
181 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:
182
183 <notextile>
184 <pre><code>$ <span class="userinput">arv keep ls 2afdc6c8b67372ffd22d8ce89d35411f+91+K@qr1hi</span>
185 qr1hi-8i9sb-1pm1t02dezhupss.log.txt
186 </code></pre>
187 </notextile>
188
189 The log collection consists of one log file named with the job id.  You can access it using @arv keep get@:
190
191 <notextile>
192 <pre><code>$ <span class="userinput">arv keep get 2afdc6c8b67372ffd22d8ce89d35411f+91+K@qr1hi/qr1hi-8i9sb-1pm1t02dezhupss.log.txt</span>
193 2013-12-16_20:44:35 qr1hi-8i9sb-1pm1t02dezhupss 7575  check slurm allocation
194 2013-12-16_20:44:35 qr1hi-8i9sb-1pm1t02dezhupss 7575  node compute13 - 8 slots
195 2013-12-16_20:44:36 qr1hi-8i9sb-1pm1t02dezhupss 7575  start
196 2013-12-16_20:44:36 qr1hi-8i9sb-1pm1t02dezhupss 7575  Install revision d9cd657b733d578ac0d2167dd75967aa4f22e0ac
197 2013-12-16_20:44:37 qr1hi-8i9sb-1pm1t02dezhupss 7575  Clean-work-dir exited 0
198 2013-12-16_20:44:37 qr1hi-8i9sb-1pm1t02dezhupss 7575  Install exited 0
199 2013-12-16_20:44:37 qr1hi-8i9sb-1pm1t02dezhupss 7575  script hash
200 2013-12-16_20:44:37 qr1hi-8i9sb-1pm1t02dezhupss 7575  script_version d9cd657b733d578ac0d2167dd75967aa4f22e0ac
201 2013-12-16_20:44:37 qr1hi-8i9sb-1pm1t02dezhupss 7575  script_parameters {"input":"33a9f3842b01ea3fdf27cc582f5ea2af"}
202 2013-12-16_20:44:37 qr1hi-8i9sb-1pm1t02dezhupss 7575  runtime_constraints {"max_tasks_per_node":0}
203 2013-12-16_20:44:37 qr1hi-8i9sb-1pm1t02dezhupss 7575  start level 0
204 2013-12-16_20:44:37 qr1hi-8i9sb-1pm1t02dezhupss 7575  status: 0 done, 0 running, 1 todo
205 2013-12-16_20:44:38 qr1hi-8i9sb-1pm1t02dezhupss 7575 0 job_task qr1hi-ot0gb-23c1k3kwrf8da62
206 2013-12-16_20:44:38 qr1hi-8i9sb-1pm1t02dezhupss 7575 0 child 7681 started on compute13.1
207 2013-12-16_20:44:38 qr1hi-8i9sb-1pm1t02dezhupss 7575  status: 0 done, 1 running, 0 todo
208 2013-12-16_20:44:39 qr1hi-8i9sb-1pm1t02dezhupss 7575 0 child 7681 on compute13.1 exit 0 signal 0 success=true
209 2013-12-16_20:44:39 qr1hi-8i9sb-1pm1t02dezhupss 7575 0 success in 1 seconds
210 2013-12-16_20:44:39 qr1hi-8i9sb-1pm1t02dezhupss 7575 0 output 
211 2013-12-16_20:44:39 qr1hi-8i9sb-1pm1t02dezhupss 7575  wait for last 0 children to finish
212 2013-12-16_20:44:39 qr1hi-8i9sb-1pm1t02dezhupss 7575  status: 1 done, 0 running, 1 todo
213 2013-12-16_20:44:39 qr1hi-8i9sb-1pm1t02dezhupss 7575  start level 1
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 1 job_task qr1hi-ot0gb-iwr0o3unqothg28
216 2013-12-16_20:44:39 qr1hi-8i9sb-1pm1t02dezhupss 7575 1 child 7716 started on compute13.1
217 2013-12-16_20:44:39 qr1hi-8i9sb-1pm1t02dezhupss 7575  status: 1 done, 1 running, 0 todo
218 2013-12-16_20:44:52 qr1hi-8i9sb-1pm1t02dezhupss 7575 1 child 7716 on compute13.1 exit 0 signal 0 success=true
219 2013-12-16_20:44:52 qr1hi-8i9sb-1pm1t02dezhupss 7575 1 success in 13 seconds
220 2013-12-16_20:44:52 qr1hi-8i9sb-1pm1t02dezhupss 7575 1 output 880b55fb4470b148a447ff38cacdd952+54
221 2013-12-16_20:44:52 qr1hi-8i9sb-1pm1t02dezhupss 7575  wait for last 0 children to finish
222 2013-12-16_20:44:52 qr1hi-8i9sb-1pm1t02dezhupss 7575  status: 2 done, 0 running, 0 todo
223 2013-12-16_20:44:52 qr1hi-8i9sb-1pm1t02dezhupss 7575  release job allocation
224 2013-12-16_20:44:52 qr1hi-8i9sb-1pm1t02dezhupss 7575  Freeze not implemented
225 2013-12-16_20:44:52 qr1hi-8i9sb-1pm1t02dezhupss 7575  collate
226 2013-12-16_20:44:53 qr1hi-8i9sb-1pm1t02dezhupss 7575  output 880b55fb4470b148a447ff38cacdd952+54+K@qr1hi
227 2013-12-16_20:44:53 qr1hi-8i9sb-1pm1t02dezhupss 7575  finish
228 </code></pre>
229 </notextile>
230
231 This concludes the first tutorial.  In the next tutorial, we will "write a script to compute the hash.":tutorial-firstscript.html