1

我有一个 Rails 应用程序需要使用服务器上的 Javascript 库。到目前为止,只要有必要,我一直在运行从 rails 到 nodejs 的系统命令。但是,我有一个计算量特别大的任务,因此需要缓存数据以加快速度。我还必须将大量输入传递给节点程序。结果,我达到了节点程序输入的缓冲区大小。我目前只是将它以足够小的块以适合缓冲区的方式多次发送到单独的节点进程,但这会导致性能问题,因为我现在不再能够在尽可能多的运行中利用缓存。我想使用管道来执行此操作,但是我的管道也碰到了缓冲区,我不知道如何清空它。到目前为止,我已经...

#ruby file
output=[]
node_pipe=IO.popen("nodejs /home/user/node_program.js","w+")

10_000.times do |time|
  node_pipe.write("a lot of stuff")
  #here I would like to read contents and push contents to output array but still be      
  #able to write to the same process in the next loop to take advantage of the cache
end

//node_program.js
var input=process.stdin;
var cache={};
input.resume();
input.on('data',function(chunk){
  cache[chunk]=library_function(chunk);
  console.log(String(other_library_function(chunk)));
}

有什么建议么?

`
4

0 回答 0