4 title: Writing Portable High-Performance Workflows
7 Copyright (C) The Arvados Authors. All rights reserved.
9 SPDX-License-Identifier: CC-BY-SA-3.0
12 h2(#performance). Performance
14 To get the best perfomance from your workflows, be aware of the following Arvados features, behaviors, and best practices:
16 If you have a sequence of short-running steps (less than 1-2 minutes each), use the Arvados extension "arv:RunInSingleContainer":cwl-extensions.html#RunInSingleContainer to avoid scheduling and data transfer overhead by running all the steps together at once. To use this feature, @cwltool@ must be installed in the container image.
18 Avoid declaring @InlineJavascriptRequirement@ or @ShellCommandRequirement@ unless you specifically need them. Don't include them "just in case" because they change the default behavior and may add extra overhead.
20 When combining a parameter value with a string, such as adding a filename extension, write @$(inputs.file.basename).ext@ instead of @$(inputs.file.basename + 'ext')@. The first form is evaluated as a simple text substitution, the second form (using the @+@ operator) is evaluated as an arbitrary Javascript expression and requires that you declare @InlineJavascriptRequirement@.
22 Use @ExpressionTool@ to efficiently rearrange input files between steps of a Workflow. For example, the following expression accepts a directory containing files paired by @_R1_@ and @_R2_@ and produces an array of Directories containing each pair.
24 {% codeblock as yaml %}
32 InlineJavascriptRequirement: {}
36 for (var i = 0; i < inputs.inputdir.listing.length; i++) {
37 var file = inputs.inputdir.listing[i];
38 var groups = file.basename.match(/^(.+)(_R[12]_)(.+)$/);
40 if (!samples[groups[1]]) {
41 samples[groups[1]] = [];
43 samples[groups[1]].push(file);
47 for (var key in samples) {
48 dirs.push({"class": "Directory",
50 "listing": [samples[key]]});
56 Available compute nodes types vary over time and across different cloud providers, so try to limit the RAM requirement to what the program actually needs. However, if you need to target a specific compute node type, see this discussion on "calculating RAM request and choosing instance type for containers.":{{site.baseurl}}/api/execution.html#RAM
58 Instead of scattering separate steps, prefer to scatter over a subworkflow.
60 With the following pattern, @step1@ has to wait for all samples to complete before @step2@ can start computing on any samples. This means a single long-running sample can prevent the rest of the workflow from moving on:
62 {% codeblock as yaml %}
85 Instead, scatter over a subworkflow. In this pattern, a sample can proceed to @step2@ as soon as @step1@ is done, independently of any other samples.
86 Example: (note, the subworkflow can also be put in a separate file)
88 {% codeblock as yaml %}
103 outputSource: step3/out
122 To write workflows that are easy to modify and portable across CWL runners (in the event you need to share your workflow with others), there are several best practices to follow:
124 Workflows should always provide @DockerRequirement@ in the @hints@ or @requirements@ section.
126 Build a reusable library of components. Share tool wrappers and subworkflows between projects. Make use of and contribute to "community maintained workflows and tools":https://github.com/common-workflow-language/workflows and tool registries such as "Dockstore":http://dockstore.org .
128 CommandLineTools wrapping custom scripts should represent the script as an input parameter with the script file as a default value. Use @secondaryFiles@ for scripts that consist of multiple files. For example:
130 {% codeblock as yaml %}
132 class: CommandLineTool
137 inputBinding: {position: 1}
140 location: bclfastq.py
148 inputBinding: {position: 2}
156 You can get the designated temporary directory using @$(runtime.tmpdir)@ in your CWL file, or from the @$TMPDIR@ environment variable in your script.
158 Similarly, you can get the designated output directory using $(runtime.outdir), or from the @HOME@ environment variable in your script.
160 Avoid specifying resource requirements in CommandLineTool. Prefer to specify them in the workflow. You can provide a default resource requirement in the top level @hints@ section, and individual steps can override it with their own resource requirement.
162 {% codeblock as yaml %}