You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm spawning a child process using spawn-command npm package, i do this when the node server starts and then for every request i read the query value and hit the running child process with stdin. The stdout that comes out of the child process is an event stream and i add a listener to read the data and then will be sending the data to sse-channel instance.
Everything works the way it should for the first request, the issue arises for subsequent requests. When i console.log the data inside the stdout's on listener handler then i could see that the data is getting cloned. Meaning, same set of data is getting repeated twice for the second request and thrice for the third request etc... I was researching this issue and possible solution for this would be to create independent streams for each request so that this data cloning would be avoided in the child.stdout's on listener handler. But i'm not sure whether this could resolve the issue. Could some one please suggest a way to overcome this hurdle.
Code looks like below,
varspawnCommand=require('spawn-command');varcmd='path to the binary file';module.exports=function(app){varchild=spawnCommand(cmd);srvc={get: function(req,res){child.stdin.write('a json object in a format that is expected by binary'+'\n');child.stdout.on('data',function(){console.log(''+data);});}}}
As i mentioned earlier the child process would be spawned once when the node server starts and then the get() method would run for every request. So each time when a request runs, the stdin's would be sent to the binary and then the "on" listener would log the data in stdout. This works perfectly for the first request, but when a second request is made (with the first request still logging data) i could see that the data's for both first and second are getting cloned twice and for third request the data's for each request is getting cloned thrice and it increases exponentially.
On the other hand if i spawn a child everytime inside the get() method i can overcome this problem but unfortunately i cannot do that because there'll be 100's of requests and i cannot afford 100's of binary instance eating up the memory.
Hope i explained it better, any suggestions would be of great help.
My noder version is 5.x.x (even though it does not matter with this query)
The text was updated successfully, but these errors were encountered:
I'm spawning a child process using spawn-command npm package, i do this when the node server starts and then for every request i read the query value and hit the running child process with stdin. The stdout that comes out of the child process is an event stream and i add a listener to read the data and then will be sending the data to sse-channel instance.
Everything works the way it should for the first request, the issue arises for subsequent requests. When i console.log the data inside the stdout's on listener handler then i could see that the data is getting cloned. Meaning, same set of data is getting repeated twice for the second request and thrice for the third request etc... I was researching this issue and possible solution for this would be to create independent streams for each request so that this data cloning would be avoided in the child.stdout's on listener handler. But i'm not sure whether this could resolve the issue. Could some one please suggest a way to overcome this hurdle.
Code looks like below,
As i mentioned earlier the child process would be spawned once when the node server starts and then the get() method would run for every request. So each time when a request runs, the stdin's would be sent to the binary and then the "on" listener would log the data in stdout. This works perfectly for the first request, but when a second request is made (with the first request still logging data) i could see that the data's for both first and second are getting cloned twice and for third request the data's for each request is getting cloned thrice and it increases exponentially.
On the other hand if i spawn a child everytime inside the get() method i can overcome this problem but unfortunately i cannot do that because there'll be 100's of requests and i cannot afford 100's of binary instance eating up the memory.
Hope i explained it better, any suggestions would be of great help.
My noder version is 5.x.x (even though it does not matter with this query)
The text was updated successfully, but these errors were encountered: