Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 如何在grpc双向rpc中发送消息,而无需从grpc节点客户端进行缓冲_Node.js_Grpc - Fatal编程技术网

Node.js 如何在grpc双向rpc中发送消息,而无需从grpc节点客户端进行缓冲

Node.js 如何在grpc双向rpc中发送消息,而无需从grpc节点客户端进行缓冲,node.js,grpc,Node.js,Grpc,这是一个双向rpc,似乎正在缓存上的消息。有没有一种方法可以在没有缓冲的情况下立即强制写入传出流?您看到这种缓冲行为的原因是写入实际上是异步完成的,因此,服务器代码需要定期允许其他异步操作在写操作之间发生,以确保它们在计算完成后立即发送。您可以利用可选回调参数write,在发送最后一条消息后立即发送每条消息。该示例中的代码可以使用以下方法编写: 你到底面临什么问题?可写流缓冲区是否已满?您是否看到在网络链路饱和之前备份了缓冲区?您是否发现在编写消息和在网络上看到消息之间有太多的延迟?还是别的什么

这是一个双向rpc,似乎正在缓存上的消息。有没有一种方法可以在没有缓冲的情况下立即强制写入传出流?

您看到这种缓冲行为的原因是写入实际上是异步完成的,因此,服务器代码需要定期允许其他异步操作在写操作之间发生,以确保它们在计算完成后立即发送。您可以利用可选回调参数
write
,在发送最后一条消息后立即发送每条消息。该示例中的代码可以使用以下方法编写:


你到底面临什么问题?可写流缓冲区是否已满?您是否看到在网络链路饱和之前备份了缓冲区?您是否发现在编写消息和在网络上看到消息之间有太多的延迟?还是别的什么?这是您在该示例中观察到的问题,还是您自己的代码出现的问题?我发现在编写消息和在服务器上查看消息之间存在延迟。具体地说,在for循环中写入的所有消息在被调用时都会发送到服务器,而不是立即写入
async.each(notes, function(note, next) {
  console.log('Sending message "' + note.message + '" at ' +
      note.location.latitude + ', ' + note.location.longitude);
  var noteMsg = new messages.RouteNote();
  noteMsg.setMessage(note.message);
  var location = new messages.Point();
  location.setLatitude(note.location.latitude);
  location.setLongitude(note.location.longitude);
  noteMsg.setLocation(location);
  // Note the use of the next callback here
  call.write(noteMsg, next);
}, function() {
  // End the stream after all messages have been sent
  call.end();
});