我们正在使用用Go seaweedfs编写的文件系统。正在端口8888上使用REST API来发布文件。我们遇到的问题是HTTPoison
超时。
我们一次又一次地发布到文件中,我们得到HTTPoison请求超时。
一些事实:
for ((i=1;i<=100;i++)); do curl -F file=@00_13_000.jpg -X POST http://188.xx.xx.xx.217:8888/everc-dupzo/snapshots/recordings/2019/11/22/09/00_13_000.jpg; done
可以正常工作,没有任何超时。生产
在生产中,我们将发送近1K POST HTTPoison
请求,其中10%给出超时错误。大多在已经存在的此类文件上。它们确实得到了更新,但是HTTPoison请求是超时的。
我们用于执行POST请求的代码如下所示。
def seaweedfs_save(camera_exid, timestamp, image, _notes) do
[{_, _, _, _, [server]}] = :ets.match_object(:storage_servers, {:_, "RW", :_, :_, :_})
hackney = [pool: :seaweedfs_upload_pool]
directory_path = construct_directory_path(camera_exid, timestamp, "recordings", "")
file_name = construct_file_name(timestamp)
file_path = directory_path <> file_name
case HTTPoison.post("#{server.url}#{file_path}", {:multipart, [{file_path, image, []}]}, [], hackney: hackney) do
{:ok, response} -> response
{:error, error} -> Logger.info "[seaweedfs_save] [#{file_path}] [#{camera_exid}] [#{inspect error}]"
end
end
hackney池设置为
:hackney_pool.child_spec(:seaweedfs_upload_pool, [timeout: 5000, max_connections: 1000])
seaweedfs的作者有一种直觉,即HTTPoison请求没有被关闭或被重用。 哈克尼(Hackney)的作者建议:
http是请求/响应协议,因此除非响应不是 应该有一个身体(204、304,头部),哈克尼会等待 直到您通过了skip_body选项,with_body选项或没有 他们通过将等待,直到超时
但是HTTPoison不允许https://github.com/edgurgel/httpoison/blob/master/lib/httpoison/base.ex#L812
我对此一无所知。任何帮助都会感激
答案 0 :(得分:0)
我认为问题在于网络带宽和/或延迟。基本上,您与max_connections: 1000
同时打开一千个连接。我很确定文件系统本身和网络对此不会感到满意。相反,示例中的curl
请求确实是一个接一个地同步运行的。
将max_connections
的值减小到100,甚至更低,以查看超时是否会消失。