Sample code:
#include <stdio.h>
#include <unistd.h>
#include <sched.h>
#include <pthread.h>
int
main (int argc, char **argv)
{
unsigned char buffer[128];
char buf[0x4000];
setvbuf (stdout, buf, _IOFBF, 0x4000);
fork ();
fork ();
pthread_t this_thread = pthread_self ();
struct sched_param params;
params.sched_priority = sched_get_priority_max (SCHED_RR);
pthread_setschedparam (this_thread, SCHED_RR, ¶ms);
while (1)
{
fwrite (&buffer, 128, 1, stdout);
}
}
This program opens 4 threads and outputs on stdout the contents of "buffer" which is 128 bytes or 16 long ints on a 64 bit cpu.
If I then run:
./writetest | pv -ptebaSs 800G >/dev/null
I get a speed of about 7.5 GB/s.
Incidentally, that is the same speed I get if I do:
$ mkfifo out
$ dd if=/dev/zero bs=16384 >out &
$ dd if=/dev/zero bs=16384 >out &
$ dd if=/dev/zero bs=16384 >out &
$ dd if=/dev/zero bs=16384 >out &
pv <out -ptebaSs 800G >/dev/null
Is there any way to make this faster? Note. the buffer in the real program is not filled with zeroes.
my curiosity is to understand how much data can a single program (mutithreaaded or multiprocess) output
It looks like 4 people didn't understand this simple question. I even put in bold the reason of the question.
fork
doesn't create a thread. Not my DV/CV though.