英文:
Martini Go server with built in web crawler get too many open files after a few hourse
问题
我建立了一个网络爬虫,用于提供其发现的一些HTTP信息。该爬虫作为一个Go协程运行,而Martini则运行Web服务器。过了一段时间后,我开始收到以下错误信息:
2014/08/01 10:23:51 http: Accept error: accept tcp [::]:3000: too many open files; retrying in 1s.
我读到说我应该尝试增加最大打开文件数,但我对这个级别的配置还不熟悉,不知道该如何操作。我在Ubuntu 14.04上运行这个程序。请问如何更改Martini服务器的最大打开文件数?谢谢!
英文:
I built a web crawler that serves up some http info on its findings. The crawler runs as a go routine and martini runs the web server. After a while I start getting
2014/08/01 10:23:51 http: Accept error: accept tcp [::]:3000: too many open files; retrying in 1s.
I read I should try increasing the max open files only I am new to this level of configuration and have no idea how to do this. I am running this on Ubuntu 14.04. How do you change a martini servers max open files please and thank you.
答案1
得分: 4
确保你不要忘记关闭从http.Get
获取的响应,就像这个问题中所示。
这个示例展示了更好的响应管理:
resp, _ := http.Get("http://127.0.0.1:3000" + path)
s, _ := ioutil.ReadAll(resp.Body)
resp.Body.Close()
如果问题仍然存在,你可以尝试在/etc/sysctl.conf
中增加fs.file-max
的值,具体方法请参考这里。
英文:
Make sure you don't forget to close the response you get from an http.Get
, as in this issue.
This example shows a better response management:
resp, _ := http.Get("http://127.0.0.1:3000"+path)
s, _ := ioutil.ReadAll(resp.Body)
resp.Body.Close()
If the issue really still persists, then you can try and increase the fs.file-max
in /etc/sysctl.conf
.
答案2
得分: 0
我通过将以下代码移出函数来解决了这个问题:
var tr = &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
var client = &http.Client{Transport: tr}
英文:
I solved this problem by moving the following code out side of the function:
var tr = &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
var client = &http.Client{Transport: tr}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论