SLUICE(1)
π SLUICE(1) π
General Commands Manual Β· the page that teaches you how to control data flow at a specified rate π no cap, this is the one
β¨ NAME β¨
sluice β a tool to control data flow at a specified rate π that's it, that's her whole job, and she ate
β¨ SYNOPSIS β¨
sluice [options]
β¨ DESCRIPTION β¨
Okay so bestie, picture this: sluice reads input and outputs a specified data rate. That's the main character energy right there. π
She comes with a whole wardrobe of data rate controlling mechanisms that you can tune for your specific use case whenever you need to. Not every vibe needs the same settings, iykyk. π
β¨ OPTIONS β¨
The sluice options are as follow, and yes we're going through every single one because they all matter:
-aβ append output to a file (used in conjunction with the-t'tee' or-Ooptions). Instead of creating a new file or truncating an existing file, this option appends data to the file. So like, no destroying the old content, we're just adding to the stack π«Ά-cdelayβ enables a constant delay time (in seconds) between writes. This option adjusts the output buffer size to try and keep the data rate constant. The output buffer size in this mode is initially set to the data rate Γ the delay. π°οΈ
This option is mutually exclusive to the -i option and implicitly enables the -o overrun and -u underrun buffer management options to dynamically re-size the read/write buffer to keep the data rate constant. By default this adjusts the buffer based on the total amount of data transferred and the time to write this (equivalent to the -s 0 turning mode). However, if the -s shift value is greater than 0, then the new size is adjusted by the previous size right shifted by the shift value. β¨
-dβ discard data, do not copy it to stdout. This makessluiceact as a data sink. She's just swallowing it all, no output, no crumbs π-Dmodeβ select the delay mode. The are various approaches to when to perform the data rate delays. The default is to perform the read, then write and finally the delay for each iteration. However, the-Doption allows one to select the delay mode as follows:
Mode Delay strategy Delay Duration
0 Read, Write, Delay (default) 1 Γ delay time
1 Delay, Read, Write 1 Γ delay time
2 Read, Delay, Write 1 Γ delay time
3 Delay, Read, Delay, Write 2 Γ 1/2 delay time
4 Read, Delay, Write, Delay 2 Γ 1/2 delay time
5 Delay, Read, Delay, Write, Delay 3 Γ 1/3 delay time
Note that modes 3 and 4 perform two delays each comprising of 1/2 the delay time and mode 5 performs 3 delays each comprising of 1/3 the delay time. π§
Modes 1, 3, 5 maybe considered as not entirely accurate in terms of the total run duration. In these modes an extraneous delay occurs before the final end-of-file empty read is performed. Just so you know π
-eβ ignore read errors. The failed read is replaced by zeros. Not me pretending the error never happened π-ffreqβ specify the frequency of-vverbose statistics updates. The default is 1/4 of a second. Note thatsluicewill try to emit updates close to the requested frequency, however, if the read/write rate is less than the frequency then the updates occur only at the read/write rate. π-Fβ flush file output after each write usingfsync. Safety first, always π-hβ show help. The classic. β¨-isizeβ specify the read/write size in bytes. TheK,M,G,TandPsuffixes allow one to specify size in Kilobytes, Megabytes, Gigabytes, Terabytes and Petabytes respectively. This option is mutually exclusive to the-coption.
In this mode, the delays between writes are used to control the data rate. By default the delay is based on the total amount of data transferred and the time taken to write this. This is equivalent to the -s 0 tuning mode. However, if the -s shift value is greater than 0, then the new delay is adjusted by the previous delay right shifted by the shift value. π₯
A special hybrid rate control mode can be invoked by also using the -o overflow and -u underflow options to also enable dynamic re-sizing of the read/write buffer. By default this adjusts the buffer based on the total amount of data transferred and the time to write this (equivalent to the -s 0 turning mode). However, if the -s shift value is greater than 0, then the new size is adjusted by the previous size right shifted by the shift value. π¦
-Ifileβ read input fromfilerather than from stdin. Come through, file input! π-msizeβ specify amount of data to process, the default size is in bytes, but theK,M,G,TandPsuffixes can specify size in Kilobytes, Megabytes, Gigabytes, Terabytes and Petabytes respectively. If this size is less than the write size, then the write size is truncated to be the-msize. βοΈ-nβ no rate control. This is just a straight data copy much likecatand all data rate controls cannot be used. Combined with the-vand-Soptions one can observe the data rates of the copy. π-oβ detect overrun and re-size read/write buffer size to try and stop overrun. This will shrink the buffer each time consecutive overruns are detected. See the-soption for details of the size re-adjustment mechanism. π-Ofileβ send output tofile, equivalent to-dt file. Shorthand queen π-pβ enable verbose stats showing % progress and ETA information. This is only valid using the-Ior-moption and the if file size is non-zero. See the-voption for more details. β³-Ppidfileβ write the process ID ofsluicein filepidfile. The file is removed whensluiceexits. She cleans up after herself, periodt. π§Ή-rrateβ specify the data rate in bytes per second. TheK,M,GandTsuffixes can specify the rate in Kilobytes/sec, Megabytes/sec, Gigabytes/sec and Terabytes/sec respectively. This option must always be provided except when the-noption is used. A zero rate is equivalent to no rate control (same as-n). π-Rβ do not read from stdin, instead read random data from/dev/urandom. Chaos mode, but make it adorable π²-sshiftβ modify the rate adjustment shift. This is a data rate tuning scaling factor used by the-r,-c,-oand-uoptions.
For the -r option, the delay between each write is controlled by modifying the previous delay by adding or subtracting the previous delay right shifted by this shift value. The larger the shift value the longer it takes to adjust up/down to the specified rate. The smaller the shift value the quicker it takes to reach the optimal delay, however, this can result in a highly fluctuating rates at the the beginning because the delay varies by a large amount causing large overruns and underruns. A shift value of 3 works well for most fast rates. π―
For the -c, -o and -u options, the size of the buffer is modified by adding or subtracting the previous size shifted by the shift value. Again, a shift value of 3 works well for most fast rates.
If the shift value is set to 0, then the shift rate adjustment tuning mechanism is explicitly turned off and data rates are adjusted based on the total amount of data transferred and the time to write this.
Small-sshift values of 1 and 2 can cause rapid oscillations before the data rate damping fully kicks into action. The value of-s 0(the default) is recommended for accurate low-speed data transfers. Trust the process bestie π
-Sβ print various performance and buffering statistics to stderr when end of file is reached. Receipts, on demand π§Ύ-tfileβ tee output to the specified file. Output is written to both stdout and to the named file. By default, the file will be created if it does not exist or re-written if it already exists. Use the-aoption to append to an existing file. Two places at once, multitasking icon π-Ttβ stop slice test aftertseconds. One can also specify the units of time in seconds, minutes, hours, days or years with the suffixs,m,h,dory. Timer says when we're done β°-uβ detect underrun and re-size read/write buffer size to try and stop underrun. This will expand the buffer each time consecutive underruns are detected. The buffer will not be expanded any more than 4MB in size. See the-soption for details of the size re-adjustment mechanism. π-vβ write verbose statistics to stderr. By default, this will display the current data rate, the last data rate adjusment (-= underrun,+= overrun), total bytes transferred, duration and the current buffer size. π
With the -p option, the progress statistics are displayed. This will display the current data rate, total bytes transferred, duration, percentage complete so far and the estimated time to completion. Note that the estimation is available using the -I and -m options and if the file size is non-zero. π¦
-Vβ print version information to standard out and exit successfully. A clean exit, we love to see it β¨-wβ warn if a long burst of continuous data rate underrun occurs, the warning is issued just once. To overcome the underrun increase the-iread/write buffer size or use the-uoption to auto-expand the read/write buffer. Too many underruns implies that too small a buffer or not enough CPU is available to keep up with the required data rate. She's telling you for your own good π«Ά-xsizeβ set pipe transfer size. If data is being piped into or out ofsluicethen this option allows one to specify the pipe size. Larger pipe sizes provide better throughput and less context switching; smaller pipe sizes are useful for low bandwidth rates where latency needs to be kept low. πΈ-zβ do not read from stdin, instead generate a stream of zeros (equivalent to reading from/dev/zero). Zero girl summer πSIGUSR1SIGINFOβ SendingSIGUSR1(orSIGINFOon BSD systems) will toggle the verbose data rate mode on/off. Signal-based vibes πSIGUSR2β Toggle underrun/overrun (-u,-o) options on/off. π
β¨ NOTES β¨
If neither -i or -c options are used, then sluice defaults to using a write buffer size of 1/32 of the data rate and bounded between the limits of 1 byte and 64MB. sluice will try to keep the data rate steady by adjusting the delay between writes. To tune this, see the -s option. π
β¨ EXAMPLES β¨
ok so these are the lil scenarios where sluice absolutely EATS π copy them, tweak them, live your truth:
Read /dev/zero and write in 4K sizes at the rate of 1MB/sec to the file 'example.dat'
cat /dev/zero | sluice -i 4K -r 1M > example.dat
Read 32MB from /dev/zero and write at the rate of 64K/sec to stdout with feedback on duration and ETA on stderr using 4K buffer writes and a tuning shift of 4.
cat /dev/zero | sluice -r 64K -vp -m 32M -i 4K -s 4
Generate a stream of zeros and write at a rate of 1MB/sec to a fifo named 'myfifo' with underrun and overrun buffer management
sluice -z -u -o -r 1MB -O myfifo
Write random data at 5MB per second to the file 'myfile' doing a write every 0.1 seconds
sluice -R -r 5M -c 0.1 > myfile
Write zeros to the file 'example-file' in 64K chunks and measure write rate as a crude throughput test
sluice -nzSv -f 0.1 -i 64K > example-file
Read data from somehost.com on port 1234 at a rate of 2MB per second and discard the data, e.g. this is a constant rate data sink.
nc somehost.com 1234 | sluice -d -r 2MB -i 8K
like?? the range?? a rate limiter, a data sink, a throughput test, a fifo wrangler β it's giving multihyphenate icon π
π EXIT STATUS π
bestie, sluice tells you how it went down through its exit status. here's the whole vibe check:
0β Exited successfully. π1β Invalid or out of range option provided. π2β File open error.3β Sleep error.4β Failed to get time of day.5β Signal handler setup error.6β Read error (file or stdin).7β Write error (file or stdout).8β Buffer allocation failed.
so if you're scripting around this, 0 is the only one that's main character energy, the rest are all "something went wrong" coded π
π BUGS π
ok this one's important so listen up:
Stopping and starting sluice usingSIGSTOPandSIGCONTwill interfere with the internal buffering rate calculations causing sluice to try to catch up and this may affect the short term data rate immediately after theSIGCONT.
translation: pause it, unpause it, and it's gonna be a lil off for a hot sec while it tries to make up for lost time. not a vibe, but it's the truth π
π SEE ALSO π
go read these too, they're in the same friend group:
π«Ά AUTHOR π«Ά
sluice was written by Colin Ian King <colin.i.king@gmail.com> with testing feedback and help from Kamal Mostafa.
This manual page was written by Colin Ian King for the Ubuntu project (but may be used by others).
shoutout to the devs, fr fr πΈ
π COPYRIGHT π
Copyright Β© 2014-2021 Canonical Ltd, Copyright Β© 2021-2024 Colin Ian King
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
so yeah β free to use, no promises, read the source if you wanna know the deets β¨
and that's the whole page bestie π this was SLUICE(1) from the sluice source, dated January 18, 2024 β go forth and rate-limit your little heart out, you're gonna slay ππ¦
π¦ where this page comes from
- debian trixie: sluice 0.03.01-1 Β· GPL-3.0-only
- ubuntu noble: sluice 0.03.00-1 Β· GPL-3.0-only
- ubuntu questing: sluice 0.03.01-1
- ubuntu resolute: sluice 0.03.01-1build1 Β· GPL-3.0-only
- ubuntu stonking: sluice 0.03.01-1build1 Β· GPL-3.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms