If I have:
node foo.js | node bar.js
is there a way to determine if there is a queue in between them that's building up?
in other words if the producer is outpacing the consumer w.r.t. stdio?
pipestdinstdiostdout
If I have:
node foo.js | node bar.js
is there a way to determine if there is a queue in between them that's building up?
in other words if the producer is outpacing the consumer w.r.t. stdio?
Best Answer
You can use
ioctl(,FIONREAD,)
on pipes in Linux to get the current number of bytes available to read. This might be found inman 7 pipe
(FIONREAD
is also inman tty_ioctl
). You can either integrate this into your application or run something like this bit of perl in parallel with it, using the pipe as stdin:So the usage would be
Try it out with something like
I get warnings from
perl
about_FORTIFY_SOURCE
, hence the stderr redirection. Thedd
reads less than the length ofdate
so you can see the result gradually increasing.For completeness, you can get the capacity of a pipe with
fcntl(,F_GETPIPE_SZ)
and set it withfcntl(,F_SETPIPE_SZ,newvalue)
up to/proc/sys/fs/pipe-max-size
(unless root or haveCAP_SYS_RESOURCE
). Seeman fcntl
.