Draw stdout at a specific speed

For a load test of my application (under Linux), I am looking for a tool that outputs data to stdout at a certain speed (for example, 100 bytes / s), so that I can transfer the output to netcat, which sends this to my application. Some option for dd would be ideal, but I haven't found anything yet. It doesn't matter what data is printed (NUL bytes in order). Any clues?

+6
performance linux limit dd
source share
4 answers

I think this is exactly what you really want: Pipe Viewer

Using <fast input> | pv -qL <rate>[k|m|g|t] | <rate-limited output> <fast input> | pv -qL <rate>[k|m|g|t] | <rate-limited output> <fast input> | pv -qL <rate>[k|m|g|t] | <rate-limited output> limit the channel to the requested speed.

+3
source share

I wrote a quick program that takes one argument, how many A characters to print before standard output per second (a negative argument means speed limit). Hope this helps! :-) (On GNU libc, you will need to link your program with -lrt .)

Edit: revised to print the default dot if the second argument is not specified, in which case the first character is used. (And that means if you want to print the NUL character, just specify an empty string as the second argument .: -))

 #include <math.h> #include <stdio.h> #include <stdlib.h> #include <time.h> #include <unistd.h> int sleeptill(const struct timespec *when) { struct timespec now, diff; clock_gettime(CLOCK_REALTIME, &now); diff.tv_sec = when->tv_sec - now.tv_sec; diff.tv_nsec = when->tv_nsec - now.tv_nsec; while (diff.tv_nsec < 0) { diff.tv_nsec += 1000000000; --diff.tv_sec; } if (diff.tv_sec < 0) return 0; return nanosleep(&diff, 0); } int main(int argc, char **argv) { double rate = 0.0; char *endp; struct timespec start; double offset; if (argc >= 2) { rate = strtod(argv[1], &endp); if (endp == argv[1] || *endp) rate = 0.0; else rate = 1 / rate; if (!argv[2]) argv[2] = "."; } if (!rate) { fprintf(stderr, "usage: %s rate [char]\n", argv[0]); return 1; } clock_gettime(CLOCK_REALTIME, &start); offset = start.tv_nsec / 1000000000.0; while (1) { struct timespec till = start; double frac; double whole; frac = modf(offset += rate, &whole); till.tv_sec += whole; till.tv_nsec = frac * 1000000000.0; sleeptill(&till); write(STDOUT_FILENO, argv[2], 1); } } 
+5
source share

If everything is in order to get all one hundred bytes at a time, you can loop with sleep and the usual old echo in the shell with at least the first attempt.

+2
source share

Well, now I use nuttcp to do "real" loads. It seems to have rather low overhead, so the test system is not too broken.

0
source share

All Articles