dongzenglin8292 2018-01-27 15:05
浏览 70
已采纳

Go构建/运行执行期间发生错误

I've created a simple go script: https://gist.github.com/kbl/86ed3b2112eb80522949f0ce574a04e3

It's fetching some xml from the internet and then starts X goroutines. The X depends on file content. In my case it was 1700 goroutines.

My first execution finished with:

$ go run mathandel1.go 
2018/01/27 14:19:37 Get https://www.boardgamegeek.com/xmlapi/boardgame/162152?pricehistory=1&stats=1: dial tcp 72.233.16.130:443: socket: too many open files
2018/01/27 14:19:37 Get https://www.boardgamegeek.com/xmlapi/boardgame/148517?pricehistory=1&stats=1: dial tcp 72.233.16.130:443: socket: too many open files
exit status 1

I've tried to increase ulimit to 2048.

Now I'm getting different error, script is the same thou:

$ go build mathandel1.go 
# command-line-arguments
/usr/local/go/pkg/tool/linux_amd64/link: flushing $WORK/command-line-arguments/_obj/exe/a.out: write $WORK/command-line-arguments/_obj/exe/a.out: file too large

What is causing that error? How can I fix that?

  • 写回答

1条回答 默认 最新

  • dtr53557 2018-01-27 15:11
    关注

    You ran ulimit 2048 which changed the maximum file size.

    From man bash(1), ulimit section:

    If no option is given, then -f is assumed.

    This means that you now set the maximum file size to 2048 bytes, that's probably not enough for.... anything.

    I'm guessing you meant to change the limit for number of open file descriptors. For this, you want to run:

    ulimit -n 2048
    

    As for the original error (before changing the maximum file size), you're launching 1700 goroutines, each performing a http get. Each creates a connection, using a tcp socket. These are covered by the open file descriptor limit.

    Instead, you should be limiting the number of concurrent downloads. This can be done with a simple worker pool pattern.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?