以特定速度进行标准输出输出
对于我的应用程序(在 Linux 下)的负载测试,我正在寻找一个以特定速率(例如 100 字节/秒)在 stdout 上输出数据的工具,以便我可以将输出通过管道传输到 netcat,后者将其发送到我的应用程序应用。 dd 的某些选项是理想的,但到目前为止我还没有找到任何东西。 打印什么类型的数据并不重要(NUL 字节就可以)。 有什么提示吗?
For a load test of my application (under Linux), I'm looking for a tool that outputs data on stdout at a specific rate (like 100 bytes/s), so that I can pipe the output to netcat which sends it to my application. Some option for dd would be ideal, but I didn't find anything so far. It doesn't really matter what kind of data is printed (NUL bytes are OK). Any hints?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我编写了一个快速程序,它接受一个参数,即每秒打印到标准输出的
A
个字符(负参数意味着没有速率限制)。 希望这可以帮助! :-) (在 GNU libc 上,您需要使用-lrt
链接您的程序。)编辑:默认情况下修改为打印点,除非指定了第二个参数,在这种情况下,第一个字符是即被使用。 (这意味着,如果您想打印 NUL 字符,只需指定一个空字符串作为第二个参数即可。:-))
I wrote a quick program that takes one argument, how many
A
characters to print to standard output per second (negative argument means no rate limiting). Hope this helps! :-) (On GNU libc, you will need to link your program with-lrt
.)Edit: revised to print dot by default, unless a second argument is specified, in which case the first character of that is used. (And that means, if you want to print the NUL character, just specify an empty string as the second argument. :-))
我认为这就是您真正想要的: Pipe Viewer
使用
| pv -qL <速率>[k|m|g|t] | <速率限制输出>
将把管道限制为请求的速率。I think that this is what you really want: Pipe Viewer
Using
<fast input> | pv -qL <rate>[k|m|g|t] | <rate-limited output>
will limit the pipe to the requested rate.如果您愿意一次获取所有一百个字节,那么您至少可以在 shell 中使用
sleep
和普通的旧echo
进行循环,作为第一次尝试。If you're fine with getting all hundred bytes at a time, you could do a loop with
sleep
and plain oldecho
in the shell as a first attempt at least.好吧,我现在使用 nuttcp 来进行“真正的”负载测试。 它的开销似乎相当低,因此测试系统不会受到太多干扰。
Well, I'm now using nuttcp to do "real" load tests instead. It seems to have quite low overhead, so the test system is not too much disturbed.