Command-line utility to execute commands in parallel and aggregate their output.
Similar interface to GNU Parallel or xargs but implemented in rust and tokio.
* Supports running commands read from stdin or input files similar to xargs, for example: head -1000 /usr/share/dict/words | rust-parallel md5 -s
.
* Supports :::
syntax to run all combinations of argument groups similar to GNU Parallel, for example: rust-parallel gzip -k ::: *.html
Prevents output interleaving and is very fast.
See the demos for example usage.
``` $ rust-parallel --help Execute commands in parallel
By Aaron Riekenberg aaron.riekenberg@gmail.com
https://github.com/aaronriekenberg/rust-parallel https://crates.io/crates/rust-parallel
Usage: rust-parallel [OPTIONS] [COMMANDANDINITIAL_ARGUMENTS]...
Arguments: [COMMANDANDINITIAL_ARGUMENTS]... Optional command and initial arguments.
If this contains 1 or more ::: delimiters the cartesian product of arguments from all groups are run.
Options:
-d, --discard-output
Possible values:
- stdout: Redirect stdout for commands to /dev/null
- stderr: Redirect stderr for commands to /dev/null
- all: Redirect stdout and stderr for commands to /dev/null
-i, --input-file
-j, --jobs
[default: 8]
-0, --null-separator Use null separator for reading input files instead of newline
-s, --shell Use shell mode for running commands.
Each command line is passed to "<shell-path> -c" as a single argument.
--channel-capacity <CHANNEL_CAPACITY>
Input and output channel capacity, defaults to num cpus * 2
[default: 16]
--disable-path-cache
Disable command path cache
--shell-path <SHELL_PATH>
Path to shell to use for shell mode
[default: /bin/bash]
-h, --help Print help (see a summary with '-h')
-V, --version Print version ```
Recommended:
For manual installation/update:
1. Install Rust
2. Install the latest version of this app from crates.io:
$ cargo install rust-parallel
3. The same cargo install rust-parallel
command will also update to the latest version after initial installation.
See the wiki page for demos.
See the wiki page for benchmarks.
#![forbid(unsafe_code)]
)O(number of input lines)
memory usage. In support of this:
tokio::sync::Semaphore
is used carefully to limit the number of commands that run concurrently. Do not spawn tasks for all input lines immediately to limit memory usage.multi_cartesian_product
to process :::
command line inputs.async
/ await
functions (aka coroutines)CommandLineArgs
instance using tokio::sync::OnceCell
.tokio::process::Command
tokio::sync::Semaphore
used to limit number of commands that run concurrently.tokio::sync::mpsc::channel
used to receive inputs from input task, and to send command outputs to an output writer task. To await command completions, use the elegant property that when all Senders
are dropped the channel is closed.tracing::Instrument
is used to provide structured debug logs.--disable-path-cache
option