4 title: "Tutorial: Running a Crunch job"
8 h1. Tutorial: Running a crunch job
10 This tutorial introduces the concepts and use of the Arvados Keep storage and Crunch job system using the @arv@ command line tool and Arvados Workbench.
12 *This tutorial assumes that you are "logged into an Arvados VM instance":ssh-access.html#login, and have a "working environment.":check-environment.html*
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.
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.
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.
28 Crunch jobs are described using JSON objects. For example:
31 <pre><code>$ <span class="userinput">read -d $'\000' the_job <<EOF
34 "script_version": "arvados:master",
37 "input": "33a9f3842b01ea3fdf27cc582f5ea2af"
44 * @read@ is a shell builtin that stores the first line of standard input into the local shell variable @the_job@
45 * @-d $'\000'@ changes the line delimiter character from newline to null so that the entire input will be considered a single line.
46 * @"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"@.
47 * @"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)→% Repositories_.
48 * @"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 Use @arv job create@ to actually submit the job. It should print out a JSON object which describes the newly created job:
53 <pre><code>$ <span class="userinput">arv -h job create --job "$the_job"</span>
55 "href":"https://qr1hi.arvadosapi.com/arvados/v1/jobs/qr1hi-8i9sb-j5dr6107mxzp3no",
57 "etag":"aulvmdxezwxo4zrw15gz1v7x3",
58 "uuid":"qr1hi-8i9sb-j5dr6107mxzp3no",
59 "owner_uuid":"qr1hi-tpzed-9zdpkpni2yddge6",
60 "created_at":"2013-12-10T17:07:08Z",
61 "modified_by_client_uuid":"qr1hi-ozdt8-obw7foaks3qjyej",
62 "modified_by_user_uuid":"qr1hi-tpzed-9zdpkpni2yddge6",
63 "modified_at":"2013-12-10T17:07:08Z",
64 "updated_at":"2013-12-10T17:07:08Z",
69 "input":"33a9f3842b01ea3fdf27cc582f5ea2af"
71 "script_version":"d3b10812b443dcf0189c1c432483bf7ac06507fe",
73 "cancelled_by_client_uuid":null,
74 "cancelled_by_user_uuid":null,
80 "is_locked_by_uuid":null,
82 "runtime_constraints":{},
85 "33a9f3842b01ea3fdf27cc582f5ea2af"
87 "log_stream_href":"https://qr1hi.arvadosapi.com/arvados/v1/jobs/qr1hi-8i9sb-j5dr6107mxzp3no/log_tail_follow"
92 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 * @"uuid"@ is the unique identifier for this specific job
95 * @"script_version"@ is the actual revision of the script used. This is useful if the version was described using the "repository:branch" format.
96 * @"log_stream_href"@ provides a means to monitor job progress, described below.
98 h3. Monitor job progress
100 Go to Workbench, and use the menu to navigate to _Compute %(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 Hit "Refresh" until it finishes. Successful completion is indicated by a green check mark in the *status* column.
104 You can watch the log messages while the job runs using @curl@:
106 notextile. <pre><code>$ <span class="userinput">curl -s -H "Authorization: OAuth2 $ARVADOS_API_TOKEN" _value_of_log_stream_href_from_arv_job_create_</span></code></pre>
108 * @-s@ suppress status messages from @curl@ itself
109 * @-H@ addes a required HTTP header with your Arvados API token
111 This will run until the job finishes or is @curl@ is canceled with control-C.
113 h3. Inspect the job output
115 You can access the job output under the *output* column of the _Compute %(rarr)→% Jobs_ page. Alternately, you can use @arv job get@ to access a JSON object describing the output:
118 <pre><code>$ <span class="userinput">arv -h job get --uuid _value_of_uuid_from_arv_job_create_</span>
120 "href":"https://qr1hi.arvadosapi.com/arvados/v1/jobs/qr1hi-8i9sb-zs6d9pxkr0vk175",
121 "kind":"arvados#job",
122 "etag":"eoe99lw7rnqxo7j29fh53hz",
123 "uuid":"qr1hi-8i9sb-zs6d9pxkr0vk175",
124 "owner_uuid":"qr1hi-tpzed-9zdpkpni2yddge6",
125 "created_at":"2013-12-10T17:23:26Z",
126 "modified_by_client_uuid":null,
127 "modified_by_user_uuid":"qr1hi-tpzed-9zdpkpni2yddge6",
128 "modified_at":"2013-12-10T17:23:45Z",
129 "updated_at":"2013-12-10T17:23:45Z",
133 "script_parameters":{
134 "input":"33a9f3842b01ea3fdf27cc582f5ea2af"
136 "script_version":"0a8c7c6fce7a9667ee42c1984a845100f51906a2",
138 "cancelled_by_client_uuid":null,
139 "cancelled_by_user_uuid":null,
140 "started_at":"2013-12-10T17:23:29Z",
141 "finished_at":"2013-12-10T17:23:44Z",
142 "output":"880b55fb4470b148a447ff38cacdd952+54+K@qr1hi",
145 "is_locked_by_uuid":"qr1hi-tpzed-9zdpkpni2yddge6",
146 "log":"f760f3dd3105103e058a043310f7e72b+3028+K@qr1hi",
147 "runtime_constraints":{},
155 "33a9f3842b01ea3fdf27cc582f5ea2af"
157 "log_stream_href":null
162 * @"output"@ is the unique identifier for this specific job's output. This is a Keep collection.
164 Now you can list the files in the collection:
167 <pre><code>$ <span class="userinput">arv keep get _value_of_output_from_arv_job_get_</span>
168 . 78b268d1e03d87f8270bdee9d5d427c5+61 0:61:md5sum.txt
172 This collection consists of the md5sum.txt file. Use @arv keep get@ to show the contents of the md5sum.txt file:
175 <pre><code>$ <span class="userinput">arv keep get 880b55fb4470b148a447ff38cacdd952+54+K@qr1hi/md5sum.txt</span>
176 44b8ae3fde7a8a88d2f7ebd237625b4f var-GS000016015-ASM.tsv.bz2
180 This md5 hash matches the md5 hash which we computed earlier.
182 This concludes the first tutorial. In the next tutorial, we will "write script to do the same work.":tutorial-firstscript.html