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 关于#html5#的问题:H5页面用户手机返回的时候跳转到指定页面例如(语言-javascript)
  • ¥15 无法使用此凭据登录,因为你的域不可用,如何解决?(标签-Windows)
  • ¥15 yolov9的训练时间
  • ¥15 二叉树遍历没有报错但无法正常运行
  • ¥15 在linux系统下vscode运行robocup3d上场球员报错
  • ¥15 Python语言实验
  • ¥15 SAP HANA SQL 增加合计行
  • ¥20 用C#语言解决一个英文打字练习器,有偿
  • ¥15 srs-sip外部服务 webrtc支持H265格式
  • ¥15 在使用abaqus软件中,继承到assembly里的surfaces怎么使用python批量调动