我们有一个在golang上运行的API,这获得了很高的流量,今天突然间我们收到了以下错误消息
http:接受错误:接受tcp [::]:8443:accept4:太多打开 文件1s重试
我之前检查过的事物是,最大FD大小,每个进程的大小是16k,但是由于某种原因,它达到了最大值,却没有提供太多细节。
能否请您指向一些gotools或任何指针以检查我如何找到导致此问题的原因?
任何帮助或指针将不胜感激
答案 0 :(得分:1)
我不确定Go工具是否可以帮助解决此类问题。代码中可能存在一些连接泄漏。
可能发生的常见泄漏是在消耗了$answer = ["attachment"=>[
"type"=>"template",
"payload"=>[
"template_type"=>"generic",
"elements"=>[
[
"title"=> "Exclusive: Lalremsiami On FIH Series Win And The Loss Of Her Father",
"image_url"=> "https://www.shethepeople.tv/wp-content/uploads/2019/07/Lalremsiami.jpg",
"subtitle"=> "See all our colors",
"default_action"=> [
"type"=> "web_url",
"url"=> "https://www.shethepeople.tv/news/lalremsiami-fih-series-win-loss-father",
"webview_height_ratio"=> "tall",
// "messenger_extensions"=> true,
// "fallback_url"=> "https://peterssendreceiveapp.ngrok.io/"
],
"buttons"=>[
[
"type"=>"web_url",
"url"=>"https://www.shethepeople.tv",
"title"=>"View Website"
],
]
],
[
"title"=>"Welcome to Peter\'s Hats",
"item_url"=>"https://www.cloudways.com/blog/migrate-symfony-from-cpanel-to-cloud-hosting/",
"image_url"=>"https://www.cloudways.com/blog/wp-content/uploads/Migrating-Your-Symfony-Website-To-Cloudways-Banner.jpg",
"subtitle"=>"We\'ve got the right hat for everyone.",
"buttons"=>[
[
"type"=>"web_url",
"url"=>"https://petersfancybrownhats.com",
"title"=>"View Website"
],
]
],
[
"title"=>"Welcome to Peter\'s Hats",
"item_url"=>"https://www.cloudways.com/blog/migrate-symfony-from-cpanel-to-cloud-hosting/",
"image_url"=>"https://www.cloudways.com/blog/wp-content/uploads/Migrating-Your-Symfony-Website-To-Cloudways-Banner.jpg",
"subtitle"=>"We\'ve got the right hat for everyone.",
"buttons"=>[
[
"type"=>"web_url",
"url"=>"https://petersfancybrownhats.com",
"title"=>"View Website"
],
]
]
]
]
]];
的有效负载之后忘记调用resp.Body.Close()
。
空闲连接可能是另一个可能的原因。根据HTTP包文档:
默认情况下,传输会缓存连接以供将来重用。访问许多主机时,这可能会留下许多打开的连接。可以使用Transport的CloseIdleConnections方法以及MaxIdleConnsPerHost和DisableKeepAlives字段来管理此行为。
在这种情况下,您可以尝试在http.Response
句柄上显式调用CloseIdleConnections
,或减小Transport
的值。