Sivaram Neelakantan wrote:
> I've been tinkering around with kafka and other bits of streaming
> software. In order to test them, is there any utility to send text or
> binary data at a specific rate to a specific port?
Probably yes.
> Is it netcat or socat?
As I did not know socat(1) [thanks], it would have been netcat (nc(1)).
Now that I know the former, I would consider it, too. Depends.
> Has anyone done anything of this sort?
Probably yes.
> A few examples would be appreciated.
You could write a shell script using sleep(1) to “read -n” from a stream
nchars characters at a time (see e.g. bash(1)) and pipe that into nc(1).
[I have learned of the read-sleep approach via
<
https://superuser.com/q/609387/125462> to which I contributed
<
https://superuser.com/a/1186711/125462>.]
# output one character of "foo" every second
echo foo |
# subshell avoids backing up and restoring $IFS
(
# read space and newline, too
IFS=''
while read -n 1 -r char
do
printf '%s' "$char"
sleep 1
done
)
With GNU sleep(1) you could have delays shorter than one second; with POSIX
sleep(1) you could compensate for the lack of this capability with reading
more characters at once.
buffer(1) can give you chunks, but apparently not specific throttling.
As I discovered via <
https://www.howtogeek.com/50794/keep-rsync-from-using-all-your-bandwidth/> (Google: “rsync throttle”), rsync(1) can give you the
throttling with “--bwlimit”, but only for connections that rsync(1) can
make.
As Ian indicated, if userspace cannot do it, your kernel might. Linux
4.9.2, for example, appears to include *packet-based* traffic shaping
support, starting from the CONFIG_NET_SCHED kernel configuration option.
The key word to look for appears to be “QoS” (Quality of Service).
[I have never used it.]
How long have you STFW for this?
<
http://catb.org/esr/faqs/smart-questions.html>
--
PointedEars
Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.