summaryrefslogtreecommitdiffstats
path: root/parallel_xz.sh
blob: 65621501c27369ef746bc942386bc1c8b118899b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/sh
# Reads filenames on stdin, xz-compresses each in place.
# Not optimal for "compress relatively few, large files" scenario!

# How many xz's to run in parallel:
procgroup=""
while test "$#" != 0; do
	# Get it from -jNUM
	N="${1#-j}"
	if test "$N" = "$1"; then
		# Not -j<something> - warn and ignore
		echo "parallel_xz: warning: unrecognized argument: '$1'"
	else
		procgroup="$N"
	fi
	shift
done

#This seems to cause problems with large numbers
if (( $procgroup > 8 )); then
	procgroup=8
fi

# If told to use only one cpu:
test "$procgroup" || exec xargs -r xz
test "$procgroup" = 1 && exec xargs -r xz

# xz has some startup cost. If files are really small,
# this cost might be significant. To combat this,
# process several files (in sequence) by each xz process via -n 16:
exec xargs -r -n 16 -P $procgroup xz