shenwei356 / rush

A cross-platform command-line tool for executing jobs in parallel
https://github.com/shenwei356/rush
MIT License
846 stars 63 forks source link

Job count appears to sense CPU count #32

Closed xkortex closed 4 years ago

xkortex commented 4 years ago

rush v0.4.2

I noticed on an N-core machine, only n jobs spawn by default. The help documentation for -j suggests that 16 is the default. Not sure if this is a feature or a bug, but I thought it was worth documenting.

~/sleepy.sh

#!/bin/bash

COUNT=0

while [[ "$COUNT" -lt 3 ]]; do
  echo "job ${1} count is ${COUNT}"
  COUNT=$((COUNT + 1))
  sleep 1
done
echo "done"

seq 0 3 | rush --immediate-output '~/sleepy.sh {}'

2-core machine:

(2/1/1): job 1 count is 0
(1/1/1): job 0 count is 0
(1/1/2): job 0 count is 1
(2/1/2): job 1 count is 1
(2/1/3): job 1 count is 2
(1/1/3): job 0 count is 2
(1/1/4): done
(2/1/4): done
(4/1/1): job 3 count is 0
(3/1/1): job 2 count is 0
(3/1/2): job 2 count is 1
(4/1/2): job 3 count is 1
(4/1/3): job 3 count is 2
(3/1/3): job 2 count is 2
(4/1/4): done
(3/1/4): done

Similarly on a 4 core, I see 4 jobs simultaneous, and so on. -j N totally overrides this (up to a point, then I ran out of file descriptors :p). But it stumped me for a bit since the directions implied 16 was the default.

Nice tool btw, absolutely love it. Way easier to deploy quickly than parallel, I just copy the bin and I'm ready to rock and roll. :)

shenwei356 commented 4 years ago
  -j, --jobs int                  run n jobs in parallel (default value depends on your device) (default 4)

It's the maximum number of simultaneously running jobs.

On an N-core machine, if n (n<N) jobs given, only n processes need to be spawned.

xkortex commented 4 years ago

OH I see what happens. On the README.md, it says

  -j, --jobs int                  run n jobs in parallel (default value depends on your device) (default 16)

But then I checked the help on my machine, it says

  -j, --jobs int                  run n jobs in parallel (default value depends on your device) (default 2)

That's actually pretty clever! I never actually checked the rush -h locally, just was referring to the docs, so shame on me :p