Giter VIP home page Giter VIP logo

lateral's Introduction

lateral

A simple process parallelizer to make lives better at the commandline.

Have you ever used xargs -P -n 1 in an attempt to run slow commands in parallel? Gotten burned or gave up? Forgot -0 when you needed it? Had to use positional arguments? Wanted to substitute text into the commandline?

Lateral is here to help.

Usage

Usage:
  lateral [command]

Available Commands:
  config      Change the server configuration
  dumpconfig  Dump available configuration options
  getpid      Print pid of server to stdout
  kill        Kill the server with fire
  run         Run the given command in the lateral server
  start       Start the lateral background server
  wait        Wait for all currently inserted tasks to finish

Flags:
      --config string   config file (default $HOME/.lateral/config.yaml)
  -h, --help            help for lateral
  -s, --socket string   UNIX domain socket path (default $HOME/.lateral/socket.$SESSIONID)

Examples

Example usage:

lateral start
for i in $(cat /tmp/names); do
  lateral run -- some_command $i
done
lateral wait

With comments:

 # start a lateral server - one per session (login shell), runs 10 parallel tasks by default
lateral start
for i in $(gather list of work); do
  # Hand off the command to lateral
  lateral run -- my_slow_command $i
done
# Wait for all the work to be done
lateral wait
# wait stops the server when all commands are complete
# if any commands returned a non-zero status, wait returns non-zero
echo $?

This is the most basic usage, and it's simpler than using xargs. It also supports much more powerful things. It doesn't only support command-line arguments like xargs, it also supports filedescriptors:

lateral start
for i in $(seq 1 100); do
  lateral run -- my_slow_command < workfile$i > /tmp/logfile$i
done
lateral wait

The stdin, stdout, and stderr of the command to be run are passed to lateral, and so redirection to files works. This makes it trivial to have per-task log files.

The parallelism is also dynamically adjustable at run-time.

lateral start -p 0 # yup, it will just queue tasks with 0 parallelism
for i in $(seq 1 100); do
  lateral run -- command_still_outputs_to_stdout_but_wont_spam inputfile$i
done
lateral config -p 10; lateral wait # command output spam can commence

This also allows you to raise parallelism when things are going slower than you want. Underestimate how much work your machine can do at once? Ratchet up the number of tasks with lateral config -p <N>. Turns out that you want to run fewer? Reducing the parallelism works as well - no new tasks will be started until the number running is under the limit.

How does this black magic work?

lateral start starts a server that listens on a unix socket that (by default) is based on your session ID. Each invocation of lateral in a different login shell will be independent.

Unix sockets support more than passing data: they also support passing filedescriptors. When lateral run is called, it sends the command-line, environment, and open filedescriptors over the unix socket to the server where they are stored and queued to be run.

Logging

Lateral uses glog, a Google logging library. Only the server logs, other commands do not. Its logs by default can be found in /tmp/lateral.INFO, but this can be configured using standard Google logging flags.

lateral's People

Contributors

akramer avatar wathiede avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

wathiede

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.