Advertise filters param in discovery doc.
[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.baseurl}}/user/getting_started/ssh-access.html#login, and have a "working environment.":{{site.baseurl}}/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 under _Compute %(rarr)&rarr;% Code 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 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 now 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 the Workbench dashboard.  Your job should be at the top of the "Recent jobs" table.  This table refreshes automatically.  When the job has completed successfully, it will show <span class="label label-success">finished</span> in the *Status* column.
102
103 On the command line, you can access log messages while the job runs using @arv job log_tail_follow@:
104
105 notextile. <pre><code>~$ <span class="userinput">arv job log_tail_follow --uuid qr1hi-8i9sb-xxxxxxxxxxxxxxx</span></code></pre>
106
107 This will print out the last several lines of the log for that job.
108
109 h2. Inspect the job output
110
111 On the workbench dashboard, look for the *Output* column of the *Recent jobs* table.  Click on the link under *Output* for your job to go to the files page with the job output.  The files page lists all the files that were output by the job.  Click on the link under the *files* column to view a file, or click on the download icon <span class="glyphicon glyphicon-download-alt"></span> to download the output file.
112
113 On the command line, you can use @arv job get@ to access a JSON object describing the output:
114
115 <notextile>
116 <pre><code>~$ <span class="userinput">arv 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 ls 880b55fb4470b148a447ff38cacdd952+54</span>
166 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.  On the workbench dashboard, this is the link under the *Log* column of the *Recent jobs* table.
183
184 On the command line, the keep identifier listed in the @"log"@ field from @arv job get@ specifies a collection.  You can list the files in the collection:
185
186 <notextile>
187 <pre><code>~$ <span class="userinput">arv keep ls xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx+91</span>
188 qr1hi-8i9sb-xxxxxxxxxxxxxxx.log.txt
189 </code></pre>
190 </notextile>
191
192 The log collection consists of one log file named with the job id.  You can access it using @arv keep get@:
193
194 <notextile>
195 <pre><code>~$ <span class="userinput">arv keep get xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx+91/qr1hi-8i9sb-xxxxxxxxxxxxxxx.log.txt</span>
196 2013-12-16_20:44:35 qr1hi-8i9sb-1pm1t02dezhupss 7575  check slurm allocation
197 2013-12-16_20:44:35 qr1hi-8i9sb-1pm1t02dezhupss 7575  node compute13 - 8 slots
198 2013-12-16_20:44:36 qr1hi-8i9sb-1pm1t02dezhupss 7575  start
199 2013-12-16_20:44:36 qr1hi-8i9sb-1pm1t02dezhupss 7575  Install revision d9cd657b733d578ac0d2167dd75967aa4f22e0ac
200 2013-12-16_20:44:37 qr1hi-8i9sb-1pm1t02dezhupss 7575  Clean-work-dir exited 0
201 2013-12-16_20:44:37 qr1hi-8i9sb-1pm1t02dezhupss 7575  Install exited 0
202 2013-12-16_20:44:37 qr1hi-8i9sb-1pm1t02dezhupss 7575  script hash
203 2013-12-16_20:44:37 qr1hi-8i9sb-1pm1t02dezhupss 7575  script_version d9cd657b733d578ac0d2167dd75967aa4f22e0ac
204 2013-12-16_20:44:37 qr1hi-8i9sb-1pm1t02dezhupss 7575  script_parameters {"input":"c1bad4b39ca5a924e481008009d94e32+210"}
205 2013-12-16_20:44:37 qr1hi-8i9sb-1pm1t02dezhupss 7575  runtime_constraints {"max_tasks_per_node":0}
206 2013-12-16_20:44:37 qr1hi-8i9sb-1pm1t02dezhupss 7575  start level 0
207 2013-12-16_20:44:37 qr1hi-8i9sb-1pm1t02dezhupss 7575  status: 0 done, 0 running, 1 todo
208 2013-12-16_20:44:38 qr1hi-8i9sb-1pm1t02dezhupss 7575 0 job_task qr1hi-ot0gb-23c1k3kwrf8da62
209 2013-12-16_20:44:38 qr1hi-8i9sb-1pm1t02dezhupss 7575 0 child 7681 started on compute13.1
210
211 2013-12-16_20:44:38 qr1hi-8i9sb-1pm1t02dezhupss 7575  status: 0 done, 1 running, 0 todo
212 2013-12-16_20:44:39 qr1hi-8i9sb-1pm1t02dezhupss 7575 0 child 7681 on compute13.1 exit 0 signal 0 success=true
213 2013-12-16_20:44:39 qr1hi-8i9sb-1pm1t02dezhupss 7575 0 success in 1 seconds
214 2013-12-16_20:44:39 qr1hi-8i9sb-1pm1t02dezhupss 7575 0 output 
215 2013-12-16_20:44:39 qr1hi-8i9sb-1pm1t02dezhupss 7575  wait for last 0 children to finish
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  start level 1
218 2013-12-16_20:44:39 qr1hi-8i9sb-1pm1t02dezhupss 7575  status: 1 done, 0 running, 1 todo
219 2013-12-16_20:44:39 qr1hi-8i9sb-1pm1t02dezhupss 7575 1 job_task qr1hi-ot0gb-iwr0o3unqothg28
220 2013-12-16_20:44:39 qr1hi-8i9sb-1pm1t02dezhupss 7575 1 child 7716 started on compute13.1
221 2013-12-16_20:44:39 qr1hi-8i9sb-1pm1t02dezhupss 7575  status: 1 done, 1 running, 0 todo
222 2013-12-16_20:44:52 qr1hi-8i9sb-1pm1t02dezhupss 7575 1 child 7716 on compute13.1 exit 0 signal 0 success=true
223 2013-12-16_20:44:52 qr1hi-8i9sb-1pm1t02dezhupss 7575 1 success in 13 seconds
224 2013-12-16_20:44:52 qr1hi-8i9sb-1pm1t02dezhupss 7575 1 output 880b55fb4470b148a447ff38cacdd952+54
225 2013-12-16_20:44:52 qr1hi-8i9sb-1pm1t02dezhupss 7575  wait for last 0 children to finish
226 2013-12-16_20:44:52 qr1hi-8i9sb-1pm1t02dezhupss 7575  status: 2 done, 0 running, 0 todo
227 2013-12-16_20:44:52 qr1hi-8i9sb-1pm1t02dezhupss 7575  release job allocation
228 2013-12-16_20:44:52 qr1hi-8i9sb-1pm1t02dezhupss 7575  Freeze not implemented
229 2013-12-16_20:44:52 qr1hi-8i9sb-1pm1t02dezhupss 7575  collate
230 2013-12-16_20:44:53 qr1hi-8i9sb-1pm1t02dezhupss 7575  output 880b55fb4470b148a447ff38cacdd952+54
231 2013-12-16_20:44:53 qr1hi-8i9sb-1pm1t02dezhupss 7575  finish
232 </code></pre>
233 </notextile>
234
235 This concludes the first tutorial.  In the next tutorial, we will "write a script to compute the hash.":tutorial-firstscript.html