HTTPoison post request Timeouts Eixir

走远了吗. 提交于 2019-12-24 03:44:06

问题


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

  1. How should we do HHTPoison request?
  2. Should we just switch to Hackney?
  3. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!