问题
We are using a filesystem written in Go, seaweedfs. It's being used a REST API on port 8888 to post Files. The issue we are having is HTTPoison
timeouts.
We post to a file, again and again, we get HTTPoison request timeout.
Few facts:
- File do get updated on seaweedfs we can see the modified date.
- HTTPoison request response is always timeout
- I have tried with curl POST.
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
which works fine without any timeout. - I have also tried to do it in my local machine with HTTPoison as well but it works fine.
Production
In production, we are sending almost 1K POST HTTPoison
requests from which 10% gives timeout error. mostly on such files which are already present. they do get updated but HTTPoison request comes as a timeout.
The code we are using to do POST request is written as under.
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 pool is set to
:hackney_pool.child_spec(:seaweedfs_upload_pool, [timeout: 5000, max_connections: 1000])
The author of seaweedfs has a hunch that HTTPoison requests are not getting closed or being reused. The author of Hackney suggests:
http is a request/response protocol so unless a response is not supposed to have a body (204, 304, head) hackney will wait for it until you pass the skip_body option, with_body option or if none of them is passed will wait until it timeout
But HTTPoison don't allow it https://github.com/edgurgel/httpoison/blob/master/lib/httpoison/base.ex#L812
I am at quite a dead end with it. Any help would be thankful about
- How should we do HHTPoison request?
- Should we just switch to Hackney?
- Or is there any better way to solve this problem? or any way to get more information about why a request is being timed out?
回答1:
I believe the issue is network bandwidth and/or latency. Basically you open a thousand connections simultaneously with max_connections: 1000
. I am pretty sure the filesystem itself and the network would not be happy about that. On the contrary, curl
requests in your example do run synchronously, one after another.
Decrease the value of max_connections
down to 100, or even less and see if the timeout would have gone.
来源:https://stackoverflow.com/questions/58993318/httpoison-post-request-timeouts-eixir