This page describes, in Unix manual page style, a program available for downloading from this site which copies data while enforcing a specified maximum transfer rate in bytes per second by pausing between data blocks. This permits bulk data transfers without “locking up” disc or network bandwidth to the detriment of other applications and/or users. It can be thought of as the equivalent of the Unix nice command for I/O.
valve - copy data, enforcing transfer rate limitation
valve [ options ] [ infile [ outfile ] ]
Usually, when you copy one file to another or transfer data between applications, you want things to finish as soon as possible—why wait any longer than necessary? However, when the operation in question consumes scarce shared disc or network transfer bandwidth (for example, when copying large files between machines on a local network or across the Internet), it may be wise to limit the transfer rate to avoid degrading performance for other users or applications. In an ideal world, wise and benevolent operating systems would automatically throttle bandwidth to achieve this goal, but as we all know, ours is not an ideal world, nor are operating systems, for the most part, wise or benevolent.
valve is a Unix/Linux/etc. command line utility which copies an input source to an output destination, pausing as necessary between blocks of data to achieve a requested mean transfer rate. Options permit measuring transfer rate without enforcing a limit and determining the timing granularity of the system on which the program is run.
Long (--) options may be abbreviated to their shortest unique prefix and single-letter options without arguments may be aggregated. Arguments to single-letter options may immediately follow the option or be separated by white space.
Arguments to the --blocksize, --rate, and --waitmin options can include commas to separate groups of digits, and may be followed by a suffix indicating a scale factor for the numeric argument as follows. Note that these suffix specifications are case-sensitive.
A trailing “D” may be used to denote a decimal power of ten instead of “B”.
valve returns status 0 if processing was completed without errors, 1 if an I/O or internal error occurred, and 2 if processing could not be performed at all due, for example, to a nonexistent input file or command line syntax error.
Suppose you're logged into a local system and you with to transfer the contents of the current directory to a directory named “/mirror/files/” on a remote system named somewhere.ratburger.net, while limiting the transfer rate to 256 Kb/sec to avoid saturating your outbound bandwidth or the inbound bandwidth of the destination site. You can accomplish this with:
tar cf - . | valve --rate 256K | \ ssh somewhere.ratburger.net "(cd /mirror/files; tar xf -)"
If no infile is specified or infile is a single “-”, valve reads from standard input; if no outfile is given, or outfile is a single “-”, output is sent to standard output. The input and output are processed strictly serially; consequently valve may (and usually will) be used in pipelines. The program can process files of any size supported by the system with any binary content whatsoever.
This is a Unix application through and through, and will require substantial work to port to other operating systems, particularly in the area of high-precision waits. It does, however, work on 32-bit Windows systems with Cygwin installed.
valve uses the nanosleep function, if available, to pause between blocks of data. If the system does not support that function, usleep is used, if available, and failing that, an emulation of usleep with setitimer and signal. If none of these facilities are available, you're out of luck.
It is tacky using “B” to denote a decimal power of ten in scale factor suffixes, but that's how dd does it, so I opted in favour of compatibility. You can use a trailing “D”, if you prefer, to indicate a decimal power.
Please report bugs and documentation errors to Bravo Uniform Golf Sierra @ Foxtrot Oscar Uniform Romeo Mike India Lima Alpha Bravo Decimal Charlie Hotel. If you don't have any idea what I just said, please consult this document.
This software is in the public domain. Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, without any conditions or restrictions. This software is provided “as is” without express or implied warranty.