* Fixed links
[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 the previous section, we downloaded a file from Keep and computed the md5 hash of the complete file.  While straightforward, 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-xxxxxxxxxxxxxxx",
57  "kind":"arvados#job",
58  "etag":"aulvmdxezwxo4zrw15gz1v7x3",
59  "uuid":"qr1hi-8i9sb-xxxxxxxxxxxxxxx",
60  "owner_uuid":"qr1hi-tpzed-9zdpkpni2yddge6",
61  "created_at":"2013-12-10T17:07:08Z",
62  "modified_by_client_uuid":"qr1hi-ozdt8-obw7foaks3qjyej",
63  "modified_by_user_uuid":"qr1hi-tpzed-9zdpkpni2yddge6",
64  "modified_at":"2013-12-10T17:07:08Z",
65  "updated_at":"2013-12-10T17:07:08Z",
66  "submit_id":null,
67  "priority":null,
68  "script":"hash",
69  "script_parameters":{
70   "input":"33a9f3842b01ea3fdf27cc582f5ea2af"
71  },
72  "script_version":"d3b10812b443dcf0189c1c432483bf7ac06507fe",
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-xxxxxxxxxxxxxxx/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 h3. 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 h3. 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-zs6d9pxkr0vk175",
118  "kind":"arvados#job",
119  "etag":"eoe99lw7rnqxo7j29fh53hz",
120  "uuid":"qr1hi-8i9sb-zs6d9pxkr0vk175",
121  "owner_uuid":"qr1hi-tpzed-9zdpkpni2yddge6",
122  "created_at":"2013-12-10T17:23:26Z",
123  "modified_by_client_uuid":null,
124  "modified_by_user_uuid":"qr1hi-tpzed-9zdpkpni2yddge6",
125  "modified_at":"2013-12-10T17:23:45Z",
126  "updated_at":"2013-12-10T17:23:45Z",
127  "submit_id":null,
128  "priority":null,
129  "script":"hash",
130  "script_parameters":{
131   "input":"33a9f3842b01ea3fdf27cc582f5ea2af"
132  },
133  "script_version":"0a8c7c6fce7a9667ee42c1984a845100f51906a2",
134  "cancelled_at":null,
135  "cancelled_by_client_uuid":null,
136  "cancelled_by_user_uuid":null,
137  "started_at":"2013-12-10T17:23:29Z",
138  "finished_at":"2013-12-10T17:23:44Z",
139  "output":"880b55fb4470b148a447ff38cacdd952+54+K@qr1hi",
140  "success":true,
141  "running":false,
142  "is_locked_by_uuid":"qr1hi-tpzed-9zdpkpni2yddge6",
143  "log":"f760f3dd3105103e058a043310f7e72b+3028+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 This concludes the first tutorial.  In the next tutorial, we will "write a script to compute the hash.":tutorial-firstscript.html