HTTPoison connection pooling

Hello,

I have read so many posts on how to set connection pool size with HTTPoison but I am still quite confused on how to implement it, partly because the explanations and the steps provided in these online posts are all based on that which is specified in the HTTPoison documentation.

First of all, does HTTPoison do connection pooling by default? If yes, what is the default size of connection pools it creates?

In simple steps, how do I change the connection pool size in my POST requests, using HTTPoison?

I would be grateful for some assistance on this.

A lot of my POST requests end up timing out and I do not know what to do.

Thanks for the support in advance.

Regards,

Jerry

HTTPoison uses Hackney under the hood. Hackey will open / close connections on demand. However, you can switch it to use a pooled mode. By default, the pool size is 50. If you want to use this pool, you have to specify the pool option through HTTPoison, which will be passed into Hackney.

The way to specify the pool option can be found at https://github.com/edgurgel/httpoison#connection-pools

If your post requests are timing out, I’m not sure that a connection pool will help—it may actually make things worse. You could try to increase recv_timeout option, which defaults to 5s. Here’s an example of how to do that:

# Set to a 5s timeout (default), but this web request will delay for 7s
iex(3)> HTTPoison.get("http://slowwly.robertomurray.co.uk/delay/7000/url/http://www.google.com")
{:error, %HTTPoison.Error{id: nil, reason: :timeout}}

# Now it's okay at 10s timeout
iex(4)> HTTPoison.get("http://slowwly.robertomurray.co.uk/delay/7000/url/http://www.google.com", [], recv_timeout: 10_000)
{:ok,
 %HTTPoison.Response{
   body: "",
4 Likes

Many thanks, @sb8244, for your response.
I will go with your suggestion.

Regards,

Jerry