我们使用的是用Go,海草编写的文件系统。它正在使用端口8888上的REST来发布文件。我们遇到的问题是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
endhackney池设置为
:hackney_pool.child_spec(:seaweedfs_upload_pool, [timeout: 5000, max_connections: 1000])“seaweedfs”的作者有一种预感,即HTTPoison请求不会被关闭或重用。“哈克尼”的作者认为:
http是一个请求/响应协议,所以除非响应不应该有一个主体(204,304,head),hackney将等待它,直到您传递skip_body选项、with_body选项,或者如果没有传递,则等待超时。
但是HTTPoison不允许它https://github.com/edgurgel/httpoison/blob/master/lib/httpoison/base.ex#L812
我对这件事一筹莫展。任何帮助都应该感谢
发布于 2019-11-27 09:37:59
我认为问题在于网络带宽和/或延迟。基本上,您可以使用max_connections: 1000同时打开1000个连接。我很确定文件系统本身和网络不会对此感到高兴。相反,在您的示例中,curl请求确实一个接一个地同步运行。
将max_connections的值降到100,甚至更少,看看超时是否已经结束。
发布于 2021-09-07 20:07:11
我想您正面临请求超时的问题。请求超时的默认值为5秒。您可以用您的日志进行验证,它应该在5秒后超时。您可以通过提供以毫秒为单位的:recv_timout作为请求的一部分来增加超时。
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, []}]}, [:recv_timout, 15000], hackney: hackney) do
{:ok, response} -> response
{:error, error} -> Logger.info "[seaweedfs_save] [#{file_path}] [#{camera_exid}] [#{inspect error}]"
end
endhttps://stackoverflow.com/questions/58993318
复制相似问题