dpgbh20688 2014-03-31 20:47
浏览 255
已采纳

如何在Go中有效处理大型数据数组(超过10MiB)?

I am working with go to download files from one server and after manipulating the files sending it to another server.

The files size can vary from 1MB to 200MB.

Currently, my code is pretty simple, I am using http.Client and bytes.Buffer .
It takes lot of time to handle does big files (the 100MB to 200MB) which there is a lot of them.

After a quick profiling, I see that most of the time I do bytes.(*Buffer).grow,
How can I create big buffers for example for 16MB?

What can I do in order to improve my efficiency of the code? General tips for handling with large http requests?

Edit

I will explain, exactly what I am trying to do. I have couchdb documents (with attachments) that I am trying to copy to another couchdb instance. The couchdb documents size can be from 30MB to 200MB, copying tiny (2 - 10MB) couchdb documents - is really fast.

But sending the document over the wire is really slow. I am currently, trying to profile, and try to use @Evan answer to see what is my problem.

  • 写回答

3条回答 默认 最新

  • doupafu6980 2014-03-31 21:32
    关注

    Take a look at the description for bytes.NewBuffer: http://golang.org/pkg/bytes/#NewBuffer

    Sounds like you can create a 16MB byte slice and use it to initialize the buffer.

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

报告相同问题?

悬赏问题

  • ¥20 matlab计算中误差
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊