doujiao4705 2017-12-06 05:34
浏览 151
已采纳

从客户端向服务器发送大量数据

I am working with Go and Grpc. I have one XML file to be sent from client to server. When server calls a method on client, client responds back with an XML document which could range from few kB to 100s MB or may be more. Please help me with how should I do it? Should I

  1. assign the value to a string variable and send normally -> rpc GetCMData (CmRequest) returns (CmReply) {}
  2. assign the value to a string variable and send as a stream -> rpc GetCMData (CmRequest) returns (stream CmReply) {}
  3. Is there any other better way to do so?

This is how CmReply looks like:

message CmReply {
  string name = 1;
}
  • 写回答

2条回答 默认 最新

  • 我在西湖1 2017-12-06 08:05
    关注

    The second one is more the way you want to go. But another point: Are you sure you want to have these hundreds of megabytes in your RAM? I'm not the Go-Geek, but I generally would prefer to work on a File Stream. And probably implement something like a back-pressure-system.

    If you work with streams: I would also implement something to make sure that you can handle a break of the stream. Let's say you have the half of your stream and the stream breaks. You don't want to start again and get all previous stream elements, which you already have on the client side. You risk again a connection break within the stream. Maybe at the same point. So, something like pagination. Let's say

    message CMRequest{
      int startAt = 0;
    }
    
    message CmReply {
      string id = 0;
      string name = 1;
    }
    

    If the stream breaks, you send a new request with startAt= LastCmReply.id+1

    Here's a video of some good practices in grpc: https://www.youtube.com/watch?v=Z_yD7YPL2oE&index=17&list=WL

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效