how to handle backpressure on child_process.fork when sending a lot of messages #4710
Unanswered
MichaelBelousov
asked this question in
Q&A
Replies: 0 comments 3 replies
-
related? nodejs/node#7657 |
Beta Was this translation helpful? Give feedback.
0 replies
-
I have elected to just manually set up ipc, and use the v8 serialization api via |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
env: node v18.5.0 Ubuntu 22.04
I have a node.js program that uses
child_process.fork
to create a worker, and then sends it a lot of messages as it performs work. I use a separate process because I am using a synchronous javascript API for dealing with a binary format, to read from one file and then the same API to write to another file. So the program would be much faster if every time the analysis on the read side was ready, it pushed a message of what to write to the write side, and then continued processing data from the read side rather than waiting for the writing to be done.But I seem to be running up against backpressure in the ipc between a node.js parent and forked child. Following is a minimal viable reproduction, where after a certain amount of messages, the child seems to stop receiving
message
events. In fact I can add a signal handler likeprocess.on("SIGUSR2", () => { debugger; }
, thenkill -s SIGUSR2 pid
, and attach with devtools to both parent and child, and manually runprocess.send
and its equivalent on the parent, but breakpoints in the child'son("message")
handler will not be hit. Even attaching withstrace --attach
, I don't see a difference in the child'srecvmsg
syscall usage when sending a message manually, but the handler isn't called.I can't seem to myself find other people dealing seeing this issue, are there any resources for handling backpressure in a
child_process.fork
'ed node.js process? I see some for streams, but I don't think it applies.parent.js
child.js
Note, in my larger project that uses this architecture, it stops sending messages to the child for 200ms every time it encounters a false result from
.send
, but that seems to not help, even if I wait much longer.Beta Was this translation helpful? Give feedback.
All reactions